前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >torch.nn.ModuleList

torch.nn.ModuleList

作者头像
狼啸风云
修改2022-09-02 22:03:42
8880
修改2022-09-02 22:03:42
举报

class torch.nn.ModuleList(modules=None)[source]

在列表中保持子模块。ModelList可以像正常Python列表一样检索,但是它所包含的模块已正确注册,并且对所有模块方法都可见。

参数:

  • modules (iterable, optional) – an iterable of modules to add

例:

代码语言:javascript
复制
class MyModule(nn.Module):
    def __init__(self):
        super(MyModule, self).__init__()
        self.linears = nn.ModuleList([nn.Linear(10, 10) for i in range(10)])

    def forward(self, x):
        # ModuleList can act as an iterable, or be indexed using ints
        for i, l in enumerate(self.linears):
            x = self.linears[i // 2](x) + l(x)
        return x

append(module)[source]

Appends a given module to the end of the list.

参数:

extend(modules)[source]

将Python可迭代器中的模块追加到列表的末尾。

参数:

  • modules (iterable) – 要追加的模块的可迭代

insert(index, module)[source]

在列表中给定索引之前插入给定模块。

参数:

  • index (int) – 索引插入。
  • module (nn.Module) – 模块插入
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-06-10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • append(module)[source]
  • extend(modules)[source]
  • insert(index, module)[source]
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档