Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile fix + volume dep + update INSTALL.md #35

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
17 changes: 9 additions & 8 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,12 +29,9 @@ 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 torchvision=0.14.0 torchaudio=0.13.0 -c pytorch

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

Expand Down
14 changes: 7 additions & 7 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
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
- /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"
- "StyleGAN_cuda:0"
- "--tab"
- "DragGAN"
- "HuskyVQA_cuda:0,SegmentAnything_cuda:0,Anything2Image_cuda:0"
- "--https"
21 changes: 14 additions & 7 deletions iGPT/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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), :, :]

Expand Down