Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to solve this problem? #11

Open
OhJackHu opened this issue Apr 6, 2022 · 4 comments
Open

How to solve this problem? #11

OhJackHu opened this issue Apr 6, 2022 · 4 comments

Comments

@OhJackHu
Copy link

OhJackHu commented Apr 6, 2022

Hi, bro, your code is very beautiful, but I made the following error when using swin-t to run the code. How can I use the pre training weight downloaded by myself instead of downloading at run time.
Traceback (most recent call last):
File "train.py", line 396, in
train_loader, test_loader, model, optimizer, schedule = set_environment(args)
File "train.py", line 94, in set_environment
model = SwinVit12(
File "/home/pengtl/jackhu/FGVC-PIM-master/models/SwinVit12.py", line 202, in init
self.extractor = timm.create_model('swin_large_patch4_window12_384_in22k', pretrained=True)
File "/home/pengtl/jackhu/FGVC-PIM-master/timm/models/factory.py", line 81, in create_model
model = create_fn(pretrained=pretrained, **kwargs)
File "/home/pengtl/jackhu/FGVC-PIM-master/timm/models/swin_transformer.py", line 654, in swin_large_patch4_window12_384_in22k
model = _create_swin_transformer('swin_large_patch4_window12_384_in22k', pretrained=pretrained, **model_kwargs)
File "/home/pengtl/jackhu/FGVC-PIM-master/timm/models/swin_transformer.py", line 562, in _create_swin_transformer
model = build_model_with_cfg(
File "/home/pengtl/jackhu/FGVC-PIM-master/timm/models/helpers.py", line 457, in build_model_with_cfg
load_pretrained(
File "/home/pengtl/jackhu/FGVC-PIM-master/timm/models/helpers.py", line 184, in load_pretrained
state_dict = load_state_dict_from_url(pretrained_url, progress=progress, map_location='cpu')
File "/home/pengtl/anaconda3/lib/python3.8/site-packages/torch/hub.py", line 528, in load_state_dict_from_url
return torch.load(cached_file, map_location=map_location)
File "/home/pengtl/anaconda3/lib/python3.8/site-packages/torch/serialization.py", line 593, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "/home/pengtl/anaconda3/lib/python3.8/site-packages/torch/serialization.py", line 762, in _legacy_load
magic_number = pickle_module.load(f, **pickle_load_args)
_pickle.UnpicklingError: invalid load key, '<'.

@OhJackHu
Copy link
Author

If I use the following code, can I avoid downloading pre training weights?

self.extractor = timm.create_model('swin_large_patch4_window12_384_in22k', pretrained=False)
self.extractor = load_model_weights(self.extractor, './swin_large_patch4_window12_384_in22k.pth')

@chou141253
Copy link
Owner

Sure! But we use timm model, please check the pre-trained model is fitting timm provided.

@OhJackHu
Copy link
Author

OhJackHu commented Apr 24, 2022

I used the pre-training weight downloaded by myself, and the following errors occurred:

QQ截图20220424203606

@zzr9zzr
Copy link

zzr9zzr commented Oct 18, 2022

I used the pre-training weight downloaded by myself, and the following errors occurred:

QQ截图20220424203606

you should change the 'state_dict' to 'model'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants