Deployment Platform: Render ✅

I suppose it may have to do with !pip list, as mrfabulous1 had mentioned earlier in the thread. However, I don’t know how to use that. I trained my model in jupyter in gradient paperspace, but I cannot run !pip list on the terminal there. !pip: not found. I tried !pip list on my pc (windows) in git bash in my fastai-v3 library but got this:

Collecting fastai
Using cached https://files.pythonhosted.org/packages/f5/e4/a7025bf28f303dbda0f862c09a7f957476fa92c9271643b4061a81bb595f/fastai-1.0.60-py3-none-any.whl
ERROR: Could not find a version that satisfies the requirement list (from versions: none)
ERROR: No matching distribution found for list

very confused >_<

Ok so I realized on jupyter its pip list. So I changed fastai==1.0.60 and numpy==1.15.4. There were many things in jupyter that were not in requirements, and some that were in requirements but not in jupyter. I did not change any of those.

Now, rerunning the deployment, more stuff runs, but I get the same error as before:

ImportError: cannot import name ‘PILLOW_VERSION’ from ‘PIL’ (/usr/local/lib/python3.7/site-packages/PIL/init.py)

@mrfabulous1 save me pls

I had the same problem. Try adding pillow==5.4.1 to your requirements.txt.

4 Likes

Perfect!!! thank you so much. I added this and then it deployed, but it got stuck at analyzing. After reading the thread above, I changed the versions of torch and torchvision and it worked!!!

Thank you!!

1 Like

Thank you so much. My issue also resolved.

Hi Mrfabuklous1

Thanks so much for all the info provided so far.

However, I’m still not able to deploy my model on Render, after training it on fastAI v3. I ran !pip list and updated the requirements text file with the versions from fastAI v3 but I’m still running into the following error:

Any thoughts on how to fix this?

Thanks so much

Hi arturola,

I think I’m running into the same error when deployiny my fastAI model on Render.

How did you solve this authorization issue with GoogleDrive?

Thanks so much for this.
Skemu

Hi Skemu hope all is well!

Can you paste a copy of your requirements.txt file here please?

Cheers mrfabulous1 :smiley::smiley:

Hi Mrfabulous1,

Thanks for the prompt reply.

Below is a copy of the requirements text file. Should I change anything?

aiofiles==0.4.0
aiohttp==3.5.4
asyncio==3.4.3
fastai==1.0.60
numpy==1.15.4
starlette==0.12.0
uvicorn==0.7.1
python-multipart==0.0.5
pillow==5.4.1
torch==1.0.0
torchvision==0.2.1

@Skemu that error means you are trying to deploy on a later version of fastai than what you trained in. You have 2 options:

Figure out which version you trained in and use it in your requirements.txt or

Re-train your model in the latest version and use it :slight_smile:

1 Like

Thanks for this.

This is what I don’t understand - I updated fastai to 1.0.60, checked this with !pip list, re-trained the model, got the export to the sharedrive, updated the requirements.txt and it still doesn’t work :frowning:

Hi Skemu

  1. Can you confirm that you tested your model on the the platform you created it on eg. put some test images in to it.

  2. Can you confirm that every library used in your requirements.txt is the same version as the platform you trained it on. (!pip list).

Cheers mrfabulous1 :smiley: :smiley:

Hi Mrfabulous1,

  1. I do confirm I’ve tested the model - just re-tested now to make sure.
  2. Yes - from what I see in the list below:

Libraries from requirements.txt:
aiofiles==0.4.0
aiohttp==3.5.4
asyncio==3.4.3
fastai==1.0.60
numpy==1.15.4
starlette==0.12.0
uvicorn==0.7.1
python-multipart==0.0.5
pillow==5.4.1
torch==1.0.0
torchvision==0.2.1

