javascriptpythondjangoconv-neural-networkefficientnet

How to use a CNN code in python inside a website?


I have website with backend in Python (Django) and JavaScript hosted on heroku. Also, I have code in python that does image classification with EfficientNet, so I want to integrate this code into my website.

The logical sequence of ideas is as follows:

  1. The user upload an image on the site;

  2. This image will be classified with the Python code;

  3. The algorithm will return an image;

  4. The returned image should be posted on the site.

Does anyone know what would be the best way to do this?


Solution

  • First of all, yes, if it is possible to implement what you are mentioning, I would implement the following:

    Use celery to implement asynchronous tasks where when the photo is uploaded, Django tells celery that it has to do the asynchronous task (in this case, use the CNN) and can leave a pending status for the photo and once the task is complete, it changes the status and would appear published on the platform.

    I recommend using asynchronous tasks for this because of the following:

    The use of the convolutional neural network can take a certain time, let us remember that the default maximum response time of an HTTP request is 30 seconds and it could cut the request, the user would see it as an error and he can also complain because uploading a photo must wait a while and for user purposes they would think that the site is slow. The implementation of asynchronous tasks allows first in the HTTP request to indicate to the user that the image is being analyzed and secondly you do not have a limit of 30 seconds to analyze, in case of having many image uploads at the same time it can crash the server. That is why with celery you can even implement queues to solve this (Using redis or rabbitMQ).

    If you want to implement knowing the status of the image in real time, you could add the use of a websocket, where when uploading the image in the response you get a URL that is the one of the websocket where you would receive information about the image once processed. You can use django-channels for it