facebookresearch / detectron2

Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.
https://detectron2.readthedocs.io/en/latest/
Apache License 2.0
30.35k stars 7.46k forks source link

export_torchscript_with_instances gives Module 'ResNet' has no attribute 'stages_and_names' error ? #4965

Closed lix19937 closed 1 year ago

lix19937 commented 1 year ago

Instructions To Reproduce the 🐛 Bug:

  1. Full runnable code or full changes you made:
    File "/opt/conda/envs/alpha_env/lib/python3.8/site-packages/torch/jit/_recursive.py", line 368, in create_methods_and_properties_from_stubs
    concrete_type._create_methods_and_properties(property_defs, property_rcbs, method_defs, method_rcbs, method_defaults)
    RuntimeError: 
    Module 'ResNet' has no attribute 'stages_and_names' (This attribute exists on the Python module, but we failed to convert Python type: 'list' to a TorchScript type. Could not infer type of list element: Cannot infer concrete type of torch.nn.Module. Its type was inferred; try adding a type annotation for the attribute.):
    File "/root/code/modeling/backbone/res2net.py", line 632
        if "stem" in self._out_features:
            outputs["stem"] = x
        for stage, name in self.stages_and_names:
                           ~~~~~~~~~~~~~~~~~~~~~ <--- HERE
            x = stage(x)
            if name in self._out_features:

ref https://github.com/facebookresearch/detectron2/issues/2734 not work !!!

Environment:

torch 1.10.2+cu113
detectron2 0.6

github-actions[bot] commented 1 year ago

Requested information was not provided in 7 days, so we're closing this issue.

Please open new issue if information becomes available. Otherwise, use github discussions for free-form discussions.