From 63a782264ae367c8246af23eb85b4b8ac4b9be2d Mon Sep 17 00:00:00 2001 From: frakw Date: Thu, 14 Nov 2024 11:28:05 +0800 Subject: [PATCH 1/4] add docker support --- docker/Dockerfile | 23 +++++++++++++++++++++++ docker/README.md | 27 +++++++++++++++++++++++++++ docker/docker-compose.yaml | 24 ++++++++++++++++++++++++ docker/requirements.txt | 16 ++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100644 docker/docker-compose.yaml create mode 100644 docker/requirements.txt diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000000..61cabf70ea --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,23 @@ +FROM tensorflow/tensorflow:1.14.0-gpu-py3 + +COPY ./requirements.txt /root + +RUN pip install --upgrade pip setuptools wheel + +RUN cd /root \ + && pip install -r mm_requirements.txt --verbose \ + && pip install --no-deps imgaug==0.4.0 + +RUN rm /etc/apt/sources.list.d/cuda.list \ + && apt-get update \ + && apt-get install vim git ffmpeg libsm6 libxext6 -y + +RUN cd /root \ + && git clone https://github.com/ywflow/BubMask.git + +RUN cd /root/BubMask \ + && python setup.py install \ + && cd .. \ + && rm -r BubMask + +WORKDIR /root/BubMask \ No newline at end of file diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000000..8d38590609 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,27 @@ +# BubMask Docker + +## Deploy container + +```bash +docker compose up -d +``` + +## Enter container and test sample image + +Make sure you have download mask_rcnn_bubble.h5 and place inside `BubMask/weights` + +```bash +docker start bubmask-container +docker exec -it bubmask-container /bin/bash +python ./bubble/bubble.py splash --weights=./weights/mask_rcnn_bubble.h5 --image=./sample_image/Expansion_pipe.jpg --results=./splash_results --confidence=0.01 +``` + +## Build image + +```bash +docker build -t frakw/bubmask:latest . +``` + +You can also use pre-build image here: + +[https://hub.docker.com/repository/docker/frakw/bubmask/tags](https://hub.docker.com/repository/docker/frakw/bubmask/tags) diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 0000000000..dd1ec69a8a --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,24 @@ +services: + bubmask: + stdin_open: true + tty: true + devices: + - /dev/dri + volumes: + - ..:/root/BubMask + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all + capabilities: + - gpu + environment: + - QT_X11_NO_MITSHM=1 + - NVIDIA_VISIBLE_DEVICES=all + - NVIDIA_DRIVER_CAPABILITIES=all + container_name: bubmask-container + build: . + image: frakw/bubmask:latest + command: /bin/bash diff --git a/docker/requirements.txt b/docker/requirements.txt new file mode 100644 index 0000000000..136ffd335a --- /dev/null +++ b/docker/requirements.txt @@ -0,0 +1,16 @@ +opencv-python-headless==4.6.0.66 +opencv-contrib-python-headless==4.6.0.66 +numpy==1.19.5 +scipy==1.5.4 +Pillow==8.4.0 +Cython==3.0.11 +matplotlib==3.3.4 +scikit-image==0.17.2 +Keras==2.0.8 +h5py==2.10.0 +#imgaug==0.4.0 +ipykernel==5.5.6 +ipyparallel==8.2.1 +ipython==7.16.3 +ipython-genutils==0.2.0 +ipywidgets==7.8.5 \ No newline at end of file From 1cf65b940febe767cbf32c432642a554778ea082 Mon Sep 17 00:00:00 2001 From: frakw Date: Thu, 14 Nov 2024 11:34:40 +0800 Subject: [PATCH 2/4] fix GPU memory exceeds issue --- bubble/bubble.py | 3 ++- bubble/solve_cudnn_error.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 bubble/solve_cudnn_error.py diff --git a/bubble/bubble.py b/bubble/bubble.py index c3e28743d0..bbb7c8473d 100644 --- a/bubble/bubble.py +++ b/bubble/bubble.py @@ -46,6 +46,7 @@ from mrcnn import visualize import tensorflow as tf import datetime +from solve_cudnn_error import * # Root directory of the project ROOT_DIR = os.path.abspath("../") @@ -509,7 +510,7 @@ def splash(model, image_path=None, video_path=None, result_path=RESULTS_DIR): if __name__ == '__main__': import argparse - + solve_cudnn_error() # Parse command line arguments parser = argparse.ArgumentParser( description='Train Mask R-CNN to detect bubbles.') diff --git a/bubble/solve_cudnn_error.py b/bubble/solve_cudnn_error.py new file mode 100644 index 0000000000..708fb2e7ba --- /dev/null +++ b/bubble/solve_cudnn_error.py @@ -0,0 +1,14 @@ +import tensorflow as tf +def solve_cudnn_error(): + gpus = tf.config.experimental.list_physical_devices('GPU') + if gpus: + try: + # Currently, memory growth needs to be the same across GPUs + for gpu in gpus: + tf.config.experimental.set_memory_growth(gpu, True) + logical_gpus = tf.config.experimental.list_logical_devices('GPU') + print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs") + except RuntimeError as e: + # Memory growth must be set before GPUs have been initialized + print(e) + From b0bad273a6cef72680d928145b7cd311233b7f6e Mon Sep 17 00:00:00 2001 From: frakw Date: Thu, 14 Nov 2024 11:35:15 +0800 Subject: [PATCH 3/4] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 12da7dd781..2789abfc1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +splash_results/ # Data files and directories common in repo root datasets/ logs/ From 174ae2c0d8e6efdfb2d788a10cf902961b185c62 Mon Sep 17 00:00:00 2001 From: Sheng-Hao Liao Date: Thu, 12 Dec 2024 22:37:22 +0800 Subject: [PATCH 4/4] Update Dockerfile --- docker/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 61cabf70ea..de42aa5043 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -5,7 +5,7 @@ COPY ./requirements.txt /root RUN pip install --upgrade pip setuptools wheel RUN cd /root \ - && pip install -r mm_requirements.txt --verbose \ + && pip install -r requirements.txt --verbose \ && pip install --no-deps imgaug==0.4.0 RUN rm /etc/apt/sources.list.d/cuda.list \ @@ -20,4 +20,4 @@ RUN cd /root/BubMask \ && cd .. \ && rm -r BubMask -WORKDIR /root/BubMask \ No newline at end of file +WORKDIR /root/BubMask