transformer-cnn-emotion-recognition icon indicating copy to clipboard operation
transformer-cnn-emotion-recognition copied to clipboard

Notebook fails to load pre-trained models

Open taavi223 opened this issue 4 years ago • 2 comments

I'm getting the following error in the Load the Trained Model from Checkpoint for Evaluation section when trying to load the pre-trained models in the repo.

# pick load folder  
load_folder = '/content/gdrive/My Drive/DL/models/checkpoints'  

# pick the epoch to load
epoch = '429'
model_name = f'parallel_all_you_wantFINAL-{epoch}.pkl'

# make full load path
load_path = os.path.join(load_folder, model_name)

## instantiate empty model and populate with params from binary 
model = parallel_all_you_want(len(emotions_dict))
load_checkpoint(optimizer, model, load_path)

print(f'Loaded model from {load_path}')

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-51-de60b48d9410> in <module>
     11 ## instantiate empty model and populate with params from binary
     12 model = parallel_all_you_want(len(emotions_dict))
---> 13 load_checkpoint(optimizer, model, load_path)
     14 
     15 print(f'Loaded model from {load_path}')

<ipython-input-50-2469ccaf4901> in load_checkpoint(optimizer, model, filename)
     11 def load_checkpoint(optimizer, model, filename):
     12     checkpoint_dict = torch.load(filename, map_location=torch.device('cpu'))
---> 13     epoch = checkpoint_dict['epoch']
     14     model.load_state_dict(checkpoint_dict['model'])
     15     if optimizer is not None:

KeyError: 'epoch'

It appears that the pre-trained model files were not generated using the structure expected by the notebook.

taavi223 avatar Dec 07 '20 20:12 taavi223

Same problem

axe980703 avatar May 02 '21 20:05 axe980703

same here

MuhammedTech avatar Nov 17 '21 09:11 MuhammedTech