-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docker image build script (#3036)
* Add docker image build script Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com> * Add README.md Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com> * Add missing .dockerignore Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com> --------- Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
- Loading branch information
Showing
8 changed files
with
159 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* | ||
!src/otx | ||
!pyproject.toml | ||
!README.md | ||
!LICENSE | ||
!MANIFEST.in | ||
!docker/download_pretrained_weights.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
FROM pytorch/pytorch:2.1.2-cuda11.8-cudnn8-runtime AS base | ||
|
||
ARG http_proxy | ||
ARG https_proxy | ||
ARG no_proxy | ||
ARG NON_ROOT_HOME=/home/non-root | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
libsm6=2:1.2.3-1 \ | ||
libxext6=2:1.3.4-0ubuntu1 \ | ||
ffmpeg=7:4.2.7-0ubuntu0.1 \ | ||
libfontconfig1=2.13.1-2ubuntu3 \ | ||
libxrender1=1:0.9.10-1 \ | ||
libgl1-mesa-glx=21.2.6-0ubuntu0.1~20.04.2 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN useradd -l -u 10001 non-root \ | ||
&& mkdir -p ${NON_ROOT_HOME} | ||
|
||
WORKDIR ${NON_ROOT_HOME} | ||
COPY . src_dir | ||
RUN chown -R non-root:non-root ${NON_ROOT_HOME} | ||
|
||
USER non-root | ||
|
||
ENV PATH=${PATH}:${NON_ROOT_HOME}/.local/bin | ||
|
||
RUN pip install --no-cache-dir src_dir/ && \ | ||
otx install --do-not-install-torch && \ | ||
rm -rf src_dir/ | ||
|
||
FROM base AS cuda | ||
|
||
|
||
FROM base AS cuda_pretrained_ready | ||
COPY docker/download_pretrained_weights.py download_pretrained_weights.py | ||
RUN python download_pretrained_weights.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# How to build cuda and cuda-pretrained-ready Docker images | ||
|
||
1. By executing the following commands, it will build two Docker images: `otx:${OTX_VERSION}-cuda` and `otx:${OTX_VERSION}-cuda-pretrained-ready`. | ||
|
||
```console | ||
git clone https://github.com/openvinotoolkit/training_extensions.git | ||
cd docker | ||
./build.sh | ||
``` | ||
|
||
2. After that, you can check whether the images are built correctly such as | ||
|
||
```console | ||
docker image ls | grep otx | ||
``` | ||
|
||
Example: | ||
|
||
```console | ||
otx 2.0.0-cuda-pretrained-ready 4f3b5f98f97c 3 minutes ago 14.5GB | ||
otx 2.0.0-cuda 8d14caccb29a 8 minutes ago 10.4GB | ||
``` | ||
|
||
`otx:${OTX_VERSION}-cuda` is a minimal Docker image where OTX is installed with CUDA supports. On the other hand, `otx:${OTX_VERSION}-cuda-pretrained-ready` includes all the model pre-trained weights that OTX provides in addition to `otx:${OTX_VERSION}-cuda`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
# shellcheck disable=SC2154 | ||
|
||
OTX_VERSION=$(python -c 'import otx; print(otx.__version__)') | ||
THIS_DIR=$(dirname "$0") | ||
|
||
echo "Build OTX ${OTX_VERSION} CUDA Docker image..." | ||
docker build \ | ||
--build-arg http_proxy="${http_proxy}" \ | ||
--build-arg https_proxy="${https_proxy}" \ | ||
--build-arg no_proxy="${no_proxy}" \ | ||
--target cuda \ | ||
-t "otx:${OTX_VERSION}-cuda" \ | ||
-f "${THIS_DIR}/Dockerfile.cuda" "${THIS_DIR}"/.. | ||
|
||
echo "Build OTX ${OTX_VERSION} CUDA pretrained-ready Docker image..." | ||
docker build \ | ||
--build-arg http_proxy="${http_proxy}" \ | ||
--build-arg https_proxy="${https_proxy}" \ | ||
--build-arg no_proxy="${no_proxy}" \ | ||
--target cuda_pretrained_ready \ | ||
-t "otx:${OTX_VERSION}-cuda-pretrained-ready" \ | ||
-f "${THIS_DIR}/Dockerfile.cuda" "${THIS_DIR}"/.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
"""Helper script to download all the model pre-trained weights.""" | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
from importlib_resources import files | ||
from omegaconf import OmegaConf | ||
from otx.core.utils.instantiators import partial_instantiate_class | ||
|
||
logging.basicConfig( | ||
level=logging.INFO, | ||
filename="download_pretrained_weights.log", | ||
filemode="w", | ||
) | ||
|
||
logger = logging.getLogger() | ||
|
||
|
||
def download_all() -> None: | ||
"""Download pre-trained weights of all models.""" | ||
recipe_dir = Path(files("otx") / "recipe") | ||
|
||
for config_path in recipe_dir.glob("**/*.yaml"): | ||
if "_base_" in str(config_path): | ||
msg = f"Skip {config_path} since it is a base config." | ||
logger.warning(msg) | ||
continue | ||
if config_path.name == "openvino_model.yaml": | ||
msg = f"Skip {config_path} since it is not a PyTorch config." | ||
logger.warning(msg) | ||
continue | ||
if "anomaly_" in str(config_path) or "otx_dino_v2" in str(config_path) or "h_label_cls" in str(config_path): | ||
msg = f"Skip {config_path} since those models show errors on instantiation." | ||
logger.warning(msg) | ||
continue | ||
|
||
config = OmegaConf.load(config_path) | ||
init_model = next(iter(partial_instantiate_class(config.model))) | ||
try: | ||
model = init_model() | ||
msg = f"Downloaded pre-trained model weight of {model!s}" | ||
logger.info(msg) | ||
except Exception: | ||
msg = f"Error on instiating {config_path}" | ||
logger.exception(msg) | ||
|
||
|
||
if __name__ == "__main__": | ||
download_all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters