-
Notifications
You must be signed in to change notification settings - Fork 14
Add Docker support and update test/demo scripts to use automatic Hugging Face downloads #28
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
Changes from all commits
2f69e4e
530a886
43aef6e
bb79602
d66a0a0
c43b46b
74d2dab
30eb7fc
53aefde
1ff5d01
8768cc4
ce1c4f0
e122e51
3d1253a
ec10769
6254cc8
d6e1fdb
3bb81e5
f1631c9
962f395
09ce42f
94b5100
b2151a6
ef803e7
bdd95b1
6107a7a
2b1626d
c944d25
e185185
11ab3d3
2f5f771
52c2497
89ff316
9f46de8
478abcd
8098412
1eb00b4
8b402c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| FROM pytorch/pytorch:2.4.1-cuda12.4-cudnn9-runtime | ||
|
|
||
| ARG USERNAME=fmpose3d | ||
| ARG USER_UID=1000 | ||
| ARG USER_GID=1000 | ||
| RUN groupadd ${USERNAME} --gid ${USER_GID} | ||
| RUN useradd -m -s /bin/bash -g ${USERNAME} -u ${USER_UID} ${USERNAME} | ||
| RUN mkdir /app /logs /data | ||
|
|
||
| ENV DEBIAN_FRONTEND=noninteractive | ||
| SHELL ["/bin/bash", "-c"] | ||
| RUN apt-get update -y && apt-get install -yy --no-install-recommends \ | ||
| vim zsh tmux wget curl htop git sudo ssh git-lfs \ | ||
| python3 python3-pip \ | ||
| libgl1-mesa-glx libglib2.0-0 \ | ||
| ffmpeg \ | ||
| && apt-get -y autoclean \ | ||
| && apt-get -y autoremove \ | ||
| && rm -rf /var/lib/apt/lists/* \ | ||
| && apt-get clean | ||
|
|
||
| ENV PATH="/opt/conda/bin:${PATH}" | ||
|
|
||
| # Initialize conda for root just in case and fix symlinks | ||
| RUN ln -fs /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh | ||
|
|
||
| # --- Install FMPose3D from GitHub --- | ||
| RUN python -m pip install --no-cache-dir --upgrade pip && \ | ||
| git clone --depth 1 https://github.com/AdaptiveMotorControlLab/FMPose3D.git /tmp/fmpose3d && \ | ||
| python -m pip install --no-cache-dir "/tmp/fmpose3d[animals,viz]" gdown && \ | ||
| rm -rf /tmp/fmpose3d | ||
|
Comment on lines
+28
to
+31
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since docker is often used for reproducability, I think it would be best if you pin a specific version here, instead of cloning at
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestions! Actually, for the first version, I pinned a specific version, but this PR changes some functions inside the package, which makes the currently released package version not work with the training code. |
||
|
|
||
| # Allow non-root user to download DLC model weights at runtime | ||
| RUN DLC_MODELZOO_DIR="$(python -c "import site, pathlib; print(pathlib.Path(site.getsitepackages()[0]) / 'deeplabcut' / 'modelzoo')")" \ | ||
| && mkdir -p "${DLC_MODELZOO_DIR}/checkpoints" \ | ||
| && chown -R "${USERNAME}:${USERNAME}" "${DLC_MODELZOO_DIR}" | ||
|
|
||
| # Set your user as owner of the home directory before switching | ||
| RUN chown -R ${USERNAME}:${USERNAME} /home/${USERNAME} | ||
|
|
||
| ENV NVIDIA_DRIVER_CAPABILITIES=all | ||
|
|
||
| # --- SWITCH TO USER --- | ||
| USER ${USERNAME} | ||
| ENV HOME=/home/${USERNAME} | ||
| WORKDIR ${HOME} | ||
|
|
||
| # Ensure dotfiles exist | ||
| RUN touch ${HOME}/.bashrc ${HOME}/.zshrc && \ | ||
| chmod 644 ${HOME}/.bashrc ${HOME}/.zshrc | ||
|
|
||
| # Install Oh My Zsh and plugins (MUST come before conda init, since OMZ overwrites .zshrc) | ||
| RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended \ | ||
| && git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions \ | ||
| && git clone https://github.com/zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting \ | ||
| && sed -i 's/^plugins=(.*)$/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/' ~/.zshrc \ | ||
| && echo "export PATH=\$PATH:${HOME}/.local/bin" >> ~/.zshrc | ||
|
|
||
| # Initialize conda AFTER Oh My Zsh (so conda init block is not overwritten) | ||
| RUN /opt/conda/bin/conda init bash && /opt/conda/bin/conda init zsh | ||
|
|
||
| # Add conda activation to bashrc and zshrc | ||
| RUN echo "conda activate base" >> ${HOME}/.bashrc && \ | ||
| echo "conda activate base" >> ${HOME}/.zshrc | ||
|
|
||
| SHELL ["/bin/zsh", "-c"] | ||
| CMD ["zsh"] | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,66 @@ | ||||||||
| # [USER: ADJUST PATH] | ||||||||
| PROJECT_NAME := fmpose3d | ||||||||
| ####### | ||||||||
| # RUN # | ||||||||
| ####### | ||||||||
|
|
||||||||
| # for local server | ||||||||
| IMG_NAME := fmpose3d | ||||||||
| IMG_TAG := v0.1 | ||||||||
| DOCKERFILE := Dockerfile | ||||||||
| # Linux/macOS: use host UID/GID; Windows fallback to 1000 | ||||||||
| HOST_UID ?= $(shell sh -c 'id -u 2>/dev/null || echo 1000') | ||||||||
| HOST_GID ?= $(shell sh -c 'id -g 2>/dev/null || echo 1000') | ||||||||
| BUILD_ARGS := \ | ||||||||
| --build-arg USERNAME=fmpose3d \ | ||||||||
| --build-arg USER_GID=$(HOST_GID) \ | ||||||||
| --build-arg USER_UID=$(HOST_UID) | ||||||||
|
|
||||||||
| build: | ||||||||
| docker build $(BUILD_ARGS) \ | ||||||||
| -t $(IMG_NAME):$(IMG_TAG) -f $(DOCKERFILE) . | ||||||||
|
|
||||||||
| build-clean: | ||||||||
| docker build --no-cache $(BUILD_ARGS) \ | ||||||||
| -t $(IMG_NAME):$(IMG_TAG) -f $(DOCKERFILE) . | ||||||||
|
|
||||||||
|
|
||||||||
| CONTAINER_NAME := fmpose3d_dev1 | ||||||||
| # [USER: ADJUST] Mount the project root into the container | ||||||||
| HOST_SRC := $(shell pwd) | ||||||||
| DOCKER_SRC := /fmpose3d | ||||||||
| VOLUMES := \ | ||||||||
| --volume "$(HOST_SRC):$(DOCKER_SRC)" | ||||||||
|
|
||||||||
|
|
||||||||
| run: | ||||||||
| docker run -it --gpus all --shm-size=64g --name $(CONTAINER_NAME) -w $(DOCKER_SRC) $(VOLUMES) $(IMG_NAME):$(IMG_TAG) | ||||||||
|
|
||||||||
| exec: | ||||||||
| docker exec -it -w $(DOCKER_SRC) $(CONTAINER_NAME) /bin/zsh | ||||||||
|
|
||||||||
| exec_bash: | ||||||||
| docker exec -it -w $(DOCKER_SRC) $(CONTAINER_NAME) /bin/bash | ||||||||
|
|
||||||||
| stop: | ||||||||
| docker stop $(CONTAINER_NAME) | ||||||||
|
|
||||||||
| rm: | ||||||||
| docker rm $(CONTAINER_NAME) | ||||||||
|
|
||||||||
| # Help message | ||||||||
| help: | ||||||||
| @echo "Available targets:" | ||||||||
| @echo " build - Build Docker image for local server." | ||||||||
| @echo " run - Run a Docker container with GPU." | ||||||||
| @echo " exec - Attach to running container (zsh)." | ||||||||
| @echo " exec_bash - Attach to running container (bash)." | ||||||||
| @echo " stop - Stop the running container." | ||||||||
| @echo " rm - Remove the stopped container." | ||||||||
| @echo " help - Show this help message." | ||||||||
| @echo "" | ||||||||
| @echo "Usage:" | ||||||||
| @echo " 1. make build" | ||||||||
| @echo " 2. make run" | ||||||||
| @echo " 3. Inside container: pip install -e '.[animals,viz]'" | ||||||||
| @echo " 4. Inside container: sh scripts/FMPose3D_train.sh" | ||||||||
|
Comment on lines
+65
to
+66
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the dockerfile allready installs fmpose, right?
Suggested change
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,7 @@ | |
| ProgressCallback = Callable[[int, int], None] | ||
|
|
||
|
|
||
| #: HuggingFace repository hosting the official FMPose3D checkpoints. | ||
| _HF_REPO_ID: str = "deruyter92/fmpose_temp" | ||
| from fmpose3d.utils.weights import HF_REPO_ID as _HF_REPO_ID | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good fix, thanks! Maybe just move it to the import block with the other |
||
|
|
||
| # Default camera-to-world rotation quaternion (from the demo script). | ||
| _DEFAULT_CAM_ROTATION = np.array( | ||
|
|
@@ -759,8 +758,6 @@ class _IngestedInput: | |
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| # FIXME @deruyter92: THIS IS TEMPORARY UNTIL WE DOWNLOAD THE WEIGHTS FROM HUGGINGFACE | ||
| SKIP_WEIGHTS_VALIDATION = object() # sentinel value to indicate that the weights should not be validated | ||
|
|
||
| class FMPose3DInference: | ||
| """High-level, two-step inference API for FMPose3D. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be safe, you could change this to the below suggestion, since the current command may fail if the user allready exists (e.g. in the parent image). But I don't expect that this is a realistic scenario, so you can also keep yours, for better readability.