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])
相关推荐
白白白飘7 小时前
pytorch 15.1 学习率调度基本概念与手动实现方法
人工智能·pytorch·学习
缘友一世9 小时前
PyTorch深度神经网络(前馈、卷积神经网络)
pytorch·cnn·dnn
墨绿色的摆渡人9 小时前
pytorch小记(二十):深入解析 PyTorch 的 `torch.randn_like`:原理、参数与实战示例
人工智能·pytorch·python
lqjun082710 小时前
Pytorch实现常用代码笔记
人工智能·pytorch·笔记
qyhua10 小时前
用 PyTorch 从零实现简易GPT(Transformer 模型)
人工智能·pytorch·transformer
墨绿色的摆渡人11 小时前
pytorch小记(二十一):PyTorch 中的 torch.randn 全面指南
人工智能·pytorch·python
lqjun082712 小时前
PyTorch实现CrossEntropyLoss示例
人工智能·pytorch·python
小蜗笔记12 小时前
显卡、Cuda和pytorch兼容问题
人工智能·pytorch·python
卡尔曼的BD SLAMer14 小时前
计算机视觉与深度学习 | Python实现EMD-SSA-VMD-LSTM-Attention时间序列预测(完整源码和数据)
python·深度学习·算法·cnn·lstm
墨绿色的摆渡人17 小时前
pytorch小记(二十二):全面解读 PyTorch 的 `torch.cumprod`——累积乘积详解与实战示例
人工智能·pytorch·python