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])
相关推荐
m0_6174939410 小时前
PyTorch CUDA设备不可用错误解决方案
人工智能·pytorch·python
happyDogg_11 小时前
npu硬件实现cnn标准卷积计算细节
人工智能·神经网络·cnn
EnCi Zheng11 小时前
09-斯坦福CS336作业 [特殊字符]
人工智能·pytorch·python·深度学习·神经网络
nashane16 小时前
HarmonyOS 6学习:卡片组件圆角白边问题的诊断与修复实战
人工智能·pytorch·深度学习·harmonyos
kcuwu.17 小时前
CNN与RNN入门技术博客
人工智能·rnn·cnn
快乐得小萝卜19 小时前
使用:Pytorch C++ API
c++·人工智能·pytorch
盼小辉丶19 小时前
PyTorch强化学习实战(9)——深度Q学习
pytorch·深度学习·强化学习
禾刀围玉2 天前
基于FPGA的卷积神经网络实现-Step2 卷积模块设计
人工智能·fpga开发·cnn
love530love2 天前
ComfyUI:为什么说它是 AIGC 应用层面的集大成者?
人工智能·pytorch·windows·aigc·devops·comfyui·extensions
啦啦啦_99992 天前
案例之 PyTorch模拟线性回归
人工智能·pytorch·线性回归