💡
DS BW
  • Data Science Build Weeks
  • Units 3 & 4
    • Start here
    • FastAPI
    • Flask
    • Plotly Dash
    • TensorFlow on Heroku
Powered by GitBook
On this page

Was this helpful?

  1. Units 3 & 4

TensorFlow on Heroku

PreviousPlotly Dash

Last updated 4 years ago

Was this helpful?

Follow this advice if you want to use TensorFlow on Heroku!

and I dealt with a lot of errors and troubleshooting today, but we were finally able to deploy a neural network model onto Heroku! To those of you that are doing the same, these three fixes did the trick:

  1. Using pipenv with Heroku causes Heroku to use an outdated version of pip, and thus not being able to install tensorflow. We needed to run the command pip freeze > requirements.txt while in a pipenv shell in the root directory in order to write all dependencies into a requirements.txt file. Then, we deleted Pipfile and Pipfile.lock.

  2. We created a runtime.txt file in order to record what version of python we were using. For example, in the file all we needed to write was python-3.8.6

  3. Finally, the tensorflow library ended up being too large for Heroku. I saw somewhere that the library is 420M in size, and Heroku has a cap at 500M. In the requirements.txt , we needed to change tensorflow to tensorflow-cpu . Tensorflow-cpu is a version of tensorflow that uses the cpu instead of the gpu, and this is ok, because the model will still work and Heroku doesn't even have gpu capabilities. The tensorflow-cpu library ended up being ~200M smaller than the standard tensorflow library.

  4. And voila! After hours of troubleshooting, the model is deployed! Maybe it was just me but I recommend using tensorflow-cpu 2.3.1!! Not 2.4! Had some very mysterious issues which heroku logs gave me absolutely no details on. It came down to that. Not sure if it's 100% necessary, but definitely worth trying if one is running into trouble.

Tomás Phillips
@Nathan McDonough
Ben Somerville