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])
相关推荐
阿正的梦工坊32 分钟前
深入理解 PyTorch 中的 unsqueeze 操作
人工智能·pytorch·python
技术小黑7 小时前
CNN算法实战系列03 | DenseNet121算法实战与解析
pytorch·深度学习·算法·cnn
z小猫不吃鱼10 小时前
01 为什么 Vision Transformer 会出现?从 CNN 到 ViT,理解视觉模型的一次重要转变
深度学习·cnn·transformer
禾刀围玉13 小时前
基于FPGA的卷积神经网络实现-方案构想
人工智能·fpga开发·cnn
keineahnung234513 小时前
為什麼要有 eval_is_non_overlapping_and_dense?PyTorch 包裝層與調用端解析
人工智能·pytorch·python·深度学习
m0_3722570213 小时前
parse_model 函数的收尾部分,负责将计算好的参数实例化为真实的 PyTorch 层,并完成元数据的绑定和通道账本的更新
人工智能·pytorch·python
心疼你的一切13 小时前
PyTorch实战:手写数字识别神经网络
人工智能·pytorch·深度学习·神经网络·机器学习
行者-全栈开发15 小时前
【AI时空分析】基于 GNN 的城市交通流量预测:图神经网络在智慧交通中的实战应用
pytorch·深度学习·图神经网络·智慧交通·交通流量预测·时空建模·geometric
m0_6174939416 小时前
解决 PyTorch 报错:RuntimeError: CUDA error: an illegal instruction was encountered
人工智能·pytorch·python
Hali_Botebie1 天前
【图卷积网络】GCN是AXΘ 和CNN是AX
网络·人工智能·cnn