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])
相关推荐
独隅1 分钟前
PyTorch 模型部署的 Docker 配置与性能调优深入指南
人工智能·pytorch·docker
是枚小菜鸡儿吖2 小时前
卷不动了?带你拆解 2026 深度学习核心版图:CNN、Transformer 与扩散模型的实战进化
深度学习·cnn·transformer
靴子学长2 小时前
Decoder only 架构下 - KV cache 的理解
pytorch·深度学习·算法·大模型·kv
寂寞旅行4 小时前
大模型基石发展历程:CNN、RNN、transformer
rnn·cnn·transformer
独隅4 小时前
PyTorch 模型性能优化:图像分类与 NLP 模型实战指南
pytorch·性能优化·分类
Narrastory4 小时前
明日香 - Pytorch 快速入门保姆级教程(九)
人工智能·pytorch·深度学习
AI视觉网奇6 小时前
vllm 踩坑记录 算力匹配
pytorch·python·深度学习
剑穗挂着新流苏3128 小时前
202_深度学习的动力源泉:矩阵微积分与自动求导 (Autograd)
人工智能·pytorch·python·深度学习·神经网络
爱丽_9 小时前
高维问题如何“降维计算”:矩阵映射、卷积与拆分汇总
深度学习·矩阵·cnn
每天吃的很好的Ruby9 小时前
报错ValueError: sampler option is mutually exclusive with shuffle
人工智能·pytorch·python