Hi everyone.
I have a model that classifies different cars.
Its size is 80 MB after I export it (I’m using resnet34).
In addition to the the size of the model, all of the libraries of fastai have a size of about 700MB.
All of that combined is over 500MB which is the limit in google cloud for deployment of cloud functions.
My question is, is there any way to reduce the size of the model and libraries significantly enough to go under 500MB?
Thanks!
Edit: for different reasons, the model has to be deployed on a cloud function. On each activation I just load the model and make the prediction.
Hello @hyaxia are your sure that you forced the installation to use CPU version ?
If you just did pip install fastai, fastai will pull the CUDA version of Pytorch (arround 700MB I think).
It takes less than 1sec for my Cloud Functions, which runs a 90MB model, to download model from bucket, load_learner, predict and return the result. I picked 1GB of RAM. Doesn’t work with 256MB.
edit: better version with requests
main.py
from fastai.learner import load_learner
from fastai.vision.core import PILImage
from google.cloud import storage
import requests as r
storage_client = storage.Client()
bucket = storage_client.get_bucket("model-chef-oeuvre")
blob = bucket.blob("model.pkl")
blob.download_to_filename("/tmp/model.pkl")
learner = load_learner("/tmp/model.pkl")
def run(request):
response = r.get(
request.args["image"],
headers={
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
}
)
# PILImage.create(BytesIO(response.content)
label, label_idx, _ = learner.predict(PILImage.create(response.content))
return str(label)
Hey @aquadzn, thanks for the reply, I did try to change my requirements.txt file to match yours, but it fails with the message {"ResourceType":"gcp-types/cloudfunctions-v1:projects.locations.functions","ResourceErrorCode":"400","ResourceErrorMessage":"Build failed: pip_install_from_wheelshad stderr output:\n/opt/python3.7/bin/python3.7: No module named pip\n\nerror:pip_install_from_wheels returned code: 1; Error ID: ECB5F712"}.
From what I’ve red, it is related to something internal in one of the libraries.
Is your deployment process unique by any means?
Also, when I try to install torch==1.7.0+cpu locally, it tell me it did not found that version.
I’m using mac, but still its suppose to find it.