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])
相关推荐
StarPrayers.11 小时前
卷积神经网络(CNN)入门实践及Sequential 容器封装
人工智能·pytorch·神经网络·cnn
一水鉴天12 小时前
整体设计 逻辑系统程序 之29 拼语言+ CNN 框架核心定位、三阶段程序与三种交换模式配套的方案讨论 之2
人工智能·神经网络·cnn
新子y13 小时前
【小白笔记】PyTorch 和 Python 基础的这些问题
pytorch·笔记·python
我是李武涯13 小时前
PyTorch DataLoader 高级用法
人工智能·pytorch·python
incidite13 小时前
一文读懂 YOLOv1 与 YOLOv2:目标检测领域的早期里程碑
cnn
Victory_orsh15 小时前
“自然搞懂”深度学习系列(基于Pytorch架构)——01初入茅庐
人工智能·pytorch·python·深度学习·算法·机器学习
StarPrayers.18 小时前
用 PyTorch 搭建 CIFAR10 线性分类器:从数据加载到模型推理全流程解析
人工智能·pytorch·python
Sherry Wangs19 小时前
显卡算力过高导致PyTorch不兼容的救赎指南
人工智能·pytorch·显卡
Sunhen_Qiletian1 天前
卷积神经网络搭建实战(二)——基于PyTorch框架和本地自定义图像数据集的食物分类案例(附输入图片预测功能)
pytorch·分类·cnn
星期天要睡觉1 天前
深度学习——基于 ResNet18 的图像分类训练
pytorch·python·机器学习