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 分钟前
《动手学深度学习》-52文本预处理实现
人工智能·pytorch·python·深度学习
胖墩会武术31 分钟前
《图像分割简史》
人工智能·神经网络·cnn·transformer
BHXDML3 小时前
基于卷积神经网络的人脸性别识别实验应用
人工智能·神经网络·cnn
_ziva_5 小时前
分布式(三)深入浅出理解PyTorch分布式训练:nn.parallel.DistributedDataParallel详解
人工智能·pytorch·分布式
Francek Chen6 小时前
【自然语言处理】02 文本规范化
人工智能·pytorch·深度学习·自然语言处理·easyui
yj_sharing7 小时前
经典卷积神经网络架构详解
人工智能·神经网络·cnn
盼小辉丶9 小时前
PyTorch实战(25)——使用PyTorch构建DQN模型
人工智能·pytorch·深度学习·强化学习
白日做梦Q18 小时前
细粒度图像分类:从双线性CNN到TransFG的技术演进
分类·数据挖掘·cnn
lixin55655621 小时前
基于深度生成对抗网络的高质量图像生成模型研究与实现
java·人工智能·pytorch·python·深度学习·语言模型
koo3641 天前
pytorch深度学习笔记18
pytorch·笔记·深度学习