How to get Predictions of Multiple images from deployed webapp?

I successfully deployed my Image Classifier as a web-app on Render.
Right now ,I can only upload one image and get a prediction for that.
My project requires me to send a folder of multiple images (~100) to the web-app and get back the predictions.

How should I modify the POST request so that I can send multiple images for prediction at once ?
Should I expose my model as a REST-API instead of a web-app to make things simpler?

Here’s an example for downloading images from a user uploaded CSV document and then creates the request via a folder. You care about the second half :slight_smile:

import csv
import StringIO

@app.route('/analyze', methods=['POST'])
async def analyze(request):
    data = await request.form()
    content = await (data['file'].read())
    s = str(content, 'utf-8')
    data = StringIO(s)
    !mkdir('Downloaded_Images')
    download_images(data, 'Downloaded_Images')
    path2 = Path('Downloaded_Images')
    data = ImageList.from_folder(path)
    learn = load_learner(path, export_file_name, test=data)
    y, _ = learn.get_preds(DatasetType.Test)
    y = torch.argmax(y, dim=1)
    preds = [learn.data.classes[int(x)] for x in y]
    rm -r 'Downloaded_Images'
    resultsFile = open('results.csv', 'wb')
    wr = csv.writer(resultsFile)
    wr.writerows([preds])
    return FileResponse('results.csv')
2 Likes

Would you mind sharing the steps of how you did this? I have no idea about the process.
So far, I have opened an account on Render. What do I do next?

Hi dmitry2020 Hope all is well and you are having a splendid day.

Below are 2 links that will be very helpful in deploying your app on render.com

https://course.fast.ai/deployment_render.html

The first link is the process to deploy on render.com
the second link is the thread for resolving issues when deploying.

Particularly look at posts with pip list This is essential in deploying your model successfully.

You can use the code in a previous post in this thread, to do inference on multiple files.

Hope this helps.

Cheers mrfabulous1 :smiley: :smiley: