2. what exact command you run:
python3 export_model.py. This is the script above to convert .pth model to onnx. I am following the method in caffe2_converter.py
3. __full logs__ you observed:
File "/usr/local/lib/python3.6/dist-packages/mock/mock.py", line 1411, in get_original
"%s does not have the attribute %r" % (target, name)
AttributeError: <class 'torch.nn.modules.container.ModuleList'> does not have the attribute 'inference'
## Expected behaviour:
I feel this is similar to issue #1143 I am not sure what the "does not have attribute 'inference'" is pointing to. I have tried running model.eval() before converting but that doesn't seem to work either. I have also tried using export_torchscript() to get the torchscript model format but get the same error. The model was trained on GPU but I have put cfg.MODEL.DEVICE = "cpu" for inference. Could that be a problem? Or is the way I am passing sample data incorrect? I have followed how it is done in caffe2_converter.py. I would appreciate any help. Thanks!
## Environment:
Instructions To Reproduce the Issue:
Check https://stackoverflow.com/help/minimal-reproducible-example for how to ask good questions. Simplify the steps to reproduce the issue using suggestions from the above link, and provide them below:
git diff
)def register_data(): register_coco_instances("val_data", {}, 'coco_mod/val.json', 'coco_mod/val')
def setup_cfg(backbone): cfg = get_cfg() cfg.merge_from_file(model_zoo.get_config_file('Misc/cascade_mask_rcnn_R_50_FPN_3x.yaml')) cfg.DATALOADER.NUM_WORKERS = 0 cfg.MODEL.WEIGHTS = 'model_0.pth' cfg.MODEL.ROI_HEADS.NUM_CLASSES = 5 cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 cfg.DATASETS.TEST = ('val_data',) cfg.MODEL.DEVICE = "cpu" cfg.freeze() return cfg
if name == 'main': register_data() cfg = setup_cfg(0) model = build_model(cfg) DetectionCheckpointer(model).resume_or_load(cfg.MODEL.WEIGHTS) data_loader = build_detection_test_loader(cfg, cfg.DATASETS.TEST[0]) first_batch = next(iter(data_loader)) tracer = Caffe2Tracer(cfg, model, first_batch)
script_model = tracer.export_torchscript()
script_model.save("model.ts")
onnx_model = tracer.export_onnx() onnx.save(onnx_model, "cascade_rcnn.onnx")
File "/usr/local/lib/python3.6/dist-packages/mock/mock.py", line 1411, in get_original "%s does not have the attribute %r" % (target, name) AttributeError: <class 'torch.nn.modules.container.ModuleList'> does not have the attribute 'inference'
sys.platform linux Python 3.6.9 (default, Apr 18 2020, 01:56:04) [GCC 8.4.0] numpy 1.16.3 detectron2 0.1.3 @/home/ubuntu/detectron2/detectron2 Compiler GCC 7.5 CUDA compiler CUDA 11.0 detectron2 arch flags sm_70 DETECTRON2_ENV_MODULE
PyTorch 1.5.1 @/home/ubuntu/.local/lib/python3.6/site-packages/torch
PyTorch debug build False
GPU available True
GPU 0 Tesla V100-SXM2-16GB
CUDA_HOME /usr/local/cuda
Pillow 7.1.2
torchvision 0.6.1 @/home/ubuntu/.local/lib/python3.6/site-packages/torchvision
torchvision arch flags sm_35, sm_50, sm_60, sm_70, sm_75
fvcore 0.1.1.post20200622
cv2 4.2.0
PyTorch built with: