Skip to content

Commit 58dc8b7

Browse files
authored
Readme update and locally MacOS test (install from repo) (#10)
1 parent 77773ec commit 58dc8b7

2 files changed

Lines changed: 100 additions & 60 deletions

File tree

README.md

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Xiaohang Yu, Ti Wang, Mackenzie Weygandt Mathis
1212
---
1313

1414

15-
## 🚀 TL;DR
15+
## TL;DR
1616
PRIMA creates a 3D quadruped mesh from a single 2D image. It leverages BioCLIP-based biological priors for robust cross-species shape understanding, then applies test-time adaptation with 2D reprojection and auxiliary keypoint guidance to refine SMAL pose and shape predictions.
1717

1818
It further can be used to build Quadruped3D, a large-scale pseudo-3D dataset with diverse species and poses.
@@ -21,15 +21,19 @@ PRIMA achieves state-of-the-art results on Animal3D, CtrlAni3D, Quadruped2D, and
2121

2222
## Installation
2323

24+
PRIMA requires Python 3.10 or newer. A CUDA-enabled PyTorch installation is
25+
recommended for local inference and training.
26+
2427
### Install from PyPI
2528

26-
> Recommended: Python 3.10 and a CUDA-enabled PyTorch installation.
29+
Create a clean environment, install PyTorch for your CUDA version, then install
30+
the package:
2731

2832
```bash
2933
conda create -n prima python=3.10 -y
3034
conda activate prima
3135

32-
# Install PyTorch matching your CUDA (example: CUDA 11.8)
36+
# Example for CUDA 11.8. Adjust this command for your CUDA version.
3337
pip install --index-url https://download.pytorch.org/whl/cu118 \
3438
"torch==2.2.1" "torchvision==0.17.1" "torchaudio==2.2.1"
3539

@@ -39,48 +43,60 @@ python -m pip install --no-build-isolation \
3943
python -m pip install --no-build-isolation \
4044
"git+https://github.com/facebookresearch/pytorch3d.git"
4145

46+
# Install PRIMA from PyPI-test (for now)
47+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple prima-animal==0.1.7
48+
4249
# Install PRIMA from PyPI
4350
pip install prima-animal
4451
```
4552

4653
`prima-animal` includes demo runtime dependencies used by `demo.py`, `demo_tta.py`, and `app.py` (including Detectron2 and DeepLabCut).
4754

48-
### Clean install from this repository
55+
### Install from this repository
56+
57+
Use this path if you want to run the code from a fresh clone.
58+
59+
```bash
60+
git clone https://github.com/AdaptiveMotorControlLab/PRIMA.git
61+
cd PRIMA
62+
```
4963

50-
Use these when developing from a **git clone** (not the PyPI wheel). The shell scripts are **non-interactive** (pip uses `--no-input`; `GIT_TERMINAL_PROMPT=0` for git). Put Hugging Face credentials in your environment or git credential helper before pushing the Space.
64+
The helper script below creates a fresh virtual environment, installs runtime
65+
dependencies, pulls Git LFS assets if available, downloads the default demo
66+
checkpoints/data, and verifies that the demo dependencies can be imported:
5167

52-
**Local (fresh venv, LFS assets, Hub demo weights, smoke test)** — requires **Python 3.10+**
53-
(Gradio 5.1+ / Space-provided Gradio 6.x and `app.py` type hints). On macOS without `python3.10` on your `PATH`, install
54-
`brew install python@3.10` and set `PRIMA_PYTHON=/opt/homebrew/bin/python3.10`.
5568

5669
```bash
57-
chmod +x scripts/clean_install_local.sh scripts/clean_redeploy_hf_space.sh scripts/deploy_hf_space.sh
58-
PRIMA_PYTHON=/opt/homebrew/bin/python3.10 ./scripts/clean_install_local.sh
70+
PRIMA_PYTHON=/path/to/python3.10 \
71+
PRIMA_VENV=prima_env \
72+
./scripts/clean_install_local.sh
73+
source prima_env/bin/activate
5974
```
6075

6176
Options:
6277

63-
- `PRIMA_VENV=.venv ./scripts/clean_install_local.sh --skip-data` — skip the large `setup_demo_data` download if `data/` is already populated.
64-
- `./scripts/clean_install_local.sh --wipe-data --force-data` — delete downloaded `data/` assets and redownload.
65-
- `./scripts/clean_install_local.sh --no-editable` — only `requirements.txt` (no `pip install -e .`); use if editable install fails and you will install the training stack via conda as in the PyPI section above. You still need **Python 3.10+** for Gradio 5.1+. The smoke test sets `PYTHONPATH` to the repo root so `import prima` works without an editable install.
66-
- **macOS / DeepLabCut:** `requirements.txt` pins `deeplabcut==3.0.0rc14`
67-
for the SuperAnimal PyTorch API. On macOS, `clean_install_local.sh` installs
68-
it separately after a compatible PyTables wheel (`tables>=3.9.2,<3.11`) to
69-
avoid Apple Silicon build issues. Validate the local setup with
70-
`./scripts/test_local_full.sh`.
78+
- `--skip-data` skips the large demo data download if `data/` is already populated.
79+
- `--wipe-data --force-data` removes downloaded demo assets and downloads them again.
80+
- `--no-editable` installs dependencies without registering the repo as an editable package.
7181

72-
After `requirements.txt`, the script runs **`pip install --no-deps -e .`** so the `prima` package is registered without re-resolving `pyproject.toml` (which would pull **Detectron2** from git again). Install Detectron2 separately if needed: `pip install 'git+https://github.com/facebookresearch/detectron2.git'`.
82+
On macOS, install Python 3.10 if needed:
7383

74-
**Hugging Face Space (full redeploy from your working tree):**
84+
```bash
85+
brew install python@3.10
86+
PRIMA_PYTHON=/opt/homebrew/bin/python3.10 \
87+
PRIMA_VENV=prima_env \
88+
./scripts/clean_install_local.sh
89+
source prima_env/bin/activate
90+
```
7591

76-
Requires [Git LFS / Xet](https://huggingface.co/docs/hub/xet/using-xet-storage#git) tooling (`brew install git-lfs git-xet`, `git xet install`, `git lfs install`). Then:
92+
If macOS reports `Cannot read image: demo_data/...`, install Git LFS and pull
93+
the demo images:
7794

7895
```bash
79-
./scripts/clean_redeploy_hf_space.sh
96+
git lfs install
97+
git lfs pull --include="demo_data/*"
8098
```
8199

82-
This is equivalent to `./scripts/deploy_hf_space.sh` and force-pushes a fresh snapshot to the Space.
83-
84100
---
85101

86102
## Demo
@@ -170,32 +186,6 @@ The `s1ckpt_inference.ckpt` checkpoint is downloaded automatically if missing.
170186

171187
Override for testing: `PRIMA_DEMO_MODE=local` or `PRIMA_DEMO_MODE=space`.
172188

173-
#### Hugging Face Space (maintainers)
174-
175-
Demo images under `demo_data/` and `images/teaser.png` are tracked with **Git LFS**
176-
(see `.gitattributes`) so they can be pushed to a Hugging Face Space under the Hub’s
177-
LFS / **Xet** bridge. Install tooling once:
178-
179-
```bash
180-
brew install git-lfs git-xet
181-
git xet install
182-
git lfs install
183-
```
184-
185-
Then from a clean checkout with LFS files present, redeploy the Space (same as `clean_redeploy_hf_space.sh`):
186-
187-
```bash
188-
./scripts/deploy_hf_space.sh
189-
# or
190-
./scripts/clean_redeploy_hf_space.sh
191-
```
192-
193-
The script rsyncs only the Git-tracked files needed by the Space from the
194-
working tree (not `git archive`) so image files are materialized before
195-
`git add` turns them into LFS blobs.
196-
During deployment, `detectron2` is removed from the Space `requirements.txt`;
197-
the app uses the DeepLabCut SuperAnimal detector fallback on the CPU Space.
198-
199189
---
200190

201191

scripts/clean_install_local.sh

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,69 @@ resolve_python() {
6868
return 1
6969
fi
7070
local c p
71-
for c in python3.12 python3.11 python3.10; do
71+
for c in python3.10 python3.11; do
7272
if command -v "$c" >/dev/null 2>&1; then
7373
if "$c" -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 10) else 1)'; then
7474
command -v "$c"
7575
return 0
7676
fi
7777
fi
7878
done
79-
for p in /opt/homebrew/bin/python3.10 /usr/local/bin/python3.10; do
79+
for p in /opt/homebrew/bin/python3.10 /usr/local/bin/python3.10 /opt/homebrew/opt/python@3.10/bin/python3.10 /usr/local/opt/python@3.10/bin/python3.10; do
8080
if [[ -x "$p" ]]; then
8181
echo "$p"
8282
return 0
8383
fi
8484
done
85+
if command -v python3.12 >/dev/null 2>&1; then
86+
command -v python3.12
87+
return 0
88+
fi
89+
return 1
90+
}
91+
92+
resolve_torch_index_url() {
93+
if [[ -n "${PRIMA_TORCH_INDEX_URL:-}" ]]; then
94+
echo "${PRIMA_TORCH_INDEX_URL}"
95+
return 0
96+
fi
97+
98+
if [[ "$(uname -s)" == "Darwin" ]]; then
99+
return 1
100+
fi
101+
102+
if command -v nvcc >/dev/null 2>&1; then
103+
local cuda_version
104+
cuda_version="$(nvcc --version | sed -n 's/.*release \([0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | head -n 1)"
105+
case "${cuda_version}" in
106+
11.8)
107+
echo "https://download.pytorch.org/whl/cu118"
108+
return 0
109+
;;
110+
12.1)
111+
echo "https://download.pytorch.org/whl/cu121"
112+
return 0
113+
;;
114+
"")
115+
echo "[clean-install] WARN: Could not parse nvcc CUDA version; using pip default PyTorch wheel." >&2
116+
return 1
117+
;;
118+
*)
119+
echo "[clean-install] WARN: CUDA ${cuda_version} detected; set PRIMA_TORCH_INDEX_URL if Detectron2 needs a specific PyTorch wheel." >&2
120+
return 1
121+
;;
122+
esac
123+
fi
124+
85125
return 1
86126
}
87127

