From c34a39b117003398daf423e961f896df1fef8118 Mon Sep 17 00:00:00 2001 From: Anatolii-R Date: Tue, 19 Mar 2024 16:54:27 +0200 Subject: [PATCH] Fix docker issues (cpu) --- dev/docker-compose.yml | 2 +- embedding-calculator/Dockerfile | 37 +++++++++++++++++-- embedding-calculator/Dockerfile_ver2 | 2 +- embedding-calculator/src/constants.py | 4 +- .../pytorch_detector/models/retinaface.py | 2 +- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml index a90df8f38..094bb565f 100644 --- a/dev/docker-compose.yml +++ b/dev/docker-compose.yml @@ -105,7 +105,7 @@ services: - UWSGI_PROCESSES=${uwsgi_processes:-2} - UWSGI_THREADS=${uwsgi_threads:-1} - CUDA_VISIBLE_DEVICES=all ## - #runtime: nvidia + runtime: nvidia healthcheck: test: curl --fail http://localhost:3000/healthcheck || exit 1 interval: 10s diff --git a/embedding-calculator/Dockerfile b/embedding-calculator/Dockerfile index f3f7bbed1..03e1cc161 100644 --- a/embedding-calculator/Dockerfile +++ b/embedding-calculator/Dockerfile @@ -1,13 +1,37 @@ ARG BASE_IMAGE -FROM ${BASE_IMAGE:-python:3.8-slim-bullseye} +FROM ${BASE_IMAGE:-nvidia/cuda:12.3.1-base-ubuntu22.04} +#FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime + +ENV TZ=Europe/Sofia \ + DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y build-essential cmake git wget unzip \ curl yasm pkg-config libswscale-dev libtbb2 libtbb-dev libjpeg-dev \ libpng-dev libtiff-dev libavformat-dev libpq-dev libfreeimage3 python3-opencv \ libaec-dev libblosc-dev libbrotli-dev libbz2-dev libgif-dev libopenjp2-7-dev \ liblcms2-dev libcharls-dev libjxr-dev liblz4-dev libcfitsio-dev libpcre3 libpcre3-dev \ - libsnappy-dev libwebp-dev libzopfli-dev libzstd-dev \ - && rm -rf /var/lib/apt/lists/* + libsnappy-dev libwebp-dev libzopfli-dev libzstd-dev \ + && rm -rf /var/lib/apt/lists/* + + + +# Update package lists and install necessary dependencies +RUN apt-get update && \ + apt-get install -y software-properties-common && \ + add-apt-repository -y ppa:deadsnakes/ppa && \ + apt-get update && \ + apt-get install -y python3.8 python3.8-dev python3-pip python3.8-distutils + +# Set symbolic links for python and pip to use Python 3.8 by default +RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 + +# Remove existing symbolic link for pip3 if it exists +RUN rm -f /usr/bin/pip3 + +# Create symbolic link for pip3 to use pip3.8 +RUN ln -s /usr/bin/pip3.8 /usr/bin/pip3 + + # Dependencies for imagecodecs WORKDIR /tmp @@ -36,12 +60,16 @@ RUN git clone --depth=1 -b 0.5.5 https://github.com/LLNL/zfp && \ rm -rf /tmp/zfp # End imagecodecs dependencies + + # install common python packages SHELL ["/bin/bash", "-c"] WORKDIR /app/ml COPY requirements.txt . # Ensure numpy is installed first as imagecodecs doesn't declare dependencies correctly until 2022.9.26, # which is not compatible with Python 3.7 + + RUN pip --no-cache-dir install $(grep ^numpy requirements.txt) RUN pip --no-cache-dir install -r requirements.txt @@ -66,7 +94,8 @@ ENV FACE_DETECTION_PLUGIN=$FACE_DETECTION_PLUGIN CALCULATION_PLUGIN=$CALCULATION EXTRA_PLUGINS=$EXTRA_PLUGINS COPY src src COPY srcext srcext -RUN python -m src.services.facescan.plugins.setup +#RUN python -m src.services.facescan.plugins.setup +RUN python3 -m src.services.facescan.plugins.setup # copy rest of the code COPY tools tools diff --git a/embedding-calculator/Dockerfile_ver2 b/embedding-calculator/Dockerfile_ver2 index 67841756d..6de9c2388 100644 --- a/embedding-calculator/Dockerfile_ver2 +++ b/embedding-calculator/Dockerfile_ver2 @@ -1,5 +1,5 @@ ARG BASE_IMAGE -FROM ${BASE_IMAGE:-nvidia/cuda:12.1.0-cudnn8-runtime-ubi8} +FROM ${BASE_IMAGE:-nvidia/cuda:12.3.1-base-ubuntu22.04} #FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime RUN apt-get update && apt-get install -y build-essential cmake git wget unzip \ diff --git a/embedding-calculator/src/constants.py b/embedding-calculator/src/constants.py index 84a43cf71..712bec3c4 100644 --- a/embedding-calculator/src/constants.py +++ b/embedding-calculator/src/constants.py @@ -41,10 +41,10 @@ class ENV(Constants): # PyTorch settings PYTORCH_MODE = get_env_bool('PYTORCH_MODE', True) # True or False - DEVICE = get_env('DEVICE', 'cpu') # 'cpu' or 'cuda:0' + DEVICE = get_env('DEVICE', 'cuda:0') # 'cpu' or 'cuda:0' RECOGNITION_MODEL = get_env('RECOGNITION_MODEL', 'ir_50') RECOGNITION_MODEL_PATH = get_env('RECOGNITION_MODEL_PATH', 'src/services/facescan/plugins/adaface/pretrained/adaface_ir50_ms1mv2.ckpt') - DETECTOR_NAME = get_env('DETECTOR_NAME', 'mtcnn') # mtcnn or retinaface + DETECTOR_NAME = get_env('DETECTOR_NAME', 'retinaface') # mtcnn or retinaface DETECTOR_NETWORK_NAME = get_env('DETECTOR_NETWORK_NAME', 'mobile0.25') # 'mobile0.25' or 'resnet50' DETECTOR_MODEL_PATH = get_env('DETECTOR_MODEL_PATH', 'src/services/facescan/plugins/pytorch_detector/weights/mobilenet0.25_Final.pth') diff --git a/embedding-calculator/src/services/facescan/plugins/pytorch_detector/models/retinaface.py b/embedding-calculator/src/services/facescan/plugins/pytorch_detector/models/retinaface.py index adc512b2c..c0959b585 100644 --- a/embedding-calculator/src/services/facescan/plugins/pytorch_detector/models/retinaface.py +++ b/embedding-calculator/src/services/facescan/plugins/pytorch_detector/models/retinaface.py @@ -55,7 +55,7 @@ def __init__(self, cfg = None, phase = 'train'): if cfg['name'] == 'mobilenet0.25': backbone = MobileNetV1() if cfg['pretrain']: - checkpoint = torch.load("services/facescan/plugins/pytorch_detector/weights/mobilenetV1X0.25_pretrain.tar", map_location=torch.device('cpu')) + checkpoint = torch.load("src/services/facescan/plugins/pytorch_detector/weights/mobilenetV1X0.25_pretrain.tar", map_location=torch.device('cpu')) from collections import OrderedDict new_state_dict = OrderedDict() for k, v in checkpoint['state_dict'].items():