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])
相关推荐
whitelbwwww3 小时前
Pytorch--张量表示实际数据
人工智能·pytorch·python
AI大模型学徒5 小时前
5090NVIDIA、CUDAToolkit、cuDNN、Miniconda、PyTorch安装
pytorch·nvidia·cudnn·nimiconda·5090驱动安装·cudatoolkit
deephub6 小时前
Scikit-Learn 1.8引入 Array API,支持 PyTorch 与 CuPy 张量的原生 GPU 加速
人工智能·pytorch·python·机器学习·scikit-learn
All The Way North-9 小时前
PyTorch MultiStepLR:指定间隔学习率衰减的原理、API、参数详解、实战
pytorch·深度学习·学习率优化算法·multisteplr算法·指定间隔学习率衰减
roman_日积跬步-终至千里9 小时前
【人工智能导论】07-学习-CNN:卷积+池化+多层堆叠,有效处理图像等结构化数据
人工智能·学习·cnn
Wishell20159 小时前
日拱一卒之Python与matlab的内存读取区别
pytorch
AI即插即用9 小时前
即插即用系列 | CVPR 2024 RMT:既要全局感受野,又要 CNN 的局部性?一种拥有显式空间先验的线性 Transformer
人工智能·深度学习·神经网络·目标检测·计算机视觉·cnn·transformer
smile_Iris10 小时前
Day 45 简单CNN
人工智能·深度学习·cnn
此处不留情10 小时前
从零构建智能水果识别系统:数据模块深度解析
人工智能·pytorch
声声codeGrandMaster21 小时前
AI之模型提升
人工智能·pytorch·python·算法·ai