Deployment Platform: Render ✅

Hi Matt that is correct if.
Once you get it working on your desktop the fun begins when you deploy it.

The render guide is good however it is likely you may have a few issues deploying it. So check the posts on this thread.

On point 3 your library versions on your laptop may be different to the repository. So you may have to change the requirements.txt when you deploy the code on render.com. See the threads which contain !pip list for an explanation.

Cheers mrfabulous1:smiley::smiley:

1 Like

If want to host you model on Google Drive and still have the problem of not being able to download the large, this is the code I´ve used on server.py, it replaces the function download_file():

Note that now instead of the url, you just pass the id of the file:

model_file_id = '19xqtsyusFddcSkdCm1hlhW3y6ljGck5L'
def download_file_from_google_drive(id, destination):
    if destination.exists():
        return
    URL = "https://docs.google.com/uc?export=download"
    session = requests.Session()
    response = session.get(URL, params = { 'id' : id }, stream = True)
    token = get_confirm_token(response)
    if token:
        params = { 'id' : id, 'confirm' : token }
        response = session.get(URL, params = params, stream = True)
    save_response_content(response, destination)

def get_confirm_token(response):
    for key, value in response.cookies.items():
        if key.startswith('download_warning'):
            return value
    return None

def save_response_content(response, destination):
    CHUNK_SIZE = 32768
    with open(destination, "wb") as f:
        for chunk in response.iter_content(CHUNK_SIZE):
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)

async def setup_learner():
    download_file_from_google_drive(model_file_id, path/'models'/f'{model_file_name}.pth')
    data_bunch = ImageDataBunch.single_from_classes(path, classes,
        ds_tfms=get_transforms(), size=224).normalize(imagenet_stats)
    learn = cnn_learner(data_bunch, models.resnet34, pretrained=False)
    learn.load(model_file_name)
    return learn

Did Render start charging fastai students? I noticed an email telling me to add a credit card and also an unpaid bill.

Yes, Render has always charged for compute, but a few months ago we added $25 in credits to new accounts. I believe you got an email because your credits ran out.

1 Like

Thanks for clarifying.

Hello everyone! I’ve deployed my model on Render but the website seems to be stuck on the “Analyzing…” mode. Looking through the logs, I do see prediction = learn.predict(img)[0] so I know it’s predicting, but no result shows on the website.

The error in the Render logs I get is AttributeError: ‘Conv2d’ object has no attribute ‘padding_mode’. Any help / advice?

Thanks in advance and thanks @anurag for Render!

1 Like

I get this same error when trying to predict:

img = data.test_ds[0][0]
learn.predict(img)

~/.conda/envs/fastai_v1_2/lib/python3.7/site-packages/fastai/torch_core.py in <listcomp>(.0)
    325 def grab_idx(x,i,batch_first:bool=True):
    326     "Grab the `i`-th batch in `x`, `batch_first` stating the batch dimension."
--> 327     if batch_first: return ([o[i].cpu() for o in x]   if is_listy(x) else x[i].cpu())
    328     else:           return ([o[:,i].cpu() for o in x] if is_listy(x) else x[:,i].cpu())
    329 

AttributeError: 'list' object has no attribute 'cpu'

Did you ever work out what was wrong?

Hi wigglepuff hope all is well!

Having created a number of different models now, all but one of the faults when deploying the model assuming it works in development, have been resolved in one of two ways, unless I made a mistake in configuring the model or building the app.

  1. I have read that fastai is generally not backwards compatible as many of the libraries such as pytorch are upgraded independently. So almost every time I create a model in Jupyter notebook by the time I have spent a day or week completing the training and building the app various libraries have been changed.

The solution to this if you are using the teddy bear template as the basis for your app, is to use !pip list and confirm that the library versions used in your development environment that you trained the model in are the same on render. You normally have to change the versions in the requirements.txt. search this forum topic for !pip list. for further details.

  1. My models seem to have a problem with my current version of Safari.

