microsoft / unilm

Large-scale Self-supervised Pre-training Across Tasks, Languages, and Modalities
https://aka.ms/GeneralAI
MIT License
20.19k stars 2.55k forks source link

Unable to use finetuned LayoutLMV3 for object detection task model for testing #1573

Open maniyarsuyash opened 5 months ago

maniyarsuyash commented 5 months ago

Describe Model I am using (LayoutLMV3): I have sucessfully finetuned LayoutLMV3 model on custom dataset similar to publaynet dataset on object detection task , it saves a .pth model but when I try to use it for eval using this script : python train_net.py --config-file cascade_layoutlmv3.yaml --eval-only --num-gpus 8 \ MODEL.WEIGHTS /path/to/layoutlmv3-base-finetuned-publaynet/model_final.pth \ OUTPUT_DIR /path/to/layoutlmv3-base-finetuned-publaynet

I get error : [06/30 11:16:16 detectron2]: Full config saved to /content/output_dir/config.yaml file /content/output_dir/config.json not found Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/transformers/configuration_utils.py", line 558, in get_config_dict user_agent=user_agent, File "/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py", line 1506, in cached_path raise EnvironmentError(f"file {url_or_filename} not found") OSError: file /content/output_dir/config.json not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/content/unilm/layoutlmv3/examples/object_detection/train_net.py", line 122, in args=(args,), File "/usr/local/lib/python3.7/dist-packages/detectron2/engine/launch.py", line 82, in launch main_func(args) File "/content/unilm/layoutlmv3/examples/object_detection/train_net.py", line 90, in main model = MyTrainer.build_model(cfg) File "/content/unilm/layoutlmv3/examples/object_detection/ditod/mytrainer.py", line 553, in build_model model = build_model(cfg) File "/usr/local/lib/python3.7/dist-packages/detectron2/modeling/meta_arch/build.py", line 22, in build_model model = META_ARCH_REGISTRY.get(meta_arch)(cfg) File "/usr/local/lib/python3.7/dist-packages/detectron2/config/config.py", line 189, in wrapped explicit_args = _get_args_from_config(from_config_func, args, *kwargs) File "/usr/local/lib/python3.7/dist-packages/detectron2/config/config.py", line 245, in _get_args_from_config ret = from_config_func(args, kwargs) File "/usr/local/lib/python3.7/dist-packages/detectron2/modeling/meta_arch/rcnn.py", line 72, in from_config backbone = build_backbone(cfg) File "/usr/local/lib/python3.7/dist-packages/detectron2/modeling/backbone/build.py", line 31, in build_backbone backbone = BACKBONE_REGISTRY.get(backbone_name)(cfg, input_shape) File "/content/unilm/layoutlmv3/examples/object_detection/ditod/backbone.py", line 168, in build_vit_fpn_backbone bottom_up = build_VIT_backbone(cfg) File "/content/unilm/layoutlmv3/examples/object_detection/ditod/backbone.py", line 154, in build_VIT_backbone config_path=config_path, image_only=cfg.MODEL.IMAGE_ONLY, cfg=cfg) File "/content/unilm/layoutlmv3/examples/object_detection/ditod/backbone.py", line 84, in init config = AutoConfig.from_pretrained(config_path) File "/usr/local/lib/python3.7/dist-packages/transformers/models/auto/configuration_auto.py", line 558, in from_pretrained configdict, = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, kwargs) File "/usr/local/lib/python3.7/dist-packages/transformers/configuration_utils.py", line 575, in get_config_dict raise EnvironmentError(msg) OSError: Can't load config for '/content/output_dir/'. Make sure that:

'/content/output_dir/' is a correct model identifier listed on 'https://huggingface.co/models'
(make sure '/content/output_dir/' is not a path to a local directory with something else, in that case)

or '/content/output_dir/' is the correct path to a directory containing a config.json file
liuwake commented 1 month ago

Just copy layoutlmv3-base-finetuned-publaynet/config.json to /content/output_dir/. The code need it.