CNN记录】pytorch中flatten函数

pytorch原型

python 复制代码
torch.flatten(input, start_dim=0, end_dim=- 1)

作用:将连续的维度范围展平维张量,一般写再某个nn后用于对输出处理,

参数:

start_dim:开始的维度

end_dim:终止的维度,-1为最后一个轴

默认值时展平为1维

例子

1、默认参数

python 复制代码
input = torch.randn(2, 3, 4, 5)
output = torch.flatten(input)
输出维:torch.Size([120])

2、设置参数

python 复制代码
input = torch.randn(2, 3, 4, 5)

output = torch.flatten(input,1)
输出shape为:torch.Size([2, 60])

output = torch.flatten(input,1,2)
输出shape为:torch.Size([2, 12, 5])
相关推荐
盼小辉丶3 天前
PyTorch实战(30)——使用TorchScript和ONNX导出通用PyTorch模型
人工智能·pytorch·深度学习·模型部署
有梦想的攻城狮3 天前
卷积神经网络(CNN)详解
人工智能·神经网络·cnn·卷积神经网络
封奚泽优3 天前
使用mmdetection项目进行训练记录
pytorch·python·cuda·mmdetection·mmcv
tony3653 天前
pytorch分布式训练解释
人工智能·pytorch·分布式
weixin_贾3 天前
深度学习基础理论与 PyTorch 实战 —— 从传统机器学习到前沿模型全攻略
pytorch·深度学习·机器学习
冰西瓜6004 天前
深度学习的数学原理(十三)—— CNN实战
人工智能·深度学习·cnn
大连好光景4 天前
PyTorch深度学习----优化器
pytorch·深度学习·学习
多恩Stone5 天前
【3D-AICG 系列-11】Trellis 2 的 Shape VAE 训练流程梳理
人工智能·pytorch·算法·3d·aigc
技道两进5 天前
使用DNN\LSTM\CNN进行时间序列预测
cnn·lstm·dnn·时间序列
隔壁大炮5 天前
08. PyTorch_张量基本创建方式
人工智能·pytorch·python