My solution test in all the top browsers.

Hope this helps mrfabulous1 :smiley::smiley:

2 Likes

I had expected it was a version discrepancy but had no idea how to address it, thank you @mrfabulous1!! Did exactly as you recommended and it worked perfectly.

Now I can finally help my friends decide if they look more like Brad Pitt or Elon Musk :wink:

(Thanks again! Wow!)

You’re Welcome.
mrfabulous1 :smiley::smiley:

1 Like

Hey guys,
My render webapp seems to be stuck on “Analyzing”.

Hi goldenflatulence hope all is well!

1. Have you tried a different browser?
2. What errors do you have in the render console?
3. On which platform did you train your model?

With the above information the problem should be easier to solve.

Cheers mrfabulous1 :smiley::smiley:

  1. I just tried a different browser, same result.
  2. I haven’t noticed any errors since I assumed that deployment meant no errors.
  3. On GCP.

Hi goldenflatulence hope you are well.

As you say you haven’t noticed any errors, it makes things a little bit more difficult to find the fault.

Please check the following.

  1. can you check the versions of libraries used on GCP and the ones used on render? See posts on using the command “!pip list” in this. thread to do this. If any are different change your library version numbers in requirements.txt file in the render app.

  2. Can you confirm that your model file (.pkl) is being accessed correctly?

  3. Can you check the network in the developer tools of the browser you may find some information when you try to analyze an image?

  4. How large is your model (.pkl) file?

  5. Does the same thing happen with very small images?

Hope these suggestions help!

Cheers mrfabulous1 :smiley::smiley:

1 Like

So, I followed you directions and also read a lot of this thread and its finally working.
Thank you so much.

Hi goldenflatulence
Well done!

mrfabulous1 :smiley::smiley:

1 Like

Hi, guys!
I have next problem: when deploy teddybears - everything is fine. As soon as I change export.pkl file and labels - get net error in log console


Any ideas how to deal with that problem?

Hi volcanoflash hope you are well!

  1. I have next problem: when deploy teddybears - everything is fine.

Do you mean you have deployed the teddy repository and it works fine on Render?

  1. As soon as I change export.pkl file and labels

Do you mean that you have trained a new model and created a export.pkl file on a different platform like your desktop or a service provider like Google Colab?
and you have put your export.pkl on google shared drive.

    • get net error in log console

You get get the error when you have done 1. and 2. and try to deploy the app.

If you have done exactly what I describe in steps 1,2 and 3 a good start would be to see posts in this thread which contain ‘pip list’ and do as they say.

Cheers mrfabulous1 :smiley::smiley:

if your answer two both tho

1 Like

Does anyone know what the URI is for torchvision 0.2.1? It’s the version I used to export my pkl on Paperspace and I can’t seem to find it on the Pytorch website. I’m having the same issues with the teddy bear classifier repo and version numbers not matching up

Hi korlandril hope all is well!

I haven’t found a specific URL for torchvision 0.2.1

However here are some things you can try,

  1. pip install torchvision==0.2.1

or you can add the following line

  1. RUN pip install torchvision==0.2.1

After the requirements line in the file called “Dockerfile” located in the repository.

  1. As there are lots of dependencies, in some cases where my model was trained months previous, I have just had to retrain it on the current versions of fastai and update all the associated libraries etc in my requirements.txt. In this case this is usally the version installed on Google Colab.

One app uses the following requirements.txt however sometimes minor changes are made in one library, which affects another library and its not always documented, so I have quite a few versions of requirements.txt.

numpy==1.16.1
torchvision==0.2.1
https://download.pytorch.org/whl/cpu/torch-1.0.1.post2-cp37-cp37m-linux_x86_64.whl
fastai==1.0.54
starlette==0.12.0
uvicorn==0.4.6
python-multipart==0.0.5
aiofiles==0.4.0
aiohttp==3.5.4

Hope this helps mrfabulous1 :smiley::smiley: `

2 Likes