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 小时前
深度学习——卷积神经网络实现手写数字识别
人工智能·深度学习·cnn
Katecat996635 小时前
肾衰竭医学影像多类别目标检测:基于Mask R-CNN的囊肿、肾脏、结石和肿瘤六类病变特征识别_1
目标检测·r语言·cnn
一行注释也不写8 小时前
【卷积层和池化层在CNN中的作用】
深度学习·计算机视觉·cnn
2501_942191779 小时前
使用Faster R-CNN实现网球球检测:基于R50-FPN-MS-3x模型的COCO数据集训练与优化
目标跟踪·r语言·cnn
不如语冰12 小时前
AI大模型入门1.1-python基础-数据结构
数据结构·人工智能·pytorch·python·cnn
2501_9413297214 小时前
长豆荚目标检测:Faster R-CNN改进模型实战与优化
目标检测·r语言·cnn
pen-ai15 小时前
PyTorch 张量维度处理详解
人工智能·pytorch·python
pen-ai15 小时前
【PyTorch】 nn.TransformerEncoderLayer 详解
人工智能·pytorch·python
山土成旧客15 小时前
【Python学习打卡-Day44】站在巨人的肩膀上:玩转PyTorch预训练模型与迁移学习
pytorch·python·学习
星河天欲瞩15 小时前
【深度学习Day1】环境配置(CUDA、PyTorch)
人工智能·pytorch·python·深度学习·学习·机器学习·conda