88128
echo "[clean-install] Repository: ${ROOT}"
89129

90130
if ! PY="$(resolve_python)"; then
91-
echo "[clean-install] ERROR: Need Python 3.10 or newer (Gradio 5 + app type hints)." >&2
92-
echo " macOS: brew install python@3.10" >&2
93-
echo " Then: PRIMA_PYTHON=/opt/homebrew/bin/python3.10 $0 ..." >&2
131+
echo "[clean-install] ERROR: Need Python 3.10, 3.11, or 3.12 on PATH, or set PRIMA_PYTHON." >&2
132+
echo " Conda example: PRIMA_PYTHON=\$HOME/miniconda3/envs/prima/bin/python3.10 $0 ..." >&2
133+
echo " macOS example: brew install python@3.10 && PRIMA_PYTHON=/opt/homebrew/bin/python3.10 $0 ..." >&2
94134
exit 1
95135
fi
96136
echo "[clean-install] Using Python: $("$PY" -c 'import sys; print(sys.executable, sys.version.split()[0])')"
@@ -116,10 +156,20 @@ source "${VENV}/bin/activate"
116156
python -m pip install --no-input -U pip wheel
117157
# Match requirements.txt / pyproject pins before pulling the rest
118158
python -m pip install --no-input "setuptools<81" "packaging<25" "Cython<3"
159+
python -m pip install --no-input "numpy==1.26.1"
160+
161+
echo "[clean-install] xtcocotools (needs numpy available during build) ..."
162+
python -m pip install --no-input --no-build-isolation "xtcocotools==1.14.3"
163+
164+
if TORCH_INDEX_URL="$(resolve_torch_index_url)"; then
165+
echo "[clean-install] Installing PyTorch from ${TORCH_INDEX_URL} ..."
166+
python -m pip install --no-input --index-url "${TORCH_INDEX_URL}" \
167+
"torch==2.2.1" "torchvision==0.17.1"
168+
fi
119169

