繁体   English   中英

Pycharm 抱怨在 pytorch 的 nn.ModuleList object 中使用 [] 运算符

[英]Pycharm complains about using [] operator with pytorch's nn.ModuleList object

Pycharm 的类型检查抱怨以下代码块(取自pytorch 的文档):

    import torch.nn as nn
    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)
        #                   ^---------- complains here about:
        # Cannot find reference '[' in 'input:(Any, ...), kwargs:dict) -> Any'
        return x

有没有办法在不压制它的情况下解决这个问题?

这是一个已知问题https://youtrack.jetbrains.com/issue/PY-37601 ,将在 2020.1 中修复。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM