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])
相关推荐
bst@微胖子2 小时前
PyTorch深度学习框架项目合集一
人工智能·pytorch·python
骇城迷影5 小时前
从零复现GPT-2 124M
人工智能·pytorch·python·gpt·深度学习
zhangfeng11338 小时前
GitHub 知名博主 hiyouga 及其明星项目 LlamaFactory项目介绍 详细介绍
人工智能·pytorch·语言模型·github
Lun3866buzha8 小时前
摩托车目标检测与识别|基于Mask R-CNN_x101-64x4d_FPN_1x_COCO模型的实现
目标检测·r语言·cnn
偷吃的耗子18 小时前
【CNN算法理解】:三、AlexNet 训练模块(附代码)
深度学习·算法·cnn
查无此人byebye1 天前
从DDPM到DiT:扩散模型3大核心架构演进|CNN到Transformer的AIGC生成革命(附实操要点)
人工智能·pytorch·深度学习·架构·cnn·音视频·transformer
love530love1 天前
突破 Windows 编译禁区:BitNet 1-bit LLM 推理框架 GPU 加速部署编译 BitNet CUDA 算子全记录
c++·人工智能·pytorch·windows·python·cuda·bitnet
艾派森1 天前
深度学习实战-基于CNN与Transformer的人工智能艺术VS人类艺术识别模型
人工智能·python·深度学习·神经网络·cnn
盼小辉丶1 天前
PyTorch实战(28)——PyTorch深度学习模型部署
人工智能·pytorch·深度学习·模型部署
呆萌小新@渊洁2 天前
LoRA 与参数高效微调:低秩适配实战指南
人工智能·pytorch·python·ai·语音识别