Gcloud app engine error


(Jinu Daniel) #1

Hello,

I am trying to create a classifier which will classify popular Indian cars. I have trained it using resnet 50 and saved the model in google drive. When i am trying it to deploy to google app engine, I am not able to do so. It is failing with the below error.

You are using pip version 19.0.1, however version 19.0.2 is available.

You should consider upgrading via the ‘pip install --upgrade pip’ command.
Removing intermediate container 2496b626f1cc
—> a761bd747ac3
Step 6/9 : COPY app app/
—> 6cdefe0e5b2c
Step 7/9 : RUN python app/server.py
—> Running in 8538549d96a9
Traceback (most recent call last):
File “app/server.py”, line 40, in
learn = loop.run_until_complete(asyncio.gather(*tasks))[0]
File “/usr/local/lib/python3.6/asyncio/base_events.py”, line 484, in run_until_complete
return future.result()
File “app/server.py”, line 35, in setup_learner
learn.load(model_file_name)
File “/usr/local/lib/python3.6/site-packages/fastai/basic_train.py”, line 238, in load
state = torch.load(self.path/self.model_dir/f’{name}.pth’, map_location=device)
File “/usr/local/lib/python3.6/site-packages/torch/serialization.py”, line 368, in load
return _load(f, map_location, pickle_module)
File “/usr/local/lib/python3.6/site-packages/torch/serialization.py”, line 532, in _load
magic_number = pickle_module.load(f)
_pickle.UnpicklingError: invalid load key, ‘<’.
The command ‘/bin/sh -c python app/server.py’ returned a non-zero code: 1
ERROR
ERROR: build step 0 “gcr.io/cloud-builders/docker” failed: exit status 1

server.py is located at github

Any help would be appreciated.


(Shawn P Emhe II) #2

Per Jeremy’s reply to another post here, that is a problem with the model URL. I was using google drive and having the same problem. I was able to get around it by using wget from the shell to download the file into the models directory of the app. Then the model needs to be renamed to model.pth or the model_file_name variable will need to be changed.
Also, you will need to update line 34 to use models.resnet50.


(Jinu Daniel) #3

Thanks for the help. I was able to download the model via wget but i encountered a another issue while deploying the app. It was related to transforms. While debugging i could see that the starter code for Google App Engine uses a deprecated method for making inference ImageDataBunch.single_from_classes. Check the source code for mode details.

So I have modified my server.py to use load_learner and used export.pkl file instead of using model.pth file. After that I was able to deploy the app to app engine and it is up and running now.

App link : https://western-shuttle-230416.appspot.com/


(Shawn P Emhe II) #4

Good catch on the deprecated function. That pointed me in the direction to realize that kaggle was using an older version of fastai without learn.export included. It looks like the differences between the versions also included an incompatible numpy version that was preventing me from deploying my GCP app engine. After updating fastai in my kaggle notebook and using learn.export like you did above I was finally able to get up and running.


(Jinu Daniel) #5

Glad it helped.