120170
echo "[clean-install] pip install -r requirements.txt (this can take a long time) ..."
121171
REQ_TMP="$(mktemp)"
122-
grep -vE '^[[:space:]]*(deeplabcut|detectron2)' "${ROOT}/requirements.txt" > "${REQ_TMP}"
172+
grep -vE '^[[:space:]]*(deeplabcut|detectron2|xtcocotools)' "${ROOT}/requirements.txt" > "${REQ_TMP}"
123173
python -m pip install --no-input -r "${REQ_TMP}"
124174
rm -f "${REQ_TMP}"
125175

@@ -153,12 +203,12 @@ if [[ "$WIPE_DATA" -eq 1 ]]; then
153203
fi
154204

155205
if [[ "$SKIP_DATA" -eq 0 ]]; then
156-
FORCE_ARGS=()
206+
echo "[clean-install] Downloading demo assets (large) ..."
157207
if [[ "$FORCE_DATA" -eq 1 ]]; then
158-
FORCE_ARGS=(--force)
208+
python "${ROOT}/scripts/setup_demo_data.py" --force
209+
else
210+
python "${ROOT}/scripts/setup_demo_data.py"
159211
fi
160-
echo "[clean-install] Downloading demo assets (large) ..."
161-
python "${ROOT}/scripts/setup_demo_data.py" "${FORCE_ARGS[@]}"
162212
else
163213
echo "[clean-install] Skipping setup_demo_data (--skip-data)."
164214
fi

0 commit comments

Comments
 (0)