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])
相关推荐
2zcode13 小时前
基于MATLAB卷积神经网络的多颜色车牌识别系统设计与实现
开发语言·matlab·cnn
贵州晓智信息科技15 小时前
学词鸭 Typing 无痛背单词
人工智能·pytorch·python·深度学习
佳xuan15 小时前
深度学习pytorch
人工智能·pytorch·深度学习
小何code15 小时前
【第19篇】卷积神经网络CNN入门:图像识别的利器
人工智能·深度学习·cnn
香蕉鼠片16 小时前
模型训练微调流程,pytorch(豆包写的
pytorch·深度学习·机器学习
T.i.s17 小时前
相对自适应判别器(Relative Adaptive Discriminator, RAD)
pytorch·gan
2zcode1 天前
基于MATLAB的CNN和SVM苹果质量智能检测与分级系统研究
支持向量机·matlab·cnn
技术小黑1 天前
CNN算法实战系列02 | ResNet50V2算法实战与解析
pytorch·深度学习·算法·cnn
Febu42 天前
Nano-vLLM-MS
pytorch·深度学习·transformer
盼小辉丶2 天前
PyTorch强化学习实战——使用交叉熵方法解决 FrozenLake 环境
人工智能·pytorch·python·强化学习