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])
相关推荐
_codemonster1 天前
深度学习实战(基于pytroch)系列(五)线性回归的pytorch实现
pytorch·深度学习·线性回归
算法与编程之美1 天前
探究pytorch中多个卷积层和全连接层的输出方法
人工智能·pytorch·深度学习·神经网络·cnn
钅日 勿 XiName1 天前
一小时速通Pytorch之自动梯度(Autograd)和计算图(Computational Graph)(二)
人工智能·pytorch·python
Nina_7171 天前
pytorch核心组件以及流程
人工智能·pytorch·python
麦麦大数据1 天前
F045 vue+flask棉花病虫害CNN识别+AI问答知识neo4j 图谱可视化系统深度学习神经网络
人工智能·深度学习·神经网络·cnn·可视化·智能问答·病虫害识别
知行力2 天前
【GitHub每日速递 20251111】PyTorch:GPU加速、动态网络,深度学习平台的不二之选!
pytorch·深度学习·github
love530love2 天前
【笔记】xFormers版本与PyTorch、CUDA对应关系及正确安装方法详解
人工智能·pytorch·windows·笔记·python·深度学习·xformers
为你写首诗ge2 天前
【python】python安装使用pytorch库环境配置
pytorch·python
Danceful_YJ2 天前
30.注意力汇聚:Nadaraya-Watson 核回归
pytorch·python·深度学习
wa的一声哭了2 天前
hf中transformers库中generate的greedy_search
android·java·javascript·pytorch·深度学习·语言模型·transformer