Home > OS >  Can't deploy my large image classification model on Heroku
Can't deploy my large image classification model on Heroku

Time:07-20

I trained an image classification model that I productionized using FastAPI and I want to deploy it via Heroku.

My model is large (859 MB), hence I added it to my repo via GitHub LFS. However Heroku does not support GitHubs LFS by default and even if it did my model would basically saturate the slug size which is limited at 500MB.

The solution that I came up with is the request the model at the begining of the app like the following, then use to classify the image:

urll = 'https://github.com/nainiayoub/paintings-artist-classifier/releases/download/v1.0.0/artists_classifier.h5'
filename_model = urll.split('/')[-1]
urllib.request.urlretrieve(urll, filename_model)

model_file = filename_model

My API was successfuly deployed however it returns

503 Undocumented Error: Service Unavailable. 

Which likely means that my model was not loaded.

At this ppoint I am stuck and I am not sure how to proceed, do you have any idea or an alternative solution to deploy my large model?

CodePudding user response:

The solution that I found is to reduce my model size by converting it to tflite like the following, and using it afterwards to classify the input images:

tflite_model_name = 'model_reduced'

converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
tflite_model = converter.convert()

open(tflite_model_name   '.tflite', 'wb').write(tflite_model)

The model size was reduced to 72MB, which was added to the size of the dependencies without saturating the slug size in Huroku, hence the api was deployed successfully.

  • Related