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])
相关推荐
淼澄研学1 天前
PyTorch深度学习实战:从零构建神经网络模型的五个核心步骤
pytorch·深度学习·神经网络
西柚研究生1234562 天前
创建自己的数据集(GoogLeNet)
深度学习·神经网络·cnn
xx_xxxxx_2 天前
AI基本结构12-lstm实现nlp
人工智能·pytorch·rnn·lstm
工业机器视觉设计和实现2 天前
cifar10训练突破80分(三,摸到pytorch尾灯!)
人工智能·pytorch·cudnn微积分
想会飞的蒲公英2 天前
PyTorch reshape、view、transpose、广播到底怎么选?
人工智能·pytorch·python
风痕天际3 天前
Pytorch开发教程2——张量核心操作完全指南
人工智能·pytorch·python
m沐沐3 天前
【深度学习】循环神经网络RNN——结构、原理与长期依赖问题解析
人工智能·pytorch·python·rnn·深度学习·算法·机器学习
FriendshipT3 天前
Ultralytics:简要解读YOLOv8 → YOLO11 → YOLO26网络架构
人工智能·pytorch·python·深度学习·yolo·目标检测
不懒不懒4 天前
路面类型识别 — CNN-LSTM 完整流程:基于车辆振动数据的端到端深度学习
深度学习·cnn·lstm
工业机器视觉设计和实现4 天前
动量的好处与困扰(二,摸到pytorch尾灯!)
人工智能·pytorch·cudnn微积分