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

Can't load weights when training the model #27

Open
khatchad opened this issue Jul 24, 2024 · 3 comments
Open

Can't load weights when training the model #27

khatchad opened this issue Jul 24, 2024 · 3 comments

Comments

@khatchad
Copy link
Contributor

I'm getting the following error when trying to train the model:

Traceback (most recent call last):                                                                                                                                                                                                                                                                                                                   
  File "/home/user/git/Python-Subjects/tf-eager-fasterrcnn/train_model.py", line 73, in <module>                                                                                                                                                                                                                                                   
    model.load_weights('weights/faster_rcnn.h5', by_name=True)                                                                                                                                                                                                                                                                                       
  File "/home/user/.local/lib/python3.10/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler                                                                                                                                                                                                                                  
    raise e.with_traceback(filtered_tb) from None                                                                                                                                                                                                                                                                                                    
  File "/home/user/.local/lib/python3.10/site-packages/keras/engine/training.py", line 2644, in load_weights                                                                                                                                                                                                                                       
    raise ValueError(                                                                                                                                                                                                                                                                                                                                
ValueError: Unable to load weights saved in HDF5 format into a subclassed Model which has not created its variables yet. Call the Model first, then load the weights. 

I have the dataset in place. I am using TensorFlow 2.9.3.

@Viredery
Copy link
Owner

Before loading weights, this line must be executed:

_ = model((batch_imgs, batch_metas), training=False)

@khatchad
Copy link
Contributor Author

Yup, it's number 8 in https://github.com/Viredery/tf-eager-fasterrcnn/blob/0afe472d9437ae76debbc5bb27b8ec43719ce8f5/train_model.ipynb.

I noticed that that directory (weights) is empty, i.e., there is no 'weights/faster_rcnn.h5 after the execution. I also tried putting the prebuilt file from your Google Drive there, but I get the same error.

Could it have something to do with the TF version?

@khatchad
Copy link
Contributor Author

khatchad commented Aug 1, 2024

Actually, since we are training from scratch in that file, I think we can avoid loading the weights.

khatchad added a commit to ponder-lab/tf-eager-fasterrcnn that referenced this issue Aug 1, 2024
We are training from scratch. See
Viredery#27 (comment).
khatchad added a commit to ponder-lab/tf-eager-fasterrcnn that referenced this issue Aug 1, 2024
We are training from scratch in the code above this line. I left it as a comment in case someone
wants to load a pretrained model. See Viredery#27 (comment).
khatchad added a commit to ponder-lab/tf-eager-fasterrcnn that referenced this issue Aug 1, 2024
We are training from scratch in the code above this line. I left it as a comment in case someone
wants to load a pretrained model. See Viredery#27 (comment).
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