Libraries from !pip list:
asn1crypto 0.24.0
attrs 18.2.0
backcall 0.1.0
beautifulsoup4 4.7.1
bleach 3.1.0
Bottleneck 1.2.1
certifi 2018.11.29
cffi 1.11.5
chardet 3.0.4
cryptography 2.3.1
cycler 0.10.0
cymem 2.0.2
cytoolz 0.9.0.1
dataclasses 0.6
decorator 4.3.0
dill 0.2.8.2
entrypoints 0.3
fastai 1.0.60
fastprogress 0.2.2
idna 2.8
ipykernel 5.1.0
ipython 7.2.0
ipython-genutils 0.2.0
ipywidgets 7.4.2
jedi 0.13.2
Jinja2 2.10
jsonschema 3.0.0a3
jupyter 1.0.0
jupyter-client 5.2.4
jupyter-console 6.0.0
jupyter-core 4.4.0
kiwisolver 1.0.1
MarkupSafe 1.1.0
matplotlib 3.0.2
mistune 0.8.4
mkl-fft 1.0.10
mkl-random 1.0.2
msgpack 0.5.6
msgpack-numpy 0.4.3.2
murmurhash 1.0.0
nb-conda 2.2.1
nb-conda-kernels 2.2.0
nbconvert 5.3.1
nbformat 4.4.0
notebook 5.7.4
numexpr 2.6.9
numpy 1.15.4
nvidia-ml-py3 7.352.0
olefile 0.46
packaging 19.0
pandas 0.23.4
pandocfilters 1.4.2
parso 0.3.1
pexpect 4.6.0
pickleshare 0.7.5
Pillow 5.4.1
pip 18.1
plac 0.9.6
preshed 2.0.1
prometheus-client 0.5.0
prompt-toolkit 2.0.7
ptyprocess 0.6.0
pycparser 2.19
Pygments 2.3.1
pyOpenSSL 18.0.0
pyparsing 2.3.1
pyrsistent 0.14.9
PySocks 1.6.8
python-dateutil 2.7.5
pytz 2018.9
PyYAML 3.13
pyzmq 17.1.2
qtconsole 4.4.3
regex 2018.1.10
requests 2.21.0
scipy 1.2.0
Send2Trash 1.5.0
setuptools 40.6.3
six 1.12.0
soupsieve 1.7.1
spacy 2.0.18
terminado 0.8.1
testpath 0.4.2
thinc 6.12.1
toolz 0.9.0
torch 1.0.0
torchvision 0.2.1
tornado 5.1.1
tqdm 4.29.1
traitlets 4.3.2
typing 3.6.4
ujson 1.35
urllib3 1.24.1
wcwidth 0.1.7
webencodings 0.5.1
wheel 0.32.3
widgetsnbextension 3.4.2
wrapt 1.10.11

Hi Skemu hope your still having a jolly day!

Assuming the model is correct and requirements.txt is correct, we have no alternative but to look else were for the problem.

  1. Can you paste your server.py file here please?
  2. Can you confirm the link to the model is working correctly and collecting the correct model, normally you can put this link in a browser and it will start to download.

Cheers mrfabulous1 :smile::smiley:

Thanks for looking into this. The jollyness is running out thin :frowning:

  1. The link to the model works fine - just tested it now

The server.py file:

import aiohttp
import asyncio
import uvicorn
from fastai import *
from fastai.vision import *
from io import BytesIO
from starlette.applications import Starlette
from starlette.middleware.cors import CORSMiddleware
from starlette.responses import HTMLResponse, JSONResponse
from starlette.staticfiles import StaticFiles

export_file_url = ‘https://drive.google.com/file/d/12jL-v6gtaSMRT_8S9GfQ-EeCuhtbmVIV/view?usp=sharing
export_file_name = ‘export.pkl’

classes = [‘rosemary’, ‘thyme’, ‘sage’]
path = Path(file).parent

app = Starlette()
app.add_middleware(CORSMiddleware, allow_origins=[’*’], allow_headers=[‘X-Requested-With’, ‘Content-Type’])
app.mount(’/static’, StaticFiles(directory=‘app/static’))

async def download_file(url, dest):
if dest.exists(): return
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
data = await response.read()
with open(dest, ‘wb’) as f:
f.write(data)

async def setup_learner():
await download_file(export_file_url, path / export_file_name)
try:
learn = load_learner(path, export_file_name)
return learn
except RuntimeError as e:
if len(e.args) > 0 and ‘CPU-only machine’ in e.args[0]:
print(e)
message = “\n\nThis model was trained with an old version of fastai and will not work in a CPU environment.\n\nPlease update the fastai library in your training environment and export your model again.\n\nSee instructions for ‘Returning to work’ at https://course.fast.ai.”
raise RuntimeError(message)
else:
raise

loop = asyncio.get_event_loop()
tasks = [asyncio.ensure_future(setup_learner())]
learn = loop.run_until_complete(asyncio.gather(*tasks))[0]
loop.close()

@app.route(’/’)
async def homepage(request):
html_file = path / ‘view’ / ‘index.html’
return HTMLResponse(html_file.open().read())

