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])
相关推荐
海海不掉头发5 小时前
【PyTorch 实战】基于 RNN/LSTM/GRU 的全球人名国籍分类器(通俗拆解 + 逐行详解)】
pytorch·rnn·lstm
学术小李1 天前
基于Pytorch,如何用CUDA自己写算子?(一)
人工智能·pytorch·python
a1117761 天前
基于PyTorch的动物图像识别系统 开源
人工智能·pytorch·python
FriendshipT1 天前
Ultralytics:解读Proto模块
人工智能·pytorch·python·深度学习·目标检测
程序员羽痕2 天前
基于 Django + PyTorch 的中文字体识别系统
pytorch·python·django
matlab代码3 天前
基于CNN卷积神经网络交通标志识别系统 (GUI界面 数字图像处理)【源码48期】
人工智能·神经网络·cnn·交通标志识别
培之3 天前
RTX 5090 安装 pytorch3d
人工智能·pytorch·python
延卿3 天前
nnDetection:基于 PyTorch 的目标检测框架
人工智能·pytorch·目标检测
2zcode3 天前
项目文档:基于MATLAB深度卷积神经网络的肺癌CT影像智能检测系统设计与实现
深度学习·matlab·cnn