I am building a docker image which I want to store on ECR(AWS) . My expections with the yolomodel is to just take an image as an input and get predicted set of pose-keypoints as output using YOLOv7-pose.
Following are in requirements.txt in docker :
boto3==1.20.23
boto3-stubs == 1.21.0
aws_lambda_typing==2.9.2
requests==2.25.1
protobuf==4.25.3
pytz == 2023.3
torch == 2.0.1
opencv-python == 4.9.0.80
dateTime == 5.4
pybase64 ==1.3.2
ultralytics ==8.1.0
typing-extensions == 3.7.4.3
and this is how I am importing it in application.py:
import cv2
import numpy as np
import boto3
import base64
import json
import torch
import math
import pytz
from ultralytics import YOLO
from datetime import datetime
Earlier I used mediapipe to do same which led me to docker size of only 500MB.
The image is being inflated by the Python packages:
DockerfileThe size of the image is 7.7 GB and the
/usr/local/lib/python3.8/site-packagesdirectory alone is 4.8 GB.I'm checking the image size with:
Using
--no-cache-dirwill reduce the size of the image.DockerfileThe size of the image is now 5.3 GB.
However, when I tried to load the packages using the code from the original question I had a problem with a missing dependency.
So I went back to first principles and simplified
requirements.txt:With those dependencies the image builds and packages load.
Since we are not specifying particular versions for all of the other packages, they are simply selected to be compatible with
boto3andultralytics, which seems to result in consistently larger footprints. For example, we get version 2.2.1 oftorch.You can probably fiddle around with specific versions of those packages but it seems unlikely that you will get the image down to 500 MB.
Sorry, I know that this is not really an "answer". But maybe there is something useful.