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 layoutlmv3 model to onnx model #5073

Open iweirman opened 1 year ago

iweirman commented 1 year ago

I encountered some errors when attempting to export the layoutlmv3 model using export_model.py.

(myconda) root@Z95jJV:/mnt/detectron2/tools/deploy# python export_model.py --config-file /mnt/unilm-master/layoutlmv3/examples/object_detection/cascade_layoutlmv3.yaml --output ./output --export-method tracing --format torchscript MODEL.WEIGHTS /home/layoutlmv3-base-finetuned-publaynet/model_final.pth MODEL.DEVICE cuda [08/29 09:56:16 detectron2]: Command line arguments: Namespace(config_file='/mnt/unilm-master/layoutlmv3/examples/object_detection/cascade_layoutlmv3.yaml', export_method='tracing', format='torchscript', opts=['MODEL.WEIGHTS', '/home/layoutlmv3-base-finetuned-publaynet/model_final.pth', 'MODEL.DEVICE', 'cuda'], output='./output', run_eval=False, sample_image=None) Traceback (most recent call last): File "export_model.py", line 210, in cfg = setup_cfg(args) File "export_model.py", line 34, in setup_cfg cfg.merge_from_file(args.config_file) File "/mnt/detectron2/detectron2/config/config.py", line 69, in merge_from_file self.merge_from_other_cfg(loaded_cfg) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/fvcore/common/config.py", line 132, in merge_from_other_cfg return super().merge_from_other_cfg(cfg_other) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/yacs/config.py", line 217, in merge_from_other_cfg _merge_a_into_b(cfg_other, self, self, []) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/yacs/config.py", line 478, in _merge_a_into_b _merge_a_into_b(v, b[k], root, key_list + [k]) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/yacs/config.py", line 491, in _merge_a_into_b raise KeyError("Non-existent config key: {}".format(full_key)) KeyError: 'Non-existent config key: MODEL.IMAGE_ONLY'

[08/29 09:56:42 detectron2]: Command line arguments: Namespace(config_file='/mnt/unilm-master/layoutlmv3/examples/object_detection/cascade_layoutlmv3.yaml', export_method='tracing', format='torchscript', opts=['MODEL.WEIGHTS', '/home/layoutlmv3-base-finetuned-publaynet/model_final.pth', 'MODEL.DEVICE', 'cuda'], output='./output', run_eval=False, sample_image=None) Traceback (most recent call last): File "export_model.py", line 210, in cfg = setup_cfg(args) File "export_model.py", line 34, in setup_cfg cfg.merge_from_file(args.config_file) File "/mnt/detectron2/detectron2/config/config.py", line 69, in merge_from_file self.merge_from_other_cfg(loaded_cfg) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/fvcore/common/config.py", line 132, in merge_from_other_cfg return super().merge_from_other_cfg(cfg_other) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/yacs/config.py", line 217, in merge_from_other_cfg _merge_a_into_b(cfg_other, self, self, []) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/yacs/config.py", line 478, in _merge_a_into_b _merge_a_into_b(v, b[k], root, key_list + [k]) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/yacs/config.py", line 491, in _merge_a_into_b raise KeyError("Non-existent config key: {}".format(full_key)) KeyError: 'Non-existent config key: MODEL.VIT

It seems like the problem is caused by the yaml file, but I am unsure of how to resolve it.

qrsssh commented 2 months ago

-base-finetuned-publaynet/model_fi

same question, have you solved?