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])
相关推荐
zhendianluli12 小时前
PyTorch 复杂模型转 ONNX 踩坑纪实:从 diff 到 nan_to_num 的三关突破
人工智能·pytorch·python
星恒随风17 小时前
从零开始理解 ResNet(上):为什么 CNN 需要“残差连接”?
人工智能·笔记·神经网络·学习·cnn
weixin_4684668519 小时前
PyTorch 与 TensorFlow 实战选型与应用场景指南
人工智能·pytorch·深度学习·算法·机器学习·tensorflow·深度学习框架
独隅21 小时前
PyTorch 新手从零搭建深度学习环境实战指南
人工智能·pytorch·深度学习
keineahnung234521 小时前
在 Google Colab 中安裝 PyTorch 2.2.0
人工智能·pytorch·python·深度学习
王_teacher1 天前
VGG16模型原理讲解-手写代码解析VGG16模型
cnn·卷积神经网络·论文笔记·vgg16
AI算法沐枫1 天前
机器学习经典小项目1:鸢尾花分类
人工智能·pytorch·深度学习·神经网络·机器学习·分类·数据挖掘
weixin_468466851 天前
PyTorch 深度学习框架核心能力与实战评测
人工智能·pytorch·深度学习·神经网络·计算机视觉·动态图·模型训练
fantasy_arch2 天前
BasicVSR-lite图像画质增强
开发语言·pytorch
小a杰.2 天前
Torchtitan NPU 框架 - PyTorch与NPU集成指南
人工智能·pytorch·python