'module' object is not iterable:

How can I iterate nn.squential() module like a list:

RuntimeError: 
'module' object is not iterable:
at /home/dai/scripts/card_ocr_cpu/detector/model_torchscript.py:83:8
    def forward(self, x):
        out = []
        for i, m in enumerate(self.features):
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...  <--- HERE
            x = m(x)
            if i in [3, 6, 13, 18]:
                out.append(x)
        return out
'__torch__.extractor.forward' is being compiled since it was called from '__torch__.EAST.forward'
at /home/dai/scripts/card_ocr_cpu/detector/model_torchscript.py:209:8
    def forward(self, x, train:bool=False):
        x1,x2,x3,x4 = self.extractor(x)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
        x = self.merge(x1,x2,x3,x4)
        score,geo = self.output(x)
        if not train:
            boxes = get_boxes_torch(score,geo,score_thresh=0.95,nms_thresh=0.2)

Could you try to add all modules into an nn.ModuleList instead of nn.Sequential?

Thank you , I fixed this problem by removing enumerate().

nn.ModuleList can’t be enumerated or subscripted in a jit.script :frowning:

It can be enumerated, it can’t currently be subscripted.

Are you sure? I’m trying to iterate over a ModuleList (without enumerate) and get the error “‘torch.torch.nn.modules.container.ModuleList’ object is not iterable”. Latest pytorch version