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])
相关推荐
weixin_446260857 小时前
[特殊字符] 视觉Transformer (ViT) 原理及性能突破:从CNN到大规模自注意力机制的迁移
深度学习·cnn·transformer
fantasy_arch9 小时前
pytorch人脸匹配模型
人工智能·pytorch·python
liuyunshengsir16 小时前
PyTorch 最小模型转 ONNX 完整样例
人工智能·pytorch·python
松☆19 小时前
torchair:昇腾PyTorch适配层生态协作深度解读
人工智能·pytorch·python
malog_21 小时前
PyTorch图像数据加载实战指南
图像处理·人工智能·pytorch·python
盼小辉丶21 小时前
PyTorch强化学习实战——Atari游戏包装器
pytorch·深度学习·强化学习
子榆.21 小时前
CANN PyTorch适配器深度拆解:从.cuda()到.npu()到底发生了什么
人工智能·pytorch·python
renke336421 小时前
写给前端的 CANN-torchtitan-npu:昇腾PyTorch Titan适配到底是啥?
前端·人工智能·pytorch·cann
初心未改HD1 天前
深度学习之CNN卷积层详解
人工智能·深度学习·cnn