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])
相关推荐
Westward-sun.34 分钟前
PyTorch迁移学习实战:用ResNet18实现20类食物图像分类(附代码详解)
pytorch·分类·迁移学习
ForDreamMusk5 小时前
PyTorch编程基础
人工智能·pytorch
郝学胜-神的一滴6 小时前
神经网络参数初始化:从梯度失控到模型收敛的核心密码
人工智能·pytorch·深度学习·神经网络·机器学习·软件构建·软件设计
机器学习之心6 小时前
一键替换数据集!基于PSO多目标优化与SHAP可解释分析的回归预测神器来了PyTorch构建
pytorch·回归·可解释分析·pso多目标优化
配奇9 小时前
PyTorch 核心使用
人工智能·pytorch·python
墨心@12 小时前
pytorch 与资源核算
pytorch·语言模型·大语言模型·datawhale·组队学习
李昊哲小课12 小时前
WSL Ubuntu 24.04 GPU 加速环境完整安装指南
c++·pytorch·深度学习·ubuntu·cuda·tensorflow2
Z.风止1 天前
Large Model-learning(6)
pytorch·深度学习·机器学习
nap-joker1 天前
优化的局部定向韦伯图样与更快的区域卷积神经网络的集成,以增强医学图像检索和分类能力
人工智能·神经网络·cnn
Acland2409401 天前
基于 PyTorch 的 Fashion-MNIST CNN 分类模型
人工智能·pytorch·分类