how to integrate torch into a docker image while keeping image size reasonable?

Viewed 59

So I've a Flask web app that will be exposing some deep learning models.

I built the image and everything works fine.

the problem is the size of this image is 5.58GB! which is a bit ridiculous.

I have some deep learning models that are copied during the build, I thought they might be the culprit but their size combined does not exceed 300MB so that's definately not it.

upon checking the history and the size of each layer I discovered this:

  • RUN /bin/sh -c pip install -r requirements.txt is taking up 771MB.
  • RUN /bin/sh -c pip install torch==1.10.2 is taking up 2.8GB!
  • RUN /bin/sh -c apt-get install ffmpeg libsm6 libxext6 is taking up 400MB.

so how do I incorporate these libraries while keeping image size reasonable? is it ok to have images of these size when deploying ml models in python?

below is the root directory:

enter image description here

Dockerfile:

FROM python:3.7.13
WORKDIR /app 
COPY ["rdm.pt", "autosort_model.pt", "rotated_model.pt", "yolov5x6.pt", "/app/"]
RUN pip install torch==1.10.2
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
RUN apt-get update
RUN apt-get install ffmpeg libsm6 libxext6  -y
COPY . /app
CMD python ./app.py

.dockerignore:

Dockerfile
README.md
__pycache__
0 Answers
Related