Pytorch:CycleGAN代码中nn.Sequential(*module)处错误:list is not a Module subclass
问题:
pytorch训练模型时,将模型的层layer都放到module列表中:
module = [layer1,layer2,layer3....]
nn.Sequential(*module)
报错list is not a Module subclass
尝试解决:
正常情况下,如下情况是正确的:
import torch
import torch.nn as nn
#net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
layer1 = [nn.Linear(2, 2), nn.Linear(2, 2)]
layer2 = [nn.Linear(2, 2), nn.Linear(2, 2)]module = layer1 + layer2
print(module)
net = nn.Sequential(*module)
print(net)
举例自己错误的情况:
import torch
import torch.nn as nn
#net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
layer1 = [nn.Linear(2, 2), nn.Linear(2, 2)]
layer2 = [nn.Linear(2, 2), nn.Linear(2, 2)]module = layer1 + [layer2]
print(module)
net = nn.Sequential(*module)
print(net)
我在module = layer1 + [layer2]中[layer2]外面多加了一层[],出现了这一问题。如果同样出现了这一问题,就需要仔细确认自己放到module列表里的内容是否除了layer,还有layer组成的其他列表,即[layer1,layer2,layer3,[layer4,layer5],layer7,layer8,layer9]是否包含了这种结构。
参考:
python - pytorch nn.Sequential(*list) TypeError: list is not a Module subclass - Stack Overflow
Pytorch:CycleGAN代码中nn.Sequential(*module)处错误:list is not a Module subclass相关推荐
- 代码中避免懒加载错误_网站设计中应避免的5大错误
代码中避免懒加载错误 The design of a website plays an imperative role in creating an effective and impressive ...
- pytorch中nn.Sequential
一个有序的容器,神经网络模块将按照在传入构造器的顺序依次被添加到计算图中执行,同时以神经网络模块为元素的有序字典也可以作为传入参数. # Example of using Sequentialmode ...
- pytorch cycleGAN代码学习1
一. 新的东西 p.s :很多架构都和之前一样,就举些不同的 1. ReplayBuffer() # Buffers of previously generated samples fake_A_ ...
- pytorch 学习笔记:nn.Sequential构造神经网络
1 两种等价的构造方式 1.1 构建Net类: 1.2 使用torch.nn.Sequential nn.Sequential里面的模块按照顺序进行排列的,所以必须确保前一个模块的输出大小和下一个模块 ...
- 解决代码中重复的捕获 promise 错误的 try catch 语句
promise promise 的出现,提供了优雅的异步解决方式,但是,多个连续继发 promise 写法依然繁琐. let promise = new Promise(function(resolv ...
- nn.Sequential()
nn.Sequential nn.Sequential()介绍 Pytorch官网举例 nn.Sequential()的本质作用 nn.Sequential()源码 nn.Sequential()介绍 ...
- php中脚本代码开始,从PHP代码中执行shell脚本
我想要做的就是使用PHP来执行youtube-dl -x --audio-format mp3 "token"并获得以下参数JSON:从PHP代码中执行shell脚本 状态(错误= ...
- CAFFE(FAQ.2):Ubuntu 配置caffe 框架之数据库读取,错误解决:ImportError: No module named leveldb解决办法...
Z: 在安装了caffe框架后需要读取大量的数据进行学习训练.比如在MNIST识别训练中,一般直接读图片会比较耗时,我们一般将图片转存为数据库中.目前主流的数据库有以下两种选择: LevelDB Lm ...
- Pytorch中nn.Module和nn.Sequencial的简单学习
文章目录 前言 1.Python 类 2.nn.Module 和 nn.Sequential 2.1 nn.Module 2.1.1 torch.nn.Module类 2.1.2 nn.Sequent ...
最新文章
- 4节点近160万IOPS:SDS/超融合测试不能只看数字
- 数据结构(Splay平衡树):HAOI2008 排名系统
- Linux进程间通信二 System V 消息队列简介与示例
- Knative Serving 健康检查机制分析
- scikit-image安装 from numpy.lib.arraypad import _validate_lengths ImportError: cannot import name ‘_va
- 转发:Datawhale第七期组队学习计划
- 对比Excel,学习pandas数据透视表
- Linux系统中输出输入的管理
- CountDownLatch 介绍与举例实现
- 值传递与引用传递区别,具体表现
- 从0开始学习 GitHub 系列之「02.加入 GitHub」
- 如何进行cad地理配准_如何对扫描图片进行ArcGIS配准?
- 系统集成项目管理工程师中高级一次通过经验之谈
- Unity与Android权限设置
- 手机怎么模拟125k卡_NFC手机能模拟门禁卡吗?
- 谷歌地图api的使用 一
- python getattrribute_Python学习——面向对象高级之反射
- 计算机一级和二级考试内容有什么不同吗?
- JAVA计算机毕业设计晨光文具店进销存系统设计与开发计算机(附源码、数据库)
- linux+++乘法口诀_通过shell脚本打印乘法口诀表