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])
相关推荐
vvoennvv5 小时前
【Python TensorFlow】CNN-BiLSTM时序预测 卷积神经网络-双向长短期记忆神经网络组合模型(附代码)
python·神经网络·cnn·tensorflow·lstm·bilstm
胡侃有料8 小时前
【目标检测】two-stage------Mask R-CNN浅析-2018
目标检测·r语言·cnn
vvoennvv13 小时前
【Python TensorFlow】 CNN-GRU卷积神经网络-门控循环神经网络时序预测算法(附代码)
python·神经网络·机器学习·cnn·gru·tensorflow
Keep_Trying_Go14 小时前
LightningCLI教程 + 视频讲解
人工智能·pytorch·语言模型·大模型·多模态·lightning
AI即插即用16 小时前
即插即用系列 | 2024 SOTA LAM-YOLO : 无人机小目标检测模型
pytorch·深度学习·yolo·目标检测·计算机视觉·视觉检测·无人机
AIminminHu16 小时前
底层视觉及图像增强-项目实践理论补充(十六-0-(25):PyTorch---》底层视觉及图像增强):从奥运大屏到手机小屏,快来挖一挖里面都有什么
pytorch
小毅&Nora17 小时前
【人工智能】人工智能发展历程全景解析:从图灵测试到大模型时代(含CNN、Q-Learning深度实践)
人工智能·cnn·q-learning
FL171713141 天前
Pytorch保存pt和pkl
人工智能·pytorch·python
钅日 勿 XiName1 天前
一小时速通pytorch之训练分类器(四)(完结)
人工智能·pytorch·python
小蜜蜂爱编程1 天前
深度学习实践 - 使用卷积神经网络的手写数字识别
人工智能·深度学习·cnn