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])
相关推荐
吉小雨2 小时前
PyTorch经典模型
人工智能·pytorch·python
crownyouyou3 小时前
最简单的一文安装Pytorch+CUDA
人工智能·pytorch·python
张琪杭4 小时前
基于CNN的10种物体识别项目
人工智能·神经网络·cnn
子午7 小时前
动物识别系统Python+卷积神经网络算法+TensorFlow+人工智能+图像识别+计算机毕业设计项目
人工智能·python·cnn
羊小猪~~11 小时前
深度学习基础案例5--VGG16人脸识别(体验学习的痛苦与乐趣)
人工智能·python·深度学习·学习·算法·机器学习·cnn
artificiali19 小时前
Anaconda配置pytorch的基本操作
人工智能·pytorch·python
#include<菜鸡>21 小时前
动手学深度学习(pytorch土堆)-04torchvision中数据集的使用
人工智能·pytorch·深度学习
chnyi6_ya1 天前
深度学习的笔记
服务器·人工智能·pytorch
安逸sgr1 天前
1、CycleGAN
pytorch·深度学习·神经网络·生成对抗网络
繁依Fanyi1 天前
828 华为云征文|华为 Flexus 云服务器部署 RustDesk Server,打造自己的远程桌面服务器
运维·服务器·开发语言·人工智能·pytorch·华为·华为云