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])
相关推荐
巴里巴气3 小时前
安装GPU版本的Pytorch
人工智能·pytorch·python
江太翁4 小时前
Pytorch torch
人工智能·pytorch·python
William.csj5 小时前
Pytorch——查看模型的推理引擎
人工智能·pytorch
weisian1516 小时前
人工智能-基础篇-10-什么是卷积神经网络CNN(网格状数据处理:输入层,卷积层,激活函数,池化层,全连接层,输出层等)
人工智能·神经网络·cnn
.30-06Springfield9 小时前
利用人名语言分类案例演示RNN、LSTM和GRU的区别(基于PyTorch)
人工智能·pytorch·python·rnn·分类·gru·lstm
xingshanchang11 小时前
PyTorch 不支持旧GPU的异常状态与解决方案:CUDNN_STATUS_NOT_SUPPORTED_ARCH_MISMATCH
人工智能·pytorch·python
云渚钓月梦未杳14 小时前
深度学习04 卷积神经网络CNN
人工智能·深度学习·cnn
Vertira10 天前
PyTorch中的permute, transpose, view, reshape和flatten函数详解(已解决)
人工智能·pytorch·python
匿名的魔术师10 天前
实验问题记录:PyTorch Tensor 也会出现 a = b 赋值后,修改 a 会影响 b 的情况
人工智能·pytorch·python
Ven%10 天前
PyTorch 张量(Tensors)全面指南:从基础到实战
人工智能·pytorch·python