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 入门精讲:从框架选择到 MNIST 手写数字识别实战
人工智能·pytorch·python
摘星编程1 天前
CANN ops-nn Pooling算子解读:CNN模型下采样与特征提取的核心
人工智能·神经网络·cnn
子榆.1 天前
CANN 与主流 AI 框架集成:从 PyTorch/TensorFlow 到高效推理的无缝迁移指南
人工智能·pytorch·tensorflow
慢半拍iii1 天前
从零搭建CNN:如何高效调用ops-nn算子库
人工智能·神经网络·ai·cnn·cann
偷吃的耗子1 天前
【CNN算法理解】:CNN平移不变性详解:数学原理与实例
人工智能·算法·cnn
哈__1 天前
CANN内存管理与资源优化
人工智能·pytorch
DeniuHe1 天前
Pytorch中的直方图
pytorch
哈__1 天前
CANN多模型并发部署方案
人工智能·pytorch
慢半拍iii1 天前
ops-nn性能调优实战:提升神经网络推理速度的秘诀
人工智能·神经网络·ai·cnn·cann
DeniuHe1 天前
Pytorch中的众数
人工智能·pytorch·python