From 3bd67b8f6b1b62eb176939b741e6b427c561adda Mon Sep 17 00:00:00 2001 From: a7ypical Date: Sun, 27 Feb 2022 20:18:03 +0200 Subject: [PATCH 1/2] Changes to run on Jetson Xavier NX. --- deploy_trt.sh | 4 +-- src/Dockerfile_trt | 36 ++++++++++++++------ src/api_trt/entrypoint.sh | 4 +-- src/api_trt/modules/utils/download_google.py | 6 +++- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/deploy_trt.sh b/deploy_trt.sh index dfa5ef9..eba2dfe 100755 --- a/deploy_trt.sh +++ b/deploy_trt.sh @@ -31,7 +31,7 @@ max_size=640,640 # Force FP16 mode for building TensorRT engines, even if it's not supported. # Please check that your GPU supports FP16, otherwise performance may drop. # For GPUs supporting it gives about 2x performance boost. -force_fp16=False +force_fp16=True # DET MODELS: @@ -100,7 +100,7 @@ for i in $(seq 0 $(($n_gpu - 1)) ); do docker rm $name; echo --- Starting container $name with $device at port $port; ((p++)); - docker run -p $port:18080\ + docker run --runtime=nvidia -p $port:18080\ --gpus $device\ -d\ -e LOG_LEVEL=$log_level\ diff --git a/src/Dockerfile_trt b/src/Dockerfile_trt index a7ae1f4..474316f 100755 --- a/src/Dockerfile_trt +++ b/src/Dockerfile_trt @@ -1,17 +1,33 @@ -FROM nvcr.io/nvidia/tensorrt:21.12-py3 +FROM nvcr.io/nvidia/l4t-ml:r32.6.1-py3 -ENV LC_ALL=C.UTF-8 -ENV LANG=C.UTF-8 +ENV LC_ALL=en_US.UTF-8 +ENV LANG=en_US.UTF-8 -RUN apt-get update && apt-get install -y libgl1-mesa-glx protobuf-compiler libprotoc-dev libb64-0d libturbojpeg -ENV PIP_INSTALL="python -m pip --no-cache-dir install --upgrade" -RUN $PIP_INSTALL requests tqdm opencv-python scikit-image fastapi uvicorn ujson numba aiofiles python-multipart httpx cupy-cuda114 icc_rt -RUN $PIP_INSTALL onnx==1.8.0 +RUN apt-get update +RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata --upgrade +RUN apt-get install -y libgl1-mesa-glx protobuf-compiler libprotoc-dev libb64-0d libturbojpeg python3-pip +ENV PIP_INSTALL="python3 -m pip --no-cache-dir install --upgrade" +RUN $PIP_INSTALL pip +RUN $PIP_INSTALL requests tqdm +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y locales + +RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ + dpkg-reconfigure --frontend=noninteractive locales && \ + update-locale LANG=en_US.UTF-8 + +RUN $PIP_INSTALL scikit-image + +RUN $PIP_INSTALL fastapi uvicorn ujson aiofiles python-multipart httpx +RUN apt-get install -y cmake git +RUN git clone --recursive https://github.com/onnx/optimizer onnxoptimizer && cd onnxoptimizer && pip3 install -e . && cd ~ && rm -rf onnxoptimizer RUN $PIP_INSTALL onnx-simplifier -RUN $PIP_INSTALL nvidia-pyindex && pip install tritonclient[http,grpc] +RUN $PIP_INSTALL nvidia-pyindex +RUN $PIP_INSTALL tritonclient[http,grpc] RUN $PIP_INSTALL git+git://github.com/lilohuang/PyTurboJPEG.git msgpack -RUN $PIP_INSTALL pynvjpeg - +COPY Tegra_Multimedia_API_R32.2.1_aarch64.tbz2 /tmp +RUN tar xvjf /tmp/Tegra_Multimedia_API_R32.2.1_aarch64.tbz2 && rm /tmp/Tegra_Multimedia_API_R32.2.1_aarch64.tbz2 +RUN mv tegra_multimedia_api /usr/src/jetson_multimedia_api +#RUN $PIP_INSTALL pynvjpeg WORKDIR /app COPY api_trt /app diff --git a/src/api_trt/entrypoint.sh b/src/api_trt/entrypoint.sh index ec192e9..57a8db8 100644 --- a/src/api_trt/entrypoint.sh +++ b/src/api_trt/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash echo Preparing models... -python prepare_models.py +python3 prepare_models.py echo Starting InsightFace-REST using $NUM_WORKERS workers. -uvicorn app:app --port 18080 --host 0.0.0.0 --workers $NUM_WORKERS --timeout-keep-alive 20000 \ No newline at end of file +uvicorn app:app --port 18080 --host 0.0.0.0 --workers $NUM_WORKERS --timeout-keep-alive 20000 diff --git a/src/api_trt/modules/utils/download_google.py b/src/api_trt/modules/utils/download_google.py index e0f7ad5..77dc88f 100644 --- a/src/api_trt/modules/utils/download_google.py +++ b/src/api_trt/modules/utils/download_google.py @@ -1,7 +1,7 @@ import requests import hashlib from tqdm import tqdm - +import re def check_hash(filename, hash, algo='md5'): @@ -48,6 +48,10 @@ def get_confirm_token(response): if key.startswith('download_warning'): return value + m = re.search('.*confirm=([^\"]*)', response.text, re.M) + if m and m.groups(): + return m.groups()[0] + return None def save_response_content(response, destination): From 8436a9308ba335102ae059f57a4fc83c5e7098b5 Mon Sep 17 00:00:00 2001 From: a7ypical Date: Thu, 3 Mar 2022 17:50:16 +0200 Subject: [PATCH 2/2] Check the response content type before test scan --- src/api_trt/modules/utils/download_google.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/api_trt/modules/utils/download_google.py b/src/api_trt/modules/utils/download_google.py index 77dc88f..8a3c5a9 100644 --- a/src/api_trt/modules/utils/download_google.py +++ b/src/api_trt/modules/utils/download_google.py @@ -48,9 +48,10 @@ def get_confirm_token(response): if key.startswith('download_warning'): return value - m = re.search('.*confirm=([^\"]*)', response.text, re.M) - if m and m.groups(): - return m.groups()[0] + if 'text/html' in response.headers['Content-Type']: + m = re.search('.*confirm=([^\"]*)', response.text, re.M) + if m and m.groups(): + return m.groups()[0] return None