atwang commited on
Commit
3c7feee
β€’
1 Parent(s): 6d737eb

get docker build working, update documentation in README

Browse files
Files changed (7) hide show
  1. .dockerignore +4 -0
  2. .gitignore +1 -0
  3. Dockerfile +61 -0
  4. README.md +42 -10
  5. app.py +2 -1
  6. pre-requirements.txt +0 -6
  7. requirements.txt +6 -2
.dockerignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .git
2
+ venv/
3
+ __pycache__/
4
+ .output/
.gitignore CHANGED
@@ -4,3 +4,4 @@ dist/
4
  venv/
5
  __pycache__/
6
  .output/
 
 
4
  venv/
5
  __pycache__/
6
  .output/
7
+ .data/
Dockerfile ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.7.1-devel-ubuntu22.04
2
+ # FROM python:3.10.13-bookworm
3
+
4
+ ENV LC_ALL C.UTF-8
5
+ ENV LANG C.UTF-8
6
+ ARG UID=1000
7
+ ARG UNAME=ubuntu
8
+ ARG DEBIAN_FRONTEND=noninteractive
9
+ ENV PATH="/home/$UNAME/.local/bin:$PATH"
10
+
11
+ # setup user
12
+ RUN useradd -m -u $UID $UNAME
13
+ WORKDIR /home/$UNAME
14
+ RUN chown -R $UNAME:$UNAME /home/$UNAME
15
+
16
+ # install Python
17
+ RUN apt-get update -y && \
18
+ apt-get install -y software-properties-common build-essential git gcc curl make vim xorg-dev libxcb-shm0 libglu1-mesa-dev clang libc++-dev libc++abi-dev libsdl2-dev ninja-build libxi-dev libtbb-dev libosmesa6-dev libudev-dev autoconf libtool && \
19
+ add-apt-repository -y ppa:deadsnakes/ppa && \
20
+ apt-get update -y && \
21
+ apt-get install -y python3.10 python3.10-dev python3.10-distutils
22
+ RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
23
+
24
+ USER $UNAME
25
+
26
+ # install python packages
27
+ COPY --chown=$UNAME requirements.txt /tmp/requirements.txt
28
+ RUN python3.10 -m pip install --no-cache-dir --upgrade setuptools distlib pip && \
29
+ python3.10 -m pip install --no-cache-dir -r /tmp/requirements.txt && \
30
+ rm /tmp/requirements.txt
31
+ RUN python3.10 -m pip install git+https://github.com/facebookresearch/detectron2.git@fc9c33b1f6e5d4c37bbb46dde19af41afc1ddb2a
32
+ RUN git clone https://github.com/isl-org/Open3D.git && \
33
+ cd Open3D/ && \
34
+ mkdir build && \
35
+ cd build && \
36
+ cmake -DENABLE_HEADLESS_RENDERING=ON \
37
+ -DBUILD_GUI=OFF \
38
+ -DBUILD_WEBRTC=OFF \
39
+ -DUSE_SYSTEM_GLEW=OFF \
40
+ -DUSE_SYSTEM_GLFW=OFF \
41
+ .. && \
42
+ make && \
43
+ make install-pip-package
44
+
45
+ # copy files
46
+ COPY --chown=$UNAME . /home/$UNAME/opdmulti-demo
47
+
48
+ ENV TORCH_CUDA_ARCH_LIST='8.0'
49
+ ENV FORCE_CUDA=1
50
+ # TODO: just install into /tmp instead of creating a user folder
51
+ RUN mkdir tmp && \
52
+ cd opdmulti-demo/mask2former/modeling/pixel_decoder/ops && \
53
+ python3.10 setup.py build install --prefix /home/$UNAME/tmp
54
+ USER root
55
+ RUN mv /home/$UNAME/tmp/local/lib/python3.10/dist-packages/MultiScaleDeformableAttention-1.0-py3.10-linux-x86_64.egg /usr/local/lib/python3.10/dist-packages/ && rm -rf /home/$UNAME/tmp
56
+ USER $UNAME
57
+ ENV PYTHONPATH="/usr/local/lib/python3.10/dist-packages/MultiScaleDeformableAttention-1.0-py3.10-linux-x86_64.egg"
58
+
59
+ WORKDIR /home/$UNAME/opdmulti-demo
60
+
61
+ CMD ["python3.10", "app.py"]
README.md CHANGED
@@ -3,26 +3,47 @@ title: Opdmulti Demo
3
  emoji: 🌍
4
  colorFrom: gray
5
  colorTo: red
6
- sdk: gradio
7
- sdk_version: 3.44.3
8
- app_file: app.py
9
  pinned: false
10
  license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
 
15
- # Installation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  To setup the environment, run the following (recommended in a virtual environment):
18
  ```
19
  # install base requirements
20
- pip install -r pre-requirements.txt
21
- pip install -r requirements.txt
 
 
22
 
 
23
  cd mask2former/modeling/pixel_decoder/ops
24
  python setup.py build install
25
 
 
 
26
  # Option A: running locally only
27
  pip install open3d==0.17.0
28
 
@@ -39,10 +60,21 @@ cd ../examples/python/visualization/
39
  python headless_rendering.py
40
  ```
41
 
42
- The setup with pre-requirements.txt and requirements.txt resolves the issue that certain packages need to be installed
43
- prior to others. By default, most additional packages should be added to requirements.txt.
44
-
45
  ## Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  To startup the application locally, run
47
  ```
48
  gradio app.py
@@ -50,4 +82,4 @@ gradio app.py
50
 
51
  You can view the app on the specified port (usually 7860). To run over an ssh connection, setup port forwarding using
52
  `-L 7860:localhost:7860` when you create your ssh connection. Note that you will need to install Open3D in headless
53
- rendering for this to work.
 
3
  emoji: 🌍
4
  colorFrom: gray
5
  colorTo: red
6
+ sdk: docker
7
+ app_port: 7860
 
8
  pinned: false
9
  license: mit
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
13
 
14
+ ## Installation
15
+
16
+ ## Requirements
17
+
18
+ For the docker build, you will just need docker in order to build and run the container, else you will need
19
+
20
+ * python 3.10
21
+ * git
22
+ * libosmesa6-dev (for open3d headless rendering)
23
+
24
+ ### Docker (preferred)
25
+
26
+ To build the docker container, run
27
+ ```
28
+ docker build -f Dockerfile -t opdmulti-demo .
29
+ ```
30
+
31
+ ### Local
32
 
33
  To setup the environment, run the following (recommended in a virtual environment):
34
  ```
35
  # install base requirements
36
+ python3.10 -m pip install -r requirements.txt
37
+
38
+ # install detectron2 (must be done after some of the libraries in requirements.txt)
39
+ python3.10 -m pip install git+https://github.com/facebookresearch/detectron2.git@fc9c33b1f6e5d4c37bbb46dde19af41afc1ddb2a
40
 
41
+ # build library for model
42
  cd mask2former/modeling/pixel_decoder/ops
43
  python setup.py build install
44
 
45
+ # INSTALL OPEN3D
46
+ # --------------
47
  # Option A: running locally only
48
  pip install open3d==0.17.0
49
 
 
60
  python headless_rendering.py
61
  ```
62
 
 
 
 
63
  ## Usage
64
+
65
+ ### Docker (preferred)
66
+
67
+ To run the docker container, execute
68
+ ```
69
+ docker run -d --network host -t opdmulti-demo
70
+ ```
71
+ If you want to see the output of the container or interact with it,
72
+
73
+ * use `-it` to run in interactive mode, and remove the `-d` option
74
+ * add `bash` to the end to open into a console rather than running the app directly
75
+
76
+ ### Local
77
+
78
  To startup the application locally, run
79
  ```
80
  gradio app.py
 
82
 
83
  You can view the app on the specified port (usually 7860). To run over an ssh connection, setup port forwarding using
84
  `-L 7860:localhost:7860` when you create your ssh connection. Note that you will need to install Open3D in headless
85
+ rendering for this to work, as described above.
app.py CHANGED
@@ -19,7 +19,7 @@ SCORE_THRESHOLD = 0.8
19
  MAX_PARTS = 5
20
  ARGS = SimpleNamespace(
21
  config_file="configs/coco/instance-segmentation/swin/opd_v1_real.yaml",
22
- model="../data/models/motion_state_pred_opdformerp_rgb.pth",
23
  input_format="RGB",
24
  output=".output",
25
  cpu=True,
@@ -54,6 +54,7 @@ def predict(rgb_image: str, depth_image: str, intrinsics: np.ndarray, num_sample
54
  return images
55
 
56
  # clear old predictions
 
57
  for path in os.listdir(ARGS.output):
58
  full_path = os.path.join(ARGS.output, path)
59
  if os.path.isdir(full_path):
 
19
  MAX_PARTS = 5
20
  ARGS = SimpleNamespace(
21
  config_file="configs/coco/instance-segmentation/swin/opd_v1_real.yaml",
22
+ model=".data/models/motion_state_pred_opdformerp_rgb.pth",
23
  input_format="RGB",
24
  output=".output",
25
  cpu=True,
 
54
  return images
55
 
56
  # clear old predictions
57
+ os.makedirs(ARGS.output, exist_ok=True)
58
  for path in os.listdir(ARGS.output):
59
  full_path = os.path.join(ARGS.output, path)
60
  if os.path.isdir(full_path):
pre-requirements.txt DELETED
@@ -1,6 +0,0 @@
1
- numpy==1.25.2
2
- Pillow==10.0.1
3
- torch==2.0.1
4
- torchaudio==2.0.2
5
- torchvision==0.15.2
6
- urllib3==1.26.16
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  h5py==3.9.0
2
  imageio==2.31.3
3
  opencv-python==4.8.0.76
@@ -10,5 +16,3 @@ timm==0.9.7
10
  black==23.9.1
11
  gradio==3.44.3
12
  huggingface-hub==0.17.2
13
- detectron2 @ git+https://github.com/facebookresearch/detectron2.git@fc9c33b1f6e5d4c37bbb46dde19af41afc1ddb2a
14
- -e mask2former/modeling/pixel_decoder/ops/
 
1
+ numpy==1.25.2
2
+ Pillow==10.0.1
3
+ torch==2.0.1
4
+ torchaudio==2.0.2
5
+ torchvision==0.15.2
6
+ urllib3==1.26.16
7
  h5py==3.9.0
8
  imageio==2.31.3
9
  opencv-python==4.8.0.76
 
16
  black==23.9.1
17
  gradio==3.44.3
18
  huggingface-hub==0.17.2