MendelXu / SAN

Open-vocabulary Semantic Segmentation
https://mendelxu.github.io/SAN/
MIT License
295 stars 27 forks source link

TypeError: PatchEmbed.__init__() got an unexpected keyword argument 'dynamic_img_pad' #19

Closed AaronNZH closed 1 year ago

AaronNZH commented 1 year ago

I got the following error:

Traceback (most recent call last): File "/home/ubuntu/anaconda3/envs/SAN/lib/python3.10/site-packages/torch/multiprocessing/spawn.py", line 69, in _wrap fn(i, args) File "/data/NZH/detectron2/detectron2/engine/launch.py", line 123, in _distributed_worker main_func(args) File "/data/NZH/SAN/train_net.py", line 260, in main model = Trainer.build_model(cfg) File "/data/NZH/detectron2/detectron2/engine/defaults.py", line 514, in build_model model = build_model(cfg) File "/data/NZH/detectron2/detectron2/modeling/meta_arch/build.py", line 22, in build_model model = META_ARCH_REGISTRY.get(meta_arch)(cfg) File "/data/NZH/detectron2/detectron2/config/config.py", line 189, in wrapped explicit_args = _get_args_from_config(from_config_func, *args, kwargs) File "/data/NZH/detectron2/detectron2/config/config.py", line 245, in _get_args_from_config ret = from_config_func(*args, *kwargs) File "/data/NZH/SAN/san/model/san.py", line 133, in from_config "side_adapter_network": build_side_adapter_network( File "/data/NZH/SAN/san/model/side_adapter/side_adapter.py", line 26, in build_side_adapter_network return SIDE_ADAPTER_REGISTRY.get(name)(cfg, input_shape) File "/data/NZH/detectron2/detectron2/config/config.py", line 189, in wrapped explicit_args = _get_args_from_config(from_config_func, args, kwargs) File "/data/NZH/detectron2/detectron2/config/config.py", line 245, in _get_args_from_config ret = from_config_func(*args, kwargs) File "/data/NZH/SAN/san/model/side_adapter/side_adapter.py", line 129, in from_config vit = create_model( File "/home/ubuntu/anaconda3/envs/SAN/lib/python3.10/site-packages/timm/models/_factory.py", line 114, in create_model model = create_fn( File "/data/NZH/SAN/san/model/side_adapter/timm_wrapper.py", line 68, in vit_w240n6d8_patch16 model = _create_vision_transformer( File "/home/ubuntu/anaconda3/envs/SAN/lib/python3.10/site-packages/timm/models/vision_transformer.py", line 1510, in _create_vision_transformer return build_model_with_cfg( File "/home/ubuntu/anaconda3/envs/SAN/lib/python3.10/site-packages/timm/models/_builder.py", line 381, in build_model_with_cfg model = model_cls(kwargs) File "/home/ubuntu/anaconda3/envs/SAN/lib/python3.10/site-packages/timm/models/vision_transformer.py", line 465, in init self.patch_embed = embed_layer( TypeError: PatchEmbed.init() got an unexpected keyword argument 'dynamic_img_pad'

However, it's weird that the vision_transformer in timm does not pass the param "dynamic_img_pad" to PatchEmbed. image

A naive solution is adding the param "dynamic_img_pad=None" to the PatchEmbed in timm_wrapper and no negative impact has been found for it so far. image

MendelXu commented 1 year ago

Thanks for your information. Is it a timm version issue?

AaronNZH commented 1 year ago

That might be the case since I haven't had this problem before. And it happened after I used a new conda environment.

Existentialdredd commented 1 year ago

Looks like it may be an issue with how the model was saved, https://github.com/huggingface/pytorch-image-models/issues/1936

did you save the whole model or just the state dict?

MendelXu commented 1 year ago

Looks like it may be an issue with how the model was saved, huggingface/pytorch-image-models#1936

did you save the whole model or just the state dict?

No. I didn't save the full model. I think it is caused by this line. https://github.com/huggingface/pytorch-image-models/blob/730b907b4d45a4713cbc425cbf224c46089fd514/timm/models/vision_transformer.py#L465-L473

AaronNZH commented 1 year ago

So it seems to be a version-related issue with the latest version of timm introducing the "dynamic_img_pad" parameter. Thanks for your help.