diff --git a/applications/object_detection_torch/Dockerfile b/applications/object_detection_torch/Dockerfile index 1231b1fcf6..5690c8a7e8 100644 --- a/applications/object_detection_torch/Dockerfile +++ b/applications/object_detection_torch/Dockerfile @@ -15,15 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. - -############################################################ -# Base image -############################################################ - ARG BASE_IMAGE -ARG GPU_TYPE - -FROM ${BASE_IMAGE} as base +FROM ${BASE_IMAGE} ARG DEBIAN_FRONTEND=noninteractive @@ -38,47 +31,19 @@ COPY utilities /tmp/scripts/utilities/ RUN chmod +x /tmp/scripts/holohub RUN /tmp/scripts/holohub setup && rm -rf /var/lib/apt/lists/* -FROM base as torch - -# Install libraries -ARG GPU_TYPE -RUN if [ "${GPU_TYPE}" = "igpu" ]; then \ - PYTORCH_WHEEL_VERSION="2.8.0"; \ - TORCHVISION_WHEEL_VERSION="0.23.0"; \ - INDEX_URL="https://pypi.jetson-ai-lab.io/jp6/cu129"; \ - else \ - CUDA_MAJOR=$(nvcc --version | grep -o "release [0-9]*" | awk '{print $2}'); \ - if [ "$CUDA_MAJOR" = "13" ]; then \ - # Reflect observed Torchvision nightly wheel dependencies for CUDA 13 - if [ $(uname -m) = "aarch64" ]; then \ - PYTORCH_WHEEL_VERSION="2.9.0"; \ - TORCHVISION_WHEEL_VERSION="0.24.0"; \ - INDEX_URL="https://download.pytorch.org/whl/test/cu130"; \ - else \ - PYTORCH_WHEEL_VERSION="2.9.0.dev20250829+cu130"; \ - TORCHVISION_WHEEL_VERSION="0.24.0.dev20250829"; \ - INDEX_URL="https://download.pytorch.org/whl/nightly/cu130"; \ - fi; \ - else \ - PYTORCH_WHEEL_VERSION="2.8.0+cu129"; \ - TORCHVISION_WHEEL_VERSION="0.23.0+cu129"; \ - INDEX_URL="https://download.pytorch.org/whl/"; \ - fi; \ - fi; \ - echo "Installing torch==${PYTORCH_WHEEL_VERSION} from $INDEX_URL"; \ - python3 -m pip install --force-reinstall torch==${PYTORCH_WHEEL_VERSION} torchvision==${TORCHVISION_WHEEL_VERSION} torchaudio --index-url $INDEX_URL; \ - if ! find /usr/local/lib/python3.12/dist-packages/torch -name libtorch_cuda.so | grep -q .; then \ - echo "libtorch_cuda.so not found, torch installation failed"; \ - exit 1; \ - fi - -RUN rm -rf /opt/libtorch/* && \ - mkdir -p /opt/libtorch && \ - LIBTORCH_PATH=$(python3 -c "import torch; print(torch.__path__[0])") && \ - ln -sf "${LIBTORCH_PATH}/lib" /opt/libtorch/lib - - # Set up Holoscan SDK container libtorch to be found with ldconfig for app C++ build and runtime RUN echo $(python3 -c "import torch; print(torch.__path__[0])")/lib > /etc/ld.so.conf.d/libtorch.conf \ && ldconfig \ && ldconfig -p | grep -q "libtorch.so" + +ARG GPU_TYPE +ARG CUDA_MAJOR +RUN INDEX_URL=""; \ + if [ "${GPU_TYPE}" = "igpu" ]; then \ + INDEX_URL="https://pypi.jetson-ai-lab.io/jp6/cu126"; \ + elif [ "${CUDA_MAJOR}" = "12" ]; then \ + INDEX_URL="https://download.pytorch.org/whl/cu129"; \ + elif [ "${CUDA_MAJOR}" = "13" ]; then \ + INDEX_URL="https://download.pytorch.org/whl/cu130"; \ + fi \ + && python3 -m pip install torchvision --no-cache-dir --index-url ${INDEX_URL}