Puting the Model Into Production: Web Apps

I just fixed it upstream: you need to pin the version of uvicorn in your requirements.txt: https://github.com/render-examples/fastai-v3/commit/740564decf1704b1e30b1364cc7327245659c7e9

1 Like

Anyone know how to get the example zeit web app working in v2? I think all you need to do is reconfigure the now.json file, but I’m not sure what needs to be changed.

@waydegg if you figure it out, let us know. I’ve removed the Zeit guide for now since it doesn’t work.

2 Likes

The problem is that v2 of Zeit’s Now service does not provide Docker based deploys.
They have a builder that should be able to build python apps, but the problem is that the newest version of python it supports is 3.4 and for fastai/pytorch we need a newer version of python. So that is where I failed.

Many thanks @anurag. My Web app works quite well now :slight_smile:

Note: this time, after installation of starlette in my fastai v1 environment, I tested my Web app locally on my computer instead of deploying it directly to Render.com. It saved me a lot of time (local debugging)!

One question: do you know how to run the starlette Web app in a jupyter notebook (like displaying http://localhost:5042/ into a notebook)?

1 Like

I’m trying to adapt the html and css files of the “fastai v1 Web App on Render” to be mobile-friendly thanks to online guides like “How to Make a Mobile-Friendly Website: Responsive Design in CSS”.

It does help but at the end, there is still a problem: the Web app (the one from Jeremy as well, at least on my devices) works on Windows desktops and android smartphones but not on IOS Apple devices (notebooks, ipads and iphones). The problem comes from the Safari Web browser? Someone knows how to solve this issue? Thanks.

AFAIK the simplest way would be to embed it in an iframe using IPython: https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.IFrame

1 Like

Thanks. It works great :slight_smile:
Firstly, launch your app in a terminal with python app/server.py serve, and then run the following code in your jupyter notebook (choose the height in pixels you want like height=500):

from IPython.display import IFrame
IFrame('http://localhost:5042/', width='100%', height=height)

Note: this notebook about IPython.display has great examples of code.

3 Likes

Noob Question: How to do this locally? Do I need to download the github folder on my local system. Also how do I install all the dependencies?

You want to run the web app locally right ? You need to clone the Render github repo, install all the dependencies in requirement.txt and then run server.py with python server.py serve in the command line.

Thanks. It worked

Please how can I show a plot like this in the web app
prob

you can try d3.js on the front-end side and just pass the probability scores as a list or json with class-names as keys probs as values.

1 Like

Hi – @anurag – I followed the sparklette instructions but when I deploy I get an error that I’m using an old version of fastai. But I did just do a pull. Any ideas?

Thanks,
z

Did you restart your kernel and retrain/reexport your model?

Some models are still running into the CUDA issue, and only the dev version version of fastai works. See https://github.com/fastai/fastai/pull/1502#issuecomment-459165078

I have build an web application with help of flask and flask_wtforms, also I have a blog post about it on Medium and all the code is on my GitHub.

1 Like

Hello @pierreguillou @anurag ,
While trying to deploy my trained model on GCP, I am getting a similar error as you got earlier. The error I am getting is as follows:-

Blockquote

Traceback (most recent call last):
File “app/server.py”, line 37, in
learn = loop.run_until_complete(asyncio.gather(*tasks))[0]
File “/usr/local/lib/python3.6/asyncio/base_events.py”, line 484, in run_until_complete
return future.result()
File “app/server.py”, line 32, in setup_learner
learn.load(model_file_name)
File “/usr/local/lib/python3.6/site-packages/fastai/basic_train.py”, line 248, in load
get_model(self.model).load_state_dict(state, strict=strict)
File “/usr/local/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 769, in load_state_dict
self.class.name, “\n\t”.join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for Sequential:
Missing key(s) in state_dict: “0.0.weight”, “0.1.weight”, “0.1.bias”, “0.1.running_mean”, “0.1.running_var”, “0.4.0.conv1.weight”, “0.4.0.bn1.weight”, “0.4.0.bn1.bias”, “0.4.0.bn1.running_mean”, “0.4.0.bn1.running_var”, “0.4.0.conv2.weight”, “0.4.0.bn2.weight”, “0.4.0.bn2.bias”, “0.4.0.bn2.running_mean”, “0.4.0.bn2.running_var”, “0.4.1.conv1.weight”, “0.4.1.bn1.weight”, “0.4.1.bn1.bias”, “0.4.1.bn1.running_mean”, “0.4.1.bn1.running_var”, “0.4.1.conv2.weight”, “0.4.1.bn2.weight”, “0.4.1.bn2.bias”, “0.4.1.bn2.running_mean”, “0.4.1.bn2.running_var”, “0.4.2.conv1.weight”, “0.4.2.bn1.weight”, “0.4.2.bn1.bias”, “0.4.2.bn1.running_mean”, “0.4.2.bn1.running_var”, “0.4.2.conv2.weight”, “0.4.2.bn2.weight”, “0.4.2.bn2.bias”, “0.4.2.bn2.running_mean”, “0.4.2.bn2.running_var”, “0.5.0.conv1.weight”, “0.5.0.bn1.weight”, “0.5.0.bn1.bias”, “0.5.0.bn1.running_mean”, “0.5.0.bn1.running_var”, “0.5.0.conv2.weight”, “0.5.0.bn2.weight”, “0.5.0.bn2.bias”, “0.5.0.bn2.running_mean”, “0.5.0.bn2.running_var”, “0.5.0.downsample.0.weight”, “0.5.0.downsample.1.weight”, “0.5.0.downsample.1.bias”, “0.5.0.downsample.1.running_mean”, “0.5.0.downsample.1.running_var”, “0.5.1.conv1.weight”, “0.5.1.bn1.weight”, “0.5.1.bn1.bias”, “0.5.1.bn1.running_mean”, “0.5.1.bn1.running_var”, “0.5.1.conv2.weight”, “0.5.1.bn2.weight”, “0.5.1.bn2.bias”, “0.5.1.bn2.running_mean”, “0.5.1.bn2.running_var”, “0.5.2.conv1.weight”, “0.5.2.bn1.weight”, “0.5.2.bn1.bias”, “0.5.2.bn1.running_mean”, “0.5.2.bn1.running_var”, “0.5.2.conv2.weight”, “0.5.2.bn2.weight”, “0.5.2.bn2.bias”, “0.5.2.bn2.running_mean”, “0.5.2.bn2.running_var”, “0.5.3.conv1.weight”, “0.5.3.bn1.weight”, “0.5.3.bn1.bias”, “0.5.3.bn1.running_mean”, “0.5.3.bn1.running_var”, “0.5.3.conv2.weight”, “0.5.3.bn2.weight”, “0.5.3.bn2.bias”, “0.5.3.bn2.running_mean”, “0.5.3.bn2.running_var”, “0.6.0.conv1.weight”, “0.6.0.bn1.weight”, “0.6.0.bn1.bias”, “0.6.0.bn1.running_mean”, “0.6.0.bn1.running_var”, “0.6.0.conv2.weight”, “0.6.0.bn2.weight”, “0.6.0.bn2.bias”, “0.6.0.bn2.running_mean”, “0.6.0.bn2.running_var”, “0.6.0.downsample.0.weight”, “0.6.0.downsample.1.weight”, “0.6.0.downsample.1.bias”, “0.6.0.downsample.1.running_mean”, “0.6.0.downsample.1.running_var”, “0.6.1.conv1.weight”, “0.6.1.bn1.weight”, “0.6.1.bn1.bias”, “0.6.1.bn1.running_mean”, “0.6.1.bn1.running_var”, “0.6.1.conv2.weight”, “0.6.1.bn2.weight”, “0.6.1.bn2.bias”, “0.6.1.bn2.running_mean”, “0.6.1.bn2.running_var”, “0.6.2.conv1.weight”, “0.6.2.bn1.weight”, “0.6.2.bn1.bias”, “0.6.2.bn1.running_mean”, “0.6.2.bn1.running_var”, “0.6.2.conv2.weight”, “0.6.2.bn2.weight”, “0.6.2.bn2.bias”, “0.6.2.bn2.running_mean”, “0.6.2.bn2.running_var”, “0.6.3.conv1.weight”, “0.6.3.bn1.weight”, “0.6.3.bn1.bias”, “0.6.3.bn1.running_mean”, “0.6.3.bn1.running_var”, “0.6.3.conv2.weight”, “0.6.3.bn2.weight”, “0.6.3.bn2.bias”, “0.6.3.bn2.running_mean”, “0.6.3.bn2.running_var”, “0.6.4.conv1.weight”, “0.6.4.bn1.weight”, “0.6.4.bn1.bias”, “0.6.4.bn1.running_mean”, “0.6.4.bn1.running_var”, “0.6.4.conv2.weight”, “0.6.4.bn2.weight”, “0.6.4.bn2.bias”, “0.6.4.bn2.running_mean”, “0.6.4.bn2.running_var”, “0.6.5.conv1.weight”, “0.6.5.bn1.weight”, “0.6.5.bn1.bias”, “0.6.5.bn1.running_mean”, “0.6.5.bn1.running_var”, “0.6.5.conv2.weight”, “0.6.5.bn2.weight”, “0.6.5.bn2.bias”, “0.6.5.bn2.running_mean”, “0.6.5.bn2.running_var”, “0.7.0.conv1.weight”, “0.7.0.bn1.weight”, “0.7.0.bn1.bias”, “0.7.0.bn1.running_mean”, “0.7.0.bn1.running_var”, “0.7.0.conv2.weight”, “0.7.0.bn2.weight”, “0.7.0.bn2.bias”, “0.7.0.bn2.running_mean”, “0.7.0.bn2.running_var”, “0.7.0.downsample.0.weight”, “0.7.0.downsample.1.weight”, “0.7.0.downsample.1.bias”, “0.7.0.downsample.1.running_mean”, “0.7.0.downsample.1.running_var”, “0.7.1.conv1.weight”, “0.7.1.bn1.weight”, “0.7.1.bn1.bias”, “0.7.1.bn1.running_mean”, “0.7.1.bn1.running_var”, “0.7.1.conv2.weight”, “0.7.1.bn2.weight”, “0.7.1.bn2.bias”, “0.7.1.bn2.running_mean”, “0.7.1.bn2.running_var”, “0.7.2.conv1.weight”, “0.7.2.bn1.weight”, “0.7.2.bn1.bias”, “0.7.2.bn1.running_mean”, “0.7.2.bn1.running_var”, “0.7.2.conv2.weight”, “0.7.2.bn2.weight”, “0.7.2.bn2.bias”, “0.7.2.bn2.running_mean”, “0.7.2.bn2.running_var”, “1.2.weight”, “1.2.bias”, “1.2.running_mean”, “1.2.running_var”, “1.4.weight”, “1.4.bias”, “1.6.weight”, “1.6.bias”, “1.6.running_mean”, “1.6.running_var”, “1.8.weight”, “1.8.bias”.
Unexpected key(s) in state_dict: “conv1.weight”, “bn1.running_mean”, “bn1.running_var”, “bn1.weight”, “bn1.bias”, “layer1.0.conv1.weight”, “layer1.0.bn1.running_mean”, “layer1.0.bn1.running_var”, “layer1.0.bn1.weight”, “layer1.0.bn1.bias”, “layer1.0.conv2.weight”, “layer1.0.bn2.running_mean”, “layer1.0.bn2.running_var”, “layer1.0.bn2.weight”, “layer1.0.bn2.bias”, “layer1.1.conv1.weight”, “layer1.1.bn1.running_mean”, “layer1.1.bn1.running_var”, “layer1.1.bn1.weight”, “layer1.1.bn1.bias”, “layer1.1.conv2.weight”, “layer1.1.bn2.running_mean”, “layer1.1.bn2.running_var”, “layer1.1.bn2.weight”, “layer1.1.bn2.bias”, “layer2.0.conv1.weight”, “layer2.0.bn1.running_mean”, “layer2.0.bn1.running_var”, “layer2.0.bn1.weight”, “layer2.0.bn1.bias”, “layer2.0.conv2.weight”, “layer2.0.bn2.running_mean”, “layer2.0.bn2.running_var”, “layer2.0.bn2.weight”, “layer2.0.bn2.bias”, “layer2.0.downsample.0.weight”, “layer2.0.downsample.1.running_mean”, “layer2.0.downsample.1.running_var”, “layer2.0.downsample.1.weight”, “layer2.0.downsample.1.bias”, “layer2.1.conv1.weight”, “layer2.1.bn1.running_mean”, “layer2.1.bn1.running_var”, “layer2.1.bn1.weight”, “layer2.1.bn1.bias”, “layer2.1.conv2.weight”, “layer2.1.bn2.running_mean”, “layer2.1.bn2.running_var”, “layer2.1.bn2.weight”, “layer2.1.bn2.bias”, “layer3.0.conv1.weight”, “layer3.0.bn1.running_mean”, “layer3.0.bn1.running_var”, “layer3.0.bn1.weight”, “layer3.0.bn1.bias”, “layer3.0.conv2.weight”, “layer3.0.bn2.running_mean”, “layer3.0.bn2.running_var”, “layer3.0.bn2.weight”, “layer3.0.bn2.bias”, “layer3.0.downsample.0.weight”, “layer3.0.downsample.1.running_mean”, “layer3.0.downsample.1.running_var”, “layer3.0.downsample.1.weight”, “layer3.0.downsample.1.bias”, “layer3.1.conv1.weight”, “layer3.1.bn1.running_mean”, “layer3.1.bn1.running_var”, “layer3.1.bn1.weight”, “layer3.1.bn1.bias”, “layer3.1.conv2.weight”, “layer3.1.bn2.running_mean”, “layer3.1.bn2.running_var”, “layer3.1.bn2.weight”, “layer3.1.bn2.bias”, “layer4.0.conv1.weight”, “layer4.0.bn1.running_mean”, “layer4.0.bn1.running_var”, “layer4.0.bn1.weight”, “layer4.0.bn1.bias”, “layer4.0.conv2.weight”, “layer4.0.bn2.running_mean”, “layer4.0.bn2.running_var”, “layer4.0.bn2.weight”, “layer4.0.bn2.bias”, “layer4.0.downsample.0.weight”, “layer4.0.downsample.1.running_mean”, “layer4.0.downsample.1.running_var”, “layer4.0.downsample.1.weight”, “layer4.0.downsample.1.bias”, “layer4.1.conv1.weight”, “layer4.1.bn1.running_mean”, “layer4.1.bn1.running_var”, “layer4.1.bn1.weight”, “layer4.1.bn1.bias”, “layer4.1.conv2.weight”, “layer4.1.bn2.running_mean”, “layer4.1.bn2.running_var”, “layer4.1.bn2.weight”, “layer4.1.bn2.bias”, “fc.weight”, “fc.bias”.
The command ‘/bin/sh -c python app/server.py’ returned a non-zero code: 1
ERROR
ERROR: build step 0 “gcr.io/cloud-builders/docker” failed: exit status 1

Blockquote

I am using Fastai- version 3. I have used resnet18 model.
I am not able to get around this error. Any help would be appreciated.

Thanks,
Rajat

Hello @RajatP, does your Web app work locally on your computer? (see local testing on GCP)

Hi @pierreguillou, Thanks for replying.
I solved this error by wrapping my model in nn.DataParallel before saving. I have not yet tried to deploy my Web app on locally on my computer.
But, the app created is stuck at “analyzing” and not moving ahead.
Do you have any idea how can I solve this problem?

Sorry but I have no idea. My best advice is to test it locally in order to solve your problem.

1 Like