skip to Main Content

I have a Django container and I want to consume another DL container inside it? For example, I have a Django app that predicting images classes and I want to make the prediction using a docker container and not a python library. That Django app will be containerised as well. In production, I will have three docker containers: Django container + Postgres container + YoloV5 container. How can I link the Django with the YoloV5 so that the prediction inside the Django will be done using the YoloV5?

I want to connect a deep learning container with Django container to make prediction using the DL container and not a python package.

2

Answers


  1. Chosen as BEST ANSWER

    As suggested by Nick and others, the solution is: by calling the YoloV5 docker container inside Django container using host.docker.internal. I mean that inside Django container (views.py) I used host.docker.internal to call the YoloV5 container. Update on 29th March 2023: Instead of using the host.docker.internal. As suggested by Nick we can use Requests: An example, say you have two containers A and B "Make sure that both of them are connected together". Container A has a function to add two numbers and I want to use this function in Container B. Then Inside Container B:

    import requests
    data = {
        'x': 5,
        'y': 3
    }
    response = requests.post('http://containerA:8000/add', json=data)
    result = response.json()
    print(result) # outputs {'result': 8}
    

    Note that ContainerA is running on port 8000.


  2. The easiest way to do this is to make a network call to the other container. You may find it simplest to wrap the YoloV5 code in a very thin web layer, e.g. using Flask, to create an API. Then call that in your Django container when you need it using requests.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search