TensorFlow on Heroku
Last updated
Was this helpful?
Last updated
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:
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
.
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
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.
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.