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])
相关推荐
AAD555888996 小时前
【番茄病害检测】基于Faster R-CNN的番茄黄叶卷曲病毒智能识别系统,完整实现与代码解析
目标跟踪·cnn
裤裤兔7 小时前
卷积神经网络中的自适应池化
人工智能·神经网络·cnn·自适应池化
Faker66363aaa8 小时前
基于Faster R-CNN的桃黄病病害检测与分类系统实现_1
分类·r语言·cnn
yzx9910139 小时前
从“识别猫”到诊断疾病:卷积神经网络如何改变我们的视觉世界
人工智能·神经网络·cnn
FF-Studio12 小时前
解决 NVIDIA RTX 50 系列 (sm_120) 架构下的 PyTorch 与 Unsloth 依赖冲突
pytorch·自然语言处理·cuda·unsloth·rtx 50 series
nwsuaf_huasir12 小时前
深度学习2-pyTorch学习-张量基本操作
pytorch·深度学习·学习
工业机器视觉设计和实现12 小时前
极简单bpnet对比极简单cnn
人工智能·神经网络·cnn
黄小耶@13 小时前
基于 CNN 的猫狗分类实战
人工智能·分类·cnn
西南胶带の池上桜1 天前
1.Pytorch模型应用(线性与非线性预测)
人工智能·pytorch·python
V1ncent Chen1 天前
机器是如何识别图片的?:卷积神经网络
人工智能·神经网络·cnn