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])
相关推荐
Ivanqhz2 小时前
BM1688 双核架构
python·深度学习·神经网络·cnn·mlir
Thomas.Sir8 小时前
第16课:PyTorch|循环神经网络RNN与序列数据处理【让模型拥有“记忆”】
人工智能·pytorch·rnn
智码看视界11 小时前
第三篇:卷积神经网络架构演进——从 LeNet 到 ResNet
计算机视觉·cnn·resnet·卷积神经网络·图像分类
失舵之舟-14 小时前
【全步骤】Pytorch 搭建自己的Unet语义分割平台
pytorch·语义分割·unet
盼小辉丶14 小时前
PyTorch强化学习实战——分布式策略梯度
人工智能·pytorch·深度学习·强化学习
jzshmyt1 天前
我用 Python 从零“生成“了一个宇宙,然后让它观察自己(v14)
人工智能·pytorch·python·numpy·matplotlib·空间计算·scipy
蝙蝠侠的小蝙蝠1 天前
【目标检测】YOLOV3 & YOLOV4 网络基本结构
目标检测·cnn·yolov3·yolov4
Thomas.Sir1 天前
第13课:PyTorch|经典CNN网络模型从零复现【从LeNet到VGG的逐行实现】
网络·pytorch·cnn
Thomas.Sir2 天前
第7课:PyTorch|激活函数全品类详解与选型实战【神经网络的“火花塞”】
人工智能·pytorch·神经网络
Thomas.Sir2 天前
第10课:PyTorch|学习率调度策略全面精讲【训练过程的“自适应巡航”】
人工智能·pytorch·学习