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

Issue with loading model: "You are trying to load a weight file containing 7 layers into a model with 5 layers." #11

Open
conorg000 opened this issue Nov 26, 2020 · 1 comment

Comments

@conorg000
Copy link

conorg000 commented Nov 26, 2020

Hi there,

Thank you to the authors for making your research, code, and results public. I'm trying to run the model from sarcasm_detection_model_CNN_LSTM_DNN.py but keep coming across this error:

model loaded from file...
Traceback (most recent call last):
File "sarcasm_detection_model_CNN_LSTM_DNN.py", line 314, in
t.load_trained_model(model_file='model.json', weight_file='model.json.hdf5')
File "sarcasm_detection_model_CNN_LSTM_DNN.py", line 208, in load_trained_model
self.__load_model(self._model_file_path + model_file, self._model_file_path + weight_file)
File "sarcasm_detection_model_CNN_LSTM_DNN.py", line 215, in __load_model
self.model.load_weights(model_weight_path)
File "C:\Users\Me\Anaconda3\envs\sarcasmpy\lib\site-packages\keras\models.py", line 768, in load_weights
topology.load_weights_from_hdf5_group(f, layers, reshape=reshape)
File "C:\Users\Me\Anaconda3\envs\sarcasmpy\lib\site-packages\keras\engine\topology.py", line 3365, in load_weights_from_hdf5_group
str(len(filtered_layers)) + ' layers.')
ValueError: You are trying to load a weight file containing 7 layers into a model with 5 layers.

The model.json says that it uses Keras v 2.1.6, which I'm using. I'm also working with Python 3.7.

Has anyone come across this? Thanks for your help.

@conorg000
Copy link
Author

The model.json file seems to be missing conv1d_2 and lstm_2. Adding them has fixed the issue, though I'm not sure if that's the right way to go about it.

Is there an up-to-date model.json which matches the weights shared on Google Drive?

Thanks :)

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

1 participant