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])
相关推荐
Wu_Dylan1 小时前
液态神经网络系列(四) | 一条 PyTorch 从零搭建 LTC 细胞
pytorch·神经网络
煤炭里de黑猫3 小时前
使用 PyTorch 实现标准 LSTM 神经网络
人工智能·pytorch·lstm
应用市场3 小时前
【显著性预测】TranSalNet:Transformer与CNN融合的视觉显著性预测模型
深度学习·cnn·transformer
~kiss~4 小时前
多头注意力中的张量重塑
pytorch·python·深度学习
煤炭里de黑猫5 小时前
使用PyTorch创建一个标准的Transformer架构
人工智能·pytorch·transformer
机器学习之心7 小时前
CNN-LSTM、LSTM、CNN三模型多变量分类预测Matlab实现
分类·cnn·lstm·cnn-lstm
Lun3866buzha7 小时前
基于YOLOv26的昆虫检测与识别系统及Pytorch实现
人工智能·pytorch·yolo
lixin5565567 小时前
基于迁移学习的图像分类增强器
java·人工智能·pytorch·python·深度学习·语言模型
翱翔的苍鹰8 小时前
多Agent智能体架构设计思路
人工智能·pytorch·python
森屿~~18 小时前
AI 手势识别系统:踩坑与实现全记录 (PyTorch + MediaPipe)
人工智能·pytorch·python