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])
相关推荐
瀚岳-诸葛弩17 小时前
对比tensorflow,从0开始学pytorch(二)--多尺度实现
人工智能·pytorch·tensorflow
LDG_AGI17 小时前
【推荐系统】深度学习训练框架(十六):模型并行——推荐系统的TorchRec和大语言模型的FSDP(Fully Sharded Data Parallel)
人工智能·pytorch·分布式·深度学习·语言模型·自然语言处理·推荐算法
盼小辉丶18 小时前
PyTorch实战(16)——基于LSTM实现音乐生成
pytorch·深度学习·lstm·生成模型
抽象带篮子1 天前
Pytorch Lightning 框架运行顺序
人工智能·pytorch·python
xixixi777771 天前
CRNN(CNN + RNN + CTC):OCR识别的经典之作
人工智能·rnn·学习·架构·cnn·ocr·图像识别
聊天QQ:180809511 天前
西门子S7 - 200PLC和MCGS组态打造3泵恒压供水变频系统
cnn
monster000w1 天前
容器云2.7pytorch版本安装问题
人工智能·pytorch·python
ytao_wang1 天前
pip install -e .报错ModuleNotFoundError: No module named ‘torch‘
pytorch·python·深度学习
阿龙AI日记2 天前
保姆级教程:Anaconda+Cuda+Torch+Pycharm配置指南
ide·pytorch·python·pycharm
liliangcsdn2 天前
如何使用pytorch模拟Pearson loss训练模型
人工智能·pytorch·python