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

用预训练模型做微调 #5

Open
linhh29 opened this issue Apr 27, 2023 · 4 comments
Open

用预训练模型做微调 #5

linhh29 opened this issue Apr 27, 2023 · 4 comments

Comments

@linhh29
Copy link

linhh29 commented Apr 27, 2023

您好!
请问怎么样用您的在market上预训练好的模型(swin_small_market.pth)来进行微调呢?
我根据readme的步骤可以用swin_small.pth来微调,但是将MODEL.PRETRAIN_PATH设为swin_small_market.pth会报错
image

@cwhgn
Copy link
Collaborator

cwhgn commented Apr 28, 2023

您好,感谢关注。我们当时的代码只为了读取SOLIDER训练的初始化模型,没有适配SOLIDER-REID训练的模型作为初始化。如果你希望用SOLIDER-REID训练的模型(比如swin_small_market.pth)作为初始化,可以把下面代码进行下替换:

self.base.init_weights(model_path)

替换成下面类似代码:

param_dict = torch.load(model_path)
for i in param_dict:
    self.state_dict()[i].copy_(param_dict[i])

@linhh29
Copy link
Author

linhh29 commented Apr 28, 2023

您好!按您所说替换之后,还是报错了
image

@cwhgn
Copy link
Collaborator

cwhgn commented Apr 29, 2023

这是因为你训练的数据类别和market不一致,导致classifier参数无法载入。你可以改成如下代码:

param_dict = torch.load(model_path)
for i in param_dict:
    if 'classifier' in i:
        continue
    self.state_dict()[i].copy_(param_dict[i])

@linhh29
Copy link
Author

linhh29 commented Apr 30, 2023

好的,感谢您!非常棒的工作

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

2 participants