Yiming-M / CLIP-EBC

The official implementation of the crowd counting model CLIP-EBC.
MIT License
43 stars 7 forks source link

Use pretrained model as initial weight #4

Closed ml-cv-developer closed 6 months ago

ml-cv-developer commented 6 months ago

I am trying to use a pretrained model in here as initial weight. https://drive.google.com/drive/folders/1hEHRsyOxvtbnq8UR0iXnQ7kcKO7aaYVM?usp=sharing But got this error.

Traceback (most recent call last):
  File "/home/viso/crowd_clip_ebc/CLIP-EBC/trainer.py", line 215, in <module>
    main()
  File "/home/viso/crowd_clip_ebc/CLIP-EBC/trainer.py", line 211, in main
    run(0, 1, args)
  File "/home/viso/crowd_clip_ebc/CLIP-EBC/trainer.py", line 123, in run
    model, optimizer, scheduler, start_epoch, loss_info, hist_scores, best_scores = load_checkpoint(args, model, optimizer, scheduler)
  File "/home/viso/crowd_clip_ebc/CLIP-EBC/utils/train_utils.py", line 111, in load_checkpoint
    model.load_state_dict(ckpt["model_state_dict"])
KeyError: 'model_state_dict'

Can you please give me a guide how I can use pre-trained weights as initial weight of the training? Best regards,

Yiming-M commented 6 months ago

Hi @ml-cv-developer,

Thanks for your interests in our work. The pre-trained weights are for evaluation. If you want to initialize the model, you need to explicitly write something like

weights = torch.load("weight_path.pth")
model.load_state_dict(weights)

instead of turning it into a ckpt.pth, as this file is used to store the states of model, optimizer, scheduler, etc.

Let me know if this doesn't solve your problem.

Many thanks, Yiming

Yiming-M commented 6 months ago

Hi @ml-cv-developer ,

We haven't heard from you for two weeks, so we guess that this issue has been solved. Please feel free to re-open it if this is not the case.

Many thanks, Yiming