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])
相关推荐
盘古开天16669 小时前
PPO算法代码实战(三):PyTorch从零实现PPO求解CartPole
人工智能·pytorch·算法
Είναι η κοπέλα14 小时前
PyTorch 安装与验证
人工智能·pytorch·python
打不了嗝 ᥬ᭄15 小时前
卷积神经网络(CNN)基础与整体架构
人工智能·神经网络·cnn
水桶学习吧_15 小时前
电网负载无功MATLAB仿真
matlab·cnn·simulink
盼小辉丶1 天前
PyTorch强化学习实战(27)——进化策略在强化学习中的应用
人工智能·pytorch·深度学习·强化学习
weixin_447195291 天前
【无标题】
pytorch·python
bigdata-余建新1 天前
week2
人工智能·pytorch·深度学习
HwJack202 天前
【共创稿事节】HarmonyOS 7材质与光照:真实感的营造与性能的平衡
pytorch·harmonyos·材质
千里码aicood2 天前
基于cnn和transformer的卡通图像质量评价
人工智能·cnn·transformer
头发够用的程序员2 天前
TensorRT 自定义算子插件实战(一):从零手写 customScaledTanh
c++·人工智能·pytorch·python·深度学习·边缘计算·jetson