Error deploying on Google App Engine - Missing key(s)

I have had several issues when deploying on Google App Engine and solved them thanks to this forum :slight_smile: but I am not sure how to progress with the following one:

I am deploying a modified version of the bear classification. The “gcloud app deploy” command throws the error below (it seems as is the model is not properly loaded?)

Any hint that may point me to the right path will be welcome.

File “/usr/local/lib/python3.6/site-packages/torch/nn/modules/”, line 769, in load_state_dict, “\n\t”.join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for Sequential:
Missing key(s) in state_dict: “0.0.weight”, “0.1.weight”, “0.1.bias”, “0.1.running_mean”, “0.1.running_var”, …

Unexpected key(s) in state_dict: “opt_func”, “loss_func”, “metrics”, “true_wd”, “bn_wd”, “wd”, “train_bn”, “model_dir”, “callback_fns”, “cb_state”, “model”, “data”, “cls”.
The command ‘/bin/sh -c python app/’ returned a non-zero code: 1

I think even I ran into this error while deploying my app to App Engine. Try to use export.pkl file instead of the pth file. Also use the method load_learner instead of ImageDataBunch.single_from_classes. Do refer my previous answer for more details

Also refer the below post and see if it helps you.

Thanks a lot!
It was the deprecated ImageDataBunch.single_from_classes … also your code example was very useful. It is now deployed :slightly_smiling_face:

Now I have another problem… it stays in “Analyzing” and I have an error in the log (TypeError: Object of type ‘Category’ is not JSON serializable) … but I will look for this in the forum or open a new thread, as it is not related to app deployment.


Do refer this post. It contains the answer you are looking for.

1 Like