From 52d99864255d1479828043317cb94798bd62733a Mon Sep 17 00:00:00 2001 From: Jack Chou Date: Thu, 8 Jun 2023 12:39:19 +0800 Subject: [PATCH 1/5] updated eng dockerfile --- docker/Dockerfile | 17 ++++++++--------- docker/docker-compose.yml | 9 +++------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 75db0bd..3a6e205 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,21 +2,25 @@ FROM continuumio/anaconda3 RUN git clone https://github.com/OpenGVLab/InternGPT.git WORKDIR InternGPT + SHELL ["/bin/bash", "-c"] RUN conda init bash RUN source "/opt/conda/bin/activate" RUN conda create -n igpt python=3.8 RUN source activate igpt -RUN apt-get clean && apt-get update && apt-get -y install --no-install-recommends gcc g++ libjpeg-dev libpng-dev zlib1g-dev build-essential +RUN apt-get clean && apt-get update && apt-get -y install --no-install-recommends gcc g++ libjpeg-dev libpng-dev zlib1g-dev build-essential libgl1-mesa-glx libxml2 RUN cp /opt/conda/envs/igpt/lib/libstdc++.so.6 /usr/lib/x86_64-linux-gnu -RUN conda install pytorch pytorch-cuda=11.7 cudatoolkit -c pytorch -c nvidia + +RUN conda update -n base -c defaults conda +RUN conda install pytorch pytorch-cuda=11.7 cudatoolkit=11.7 -c pytorch -c nvidia +RUN conda install -c conda-forge cudatoolkit-dev=11.7 +RUN conda install -c numba llvmlite numba RUN pip install -r requirements.txt RUN pip install git+https://github.com/facebookresearch/detectron2.git RUN pip install mediapipe -RUN pip install imageio-ffmpeg RUN pip uninstall -y opencv-python RUN pip uninstall -y opencv-python-headless @@ -25,12 +29,7 @@ RUN pip uninstall -y opencv-contrib-python-headless RUN pip install opencv-python-headless==4.6.0.66 RUN pip install opencv-contrib-python==4.6.0.66 -RUN apt-get -y install libgl1-mesa-glx -RUN apt-get -y install libxml2 - -RUN conda install -c conda-forge cudatoolkit-dev -RUN conda install --channel=numba llvmlite -RUN conda install -c numba numba +RUN git pull EXPOSE 7862 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 42b0280..e75ac3c 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,14 +1,13 @@ services: igpt: - build: . image: "igpt" container_name: "igpt" restart: "unless-stopped" ports: - "7862:7862" volumes: - - /path/to/model_zoo:/InternGPT/model_zoo - - /path/to/certificate:/InternGPT/certificate + - /data/InternGPT/model_zoo:/InternGPT/model_zoo + - /data/InternGPT/certificate:/InternGPT/certificate entrypoint: "python" deploy: resources: @@ -21,7 +20,5 @@ services: - "-u" - "app.py" - "--load" - - "StyleGAN_cuda:0" - - "--tab" - - "DragGAN" + - "ImageOCRRecognition_cuda:0,Text2Image_cuda:0,SegmentAnything_cuda:0,ActionRecognition_cuda:0,VideoCaption_cuda:0,DenseCaption_cuda:0,ReplaceMaskedAnything_cuda:0,LDMInpainting_cuda:0,SegText2Image_cuda:0,ScribbleText2Image_cuda:0,Image2Scribble_cuda:0,Image2Canny_cuda:0,CannyText2Image_cuda:0,StyleGAN_cuda:0,Anything2Image_cuda:0,HuskyVQA_cuda:0" - "--https" From 8db05b968f831f4ce060947d145792732ef75798 Mon Sep 17 00:00:00 2001 From: Jack Chou Date: Thu, 8 Jun 2023 14:42:29 +0800 Subject: [PATCH 2/5] fixed docker compose to prevent redownload on startup --- INSTALL.md | 12 ++++++++++++ docker/Dockerfile | 2 ++ docker/docker-compose.yml | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 63bbad9..f7dd30d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -54,3 +54,15 @@ docker compose up docker compose run -i --entrypoint /bin/bash igpt ``` + +## A note on dependencies: + +CUDA, torch, and opencv are notorious for version incompatibilities (mostly due to binaries being built against specific versions), so here's a quick checklist: + +1. `opencv` libraries should always have specified version numbers, and there should only ever be one set on the system + +2. `cuda` libraries should always have specified version numbers, but can exist independently using conda + +3. `torch` libraries should always have specified version numbers, especially for torchvision [here](https://pypi.org/project/torchvision/) and torchaudio [here](https://pytorch.org/audio/main/installation.html); always check `pytorch` and `python` versions before building + +If deploying as Swarm or via Kubernetes, note that the build directory should have access to tty, and individual clients should be paired with individual gpus or gpu partitions. See [here](https://docs.nvidia.com/datacenter/tesla/mig-user-guide/index.html). diff --git a/docker/Dockerfile b/docker/Dockerfile index 3a6e205..e00e59d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -29,6 +29,8 @@ RUN pip uninstall -y opencv-contrib-python-headless RUN pip install opencv-python-headless==4.6.0.66 RUN pip install opencv-contrib-python==4.6.0.66 +RUN conda install torchvision=0.14.0 torchaudio=0.13.0 -c pytorch + RUN git pull EXPOSE 7862 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index e75ac3c..4e89a1b 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -8,6 +8,8 @@ services: volumes: - /data/InternGPT/model_zoo:/InternGPT/model_zoo - /data/InternGPT/certificate:/InternGPT/certificate + - /data/InternGPT/checkpoints:/InternGPT/checkpoints + - /data/InternGPT/.EasyOCR:/InternGPT/.EasyOCR/model entrypoint: "python" deploy: resources: @@ -20,5 +22,5 @@ services: - "-u" - "app.py" - "--load" - - "ImageOCRRecognition_cuda:0,Text2Image_cuda:0,SegmentAnything_cuda:0,ActionRecognition_cuda:0,VideoCaption_cuda:0,DenseCaption_cuda:0,ReplaceMaskedAnything_cuda:0,LDMInpainting_cuda:0,SegText2Image_cuda:0,ScribbleText2Image_cuda:0,Image2Scribble_cuda:0,Image2Canny_cuda:0,CannyText2Image_cuda:0,StyleGAN_cuda:0,Anything2Image_cuda:0,HuskyVQA_cuda:0" + - "HuskyVQA_cuda:0,SegmentAnything_cuda:0,ImageOCRRecognition_cuda:0,Anything2Image_cuda:0,ReplaceMaskedAnything_cuda:0" - "--https" From 18f07e72adf52c8c64d127cad60961539862c28a Mon Sep 17 00:00:00 2001 From: Jack Chou Date: Thu, 8 Jun 2023 14:48:05 +0800 Subject: [PATCH 3/5] fix easyocr volume dep --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 4e89a1b..7030727 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -9,7 +9,7 @@ services: - /data/InternGPT/model_zoo:/InternGPT/model_zoo - /data/InternGPT/certificate:/InternGPT/certificate - /data/InternGPT/checkpoints:/InternGPT/checkpoints - - /data/InternGPT/.EasyOCR:/InternGPT/.EasyOCR/model + - /data/InternGPT/.EasyOCR:/root/.EasyOCR/model entrypoint: "python" deploy: resources: From a26861c8b3988f0b7e352a5093101542be839cef Mon Sep 17 00:00:00 2001 From: Jack Chou Date: Thu, 8 Jun 2023 14:54:15 +0800 Subject: [PATCH 4/5] fix for imagebind volumes --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 7030727..8a12eed 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -8,7 +8,7 @@ services: volumes: - /data/InternGPT/model_zoo:/InternGPT/model_zoo - /data/InternGPT/certificate:/InternGPT/certificate - - /data/InternGPT/checkpoints:/InternGPT/checkpoints + - /data/InternGPT/checkpoints:/InternGPT/.checkpoints - /data/InternGPT/.EasyOCR:/root/.EasyOCR/model entrypoint: "python" deploy: From 6387e945046fe39106b35b829941802d9fcd3cc4 Mon Sep 17 00:00:00 2001 From: Jack Chou Date: Thu, 8 Jun 2023 19:37:42 +0800 Subject: [PATCH 5/5] mask func is not well formed --- docker/docker-compose.yml | 7 ++++--- iGPT/models/image.py | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 8a12eed..7fecf13 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -8,19 +8,20 @@ services: volumes: - /data/InternGPT/model_zoo:/InternGPT/model_zoo - /data/InternGPT/certificate:/InternGPT/certificate - - /data/InternGPT/checkpoints:/InternGPT/.checkpoints + - /data/InternGPT/checkpoints:/InternGPT/checkpoints - /data/InternGPT/.EasyOCR:/root/.EasyOCR/model + - /data/stable-diffusion-webui-docker/data/image_output:/InternGPT/image entrypoint: "python" deploy: resources: reservations: devices: - driver: nvidia - count: 1 + count: all capabilities: [gpu] command: - "-u" - "app.py" - "--load" - - "HuskyVQA_cuda:0,SegmentAnything_cuda:0,ImageOCRRecognition_cuda:0,Anything2Image_cuda:0,ReplaceMaskedAnything_cuda:0" + - "HuskyVQA_cuda:0,SegmentAnything_cuda:0,Anything2Image_cuda:0" - "--https" diff --git a/iGPT/models/image.py b/iGPT/models/image.py index 66334b7..83fa5c5 100644 --- a/iGPT/models/image.py +++ b/iGPT/models/image.py @@ -670,7 +670,7 @@ def inference_by_mask(self, inputs): mask_img.save(filaname, "PNG") return filaname - def segment_by_mask(self, mask, features): + def segment_by_mask(self, mask, features=None): random.seed(GLOBAL_SEED) idxs = np.nonzero(mask) num_points = min(max(1, int(len(idxs[0]) * 0.01)), 16) @@ -681,12 +681,19 @@ def segment_by_mask(self, mask, features): points = np.array(new_mask).reshape(2, -1).transpose(1, 0)[:, ::-1] labels = np.array([1] * num_points) - res_masks, scores, _ = self.predictor.predict( - features=features, - point_coords=points, - point_labels=labels, - multimask_output=True, - ) + if features is None: + res_masks, scores, _ = self.predictor.predict( + point_coords=points, + point_labels=labels, + multimask_output=True, + ) + else: + res_masks, scores, _ = self.predictor.predict( + features=features, + point_coords=points, + point_labels=labels, + multimask_output=True, + ) return res_masks[np.argmax(scores), :, :]