@app.route(’/analyze’, methods=[‘POST’])
async def analyze(request):
img_data = await request.form()
img_bytes = await (img_data[‘file’].read())
img = open_image(BytesIO(img_bytes))
prediction = learn.predict(img)[0]
return JSONResponse({‘result’: str(prediction)})

if name == ‘main’:
if ‘serve’ in sys.argv:
uvicorn.run(app=app, host=‘0.0.0.0’, port=5000, log_level=“info”)

Hi, I can deploy the test app just fine. But if I try to deploy my model it runs out of memory and the app gets killed (“Server failed; Out of memory (used over 512MB)”).
I’m surprised since it’s the same resnet34 architecture, although it uses a lot more classes. Is there something I can do to reduce the memory usage of my model?

This is the repo: https://github.com/leoauri/audio-auto-tag/tree/master

Hi leoauri hope all is well.

I believe there is a 0.5Mb limit on the basic render account.
If your model file is large try testing your app with a smaller model this may work.

Cheers mrfabulous1 :smiley::smiley:

I just tried to deploy for the first time with Render but the install failed on installing Pillow??

Jan 22 08:49:38 PM  INFO[0002] Downloading base image python:3.7-slim-stretch

Jan 22 08:49:46 PM INFO[0010] RUN apt-get update && apt-get install -y git python3-dev gcc && rm -rf /var/lib/apt/lists/*
Jan 22 08:50:02 PM INFO[0026] COPY requirements.txt .
Jan 22 08:50:02 PM INFO[0026] extractedFiles: [/requirements.txt /]
Jan 22 08:50:02 PM INFO[0027] RUN pip install --upgrade -r requirements.txt
Jan 22 08:50:56 PM INFO[0080] COPY app app/
Jan 22 08:50:56 PM INFO[0080] RUN python app/server.py
Jan 22 08:51:07 PM Traceback (most recent call last):
File “app/server.py”, line 5, in
from fastai.vision import *
File “/usr/local/lib/python3.7/site-packages/fastai/vision/init.py”, line 3, in
from .learner import *
File “/usr/local/lib/python3.7/site-packages/fastai/vision/learner.py”, line 6, in
from . import models
File “/usr/local/lib/python3.7/site-packages/fastai/vision/models/init.py”, line 2, in
from torchvision.models import ResNet,resnet18,resnet34,resnet50,resnet101,resnet152
File “/usr/local/lib/python3.7/site-packages/torchvision/init.py”, line 2, in
from torchvision import datasets
File “/usr/local/lib/python3.7/site-packages/torchvision/datasets/init.py”, line 9, in
from .fakedata import FakeData
File “/usr/local/lib/python3.7/site-packages/torchvision/datasets/fakedata.py”, line 3, in
from … import transforms
File “/usr/local/lib/python3.7/site-packages/torchvision/transforms/init.py”, line 1, in
from .transforms import *
File “/usr/local/lib/python3.7/site-packages/torchvision/transforms/transforms.py”, line 17, in
from . import functional as F
File “/usr/local/lib/python3.7/site-packages/torchvision/transforms/functional.py”, line 5, in
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
ImportError: cannot import name ‘PILLOW_VERSION’ from ‘PIL’ (/usr/local/lib/python3.7/site-packages/PIL/init.py)
Jan 22 08:51:07 PM error building image: error building stage: failed to execute command: waiting for process to exit: exit status 1
Jan 22 08:51:07 PM error: exit status 1

Any advise here as I just used the standard setup with nothing special…

Thanks
Less

Hi LessW2020 hope your having a jolly day.

If you search this thread for pip list you will find that the majority of people train their models on one platform then transfer it to render.com

however often the library versions are different between the training platform (I use Colab) and the versions in the requirements.txt of the deployed app created with the teddy bear repo.

So the first step to problem solving is to run pip list on your training platform and confirm the versions are the same in your deployed app requirements.txt. if not change requirements.txt in your deployed app.
Depending on the differences it can be none or all :unamused:

Also if you search this thread you will notice people have been having issues with pillow and have added it to their requirements.txt.

Running fastai2 on colab I have also noted this error.

1 Like

Which version of pillow are you installing @LessW2020. As @mrfabulous1 mentioned, there’s some bugs with the newest version, I’d double check you’re installing the same version :slight_smile: (you can also do pip show pillow to get the version info)

2 Likes