From d6d7b921aaedc26fa15d917834260fb50e6a3bb1 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 2 Feb 2025 15:38:57 +0400 Subject: [PATCH] Fix Dockerfile to ensure proper build --- Dockerfile | 56 +++++++++++++++++++++++++++++++----------------------- README.md | 9 +++++++++ 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index cbdd5e8..b954cab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,43 @@ -FROM pytorch/pytorch:2.1.2-cuda12.1-cudnn8-runtime -ARG DEBIAN_FRONTEND=noninteractive +FROM nvidia/cuda:11.3.1-devel-ubuntu20.04 -ENV CUDA_HOME=/usr/local/cuda \ - TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0 7.5 8.0 8.6+PTX" \ - SETUPTOOLS_USE_DISTUTILS=stdlib +ENV CUDA_HOME=/usr/local/cuda-11.3/ -RUN conda update conda -y +# Avoid interactive prompts during build +ENV DEBIAN_FRONTEND=noninteractive -# Install libraries in the brand new image. -RUN apt-get -y update && apt-get install -y --no-install-recommends \ - wget \ - build-essential \ - git \ - python3-opencv \ - ca-certificates && \ - rm -rf /var/lib/apt/lists/* +# System dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + git \ + wget \ + python3.8 \ + python3-pip \ + python3-venv \ + python3-opencv \ + && rm -rf /var/lib/apt/lists/* -# Set the working directory for all the subsequent Dockerfile instructions. -WORKDIR /opt/program +WORKDIR /app +# Clone GroundingDINO repo RUN git clone https://github.com/IDEA-Research/GroundingDINO.git -RUN mkdir weights ; cd weights ; wget -q https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth ; cd .. +# Install Python dependencies +RUN pip install --upgrade pip && \ + pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113 && \ + pip install networkx==2.6.3 -RUN conda install -c "nvidia/label/cuda-12.1.1" cuda -y -ENV CUDA_HOME=$CONDA_PREFIX +# Install GroundingDINO requirements +RUN cd GroundingDINO && \ + pip install -r requirements.txt && \ + pip install -e . -ENV PATH=/usr/local/cuda/bin:$PATH +# Download pre-trained weights +RUN mkdir -p /app/weights && \ + wget -P /app/weights https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth -RUN cd GroundingDINO/ && python -m pip install . +# Environment variables +ENV PYTHONPATH=/app/GroundingDINO +ENV CUDA_VISIBLE_DEVICES=0 -COPY docker_test.py docker_test.py - -CMD [ "python", "docker_test.py" ] \ No newline at end of file +# Use JSON array format for CMD +CMD ["bash", "-c", "cd GroundingDINO && python3 demo/gradio_app.py"] diff --git a/README.md b/README.md index 84e3191..21b061e 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,15 @@ cv2.imwrite("annotated_image.jpg", annotated_frame) We also provide a demo code to integrate Grounding DINO with Gradio Web UI. See the file `demo/gradio_app.py` for more details. +**Running Web UI with Docker** + +To run the web UI using Docker, first build and run the container: + +```bash +docker build -t grounding_dino . +docker run --gpus all --network host -it grounding_dino +``` + **Notebooks** - We release [demos](demo/image_editing_with_groundingdino_gligen.ipynb) to combine [Grounding DINO](https://arxiv.org/abs/2303.05499) with [GLIGEN](https://github.com/gligen/GLIGEN) for more controllable image editings.