Skip to content

Commit d47c579

Browse files
chyomin06fracape
authored andcommitted
[feat] SAM2 installation script
1 parent 4fb20be commit d47c579

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ It currently focuses on two types of pipeline:
2626

2727
- [Segment Anything](https://github.com/facebookresearch/segment-anything/tree/main)
2828

29+
- [Segment Anything 2 (SAM2)](https://github.com/facebookresearch/sam2?tab=readme-ov-file)
30+
2931
## Documentation
3032

3133
A complete documentation is provided [here](https://interdigitalinc.github.io/CompressAI-Vision/index.html), including [installation](https://interdigitalinc.github.io/CompressAI-Vision/installation), [CLI usage](https://interdigitalinc.github.io/CompressAI-Vision/cli_usage.html), as well as [tutorials](https://interdigitalinc.github.io/CompressAI-Vision/tutorials).
@@ -80,6 +82,9 @@ path/to/weights/jde/jde.1088x608.uncertainty.pt
8082
The file can be downloaded at the following link (in place of the above file path):
8183
"https://docs.google.com/uc?export=download&id=1nlnuYfGNuHWZztQHXwVZSL_FvfE551pA"
8284

85+
NOTE 3: SAM2 requires python>=3.10, torch>=2.5.1 and torchvision>=0.20.1., which are higher versions of the packages needed for the previous models installation.
86+
For instance, the installation of models with the ‘-—fcm-cttc’ configuration may be incompatible with SAM2 installation, and vice versa.
87+
8388
### 2. Using uv:
8489
Within the root folder of compressai-vision:
8590
```
@@ -176,4 +181,5 @@ If you use this project, please cite:
176181
* [JDE](https://github.com/Zhongdao/Towards-Realtime-MOT.git)
177182
* [YOLOX](https://github.com/Megvii-BaseDetection/YOLOX)
178183
* [MMPOSE RTMO](https://github.com/open-mmlab/mmpose/tree/main/projects/rtmo)
179-
* [Segment Anything](https://github.com/facebookresearch/segment-anything/tree/main)
184+
* [Segment Anything](https://github.com/facebookresearch/segment-anything/tree/main)
185+
* [SAM2](https://github.com/facebookresearch/sam2?tab=readme-ov-file)

scripts/install.sh

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "${SCRIPT_PATH}")" &> /dev/null && pwd)
88

99
# --- Configuration ---
1010
# Central array for all vision models
11-
VISION_MODELS=(detectron2 jde yolox mmpose segment_anything)
11+
VISION_MODELS=(detectron2 jde yolox mmpose segment_anything sam2)
1212

1313
# Default versions
1414
TORCH_VERSION="2.0.0"
@@ -86,6 +86,10 @@ fe5ad56ff746aa55c5f453b01f8395134e9281d240dbeb473411d4a6b262c9dc detectron2/COC
8686
516a421f8717548300c3ee6356a3444ac539083d4a9912f8ca1619ee63d0986d mmpose/rtmo_coco/rtmo-l_16xb16-600e_coco-640x640-516a421f_20231211.pth https://download.openmmlab.com/mmpose/v1/projects/rtmo/rtmo-l_16xb16-600e_coco-640x640-516a421f_20231211.pth
8787
b5905e9faf500a2608c93991f91a41a6150bcd2dd30986865a73becd94542fa1 yolox/darknet53/yolox_darknet.pth https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_darknet.pth
8888
a7bf3b02f3ebf1267aba913ff637d9a2d5c33d3173bb679e46d9f338c26f262e segment_anything/sam_vit_h_4b8939.pth https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
89+
a2345aede8715ab1d5d31b4a509fb160c5a4af1970f199d9054ccfb746c004c5 sam2/sam2.1_hiera_base_plus.pt https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_base_plus.pt
90+
2647878d5dfa5098f2f8649825738a9345572bae2d4350a2468587ece47dd318 sam2/sam2.1_hiera_large.pt https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt
91+
6d1aa6f30de5c92224f8172114de081d104bbd23dd9dc5c58996f0cad5dc4d38 sam2/sam2.1_hiera_small.pt https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_small.pt
92+
7402e0d864fa82708a20fbd15bc84245c2f26dff0eb43a4b5b93452deb34be69 sam2/sam2.1_hiera_tiny.pt https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_tiny.pt
8993
"
9094

9195

@@ -480,14 +484,48 @@ install_segment_anything () {
480484
cd "${COMPRESSAI_VISION_ROOT_DIR}"
481485
}
482486

487+
prepare_sam2 () {
488+
echo
489+
echo "Preparing Segment Anything 2 for installation"
490+
echo
491+
492+
if [ -d "${MODELS_SOURCE_DIR}/sam2" ] && [ -n "$(ls -A "${MODELS_SOURCE_DIR}/sam2")" ]; then
493+
echo "Source directory already exists: ${MODELS_SOURCE_DIR}/sam2"
494+
return
495+
fi
496+
497+
git clone https://github.com/facebookresearch/sam2.git "${MODELS_SOURCE_DIR}/sam2"
498+
cd "${MODELS_SOURCE_DIR}/sam2"
499+
# Dec 16, 2024
500+
git reset --hard 2b90b9f5ceec907a1c18123530e92e794ad901a4
501+
cd "${COMPRESSAI_VISION_ROOT_DIR}"
502+
}
503+
504+
install_sam2 () {
505+
echo
506+
echo "Installing Segment Anything 2 (reference: https://github.com/facebookresearch/sam2)"
507+
echo "Requirements: python>=3.10, as well as torch>=2.5.1 and torchvision>=0.20.1."
508+
echo
509+
510+
cd "${MODELS_SOURCE_DIR}/sam2"
511+
512+
if [[ "${PACKAGE_MANAGER}" == "pip3" ]]; then
513+
"${PIP[@]}" install -e .
514+
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
515+
cd "${COMPRESSAI_VISION_ROOT_DIR}"
516+
uv sync --inexact --group=models-sam2
517+
fi
518+
519+
cd "${COMPRESSAI_VISION_ROOT_DIR}"
520+
}
483521

484522
download_weights () {
485523
detect_env
486524
mkdir -p "${MODELS_WEIGHT_DIR}"
487525
cd "${MODELS_WEIGHT_DIR}/"
488-
489-
for model in detectron2 jde mmpose yolox segment_anything; do
490-
if ! [[ ",${MODEL,,}," == *",${model},"* ]] && [[ ",${MODEL,,}," != *",all,"* ]]; then
526+
527+
for model in detectron2 jde mmpose yolox segment_anything sam2; do
528+
if ! [[ ",${MODEL,,}," == *",${model},"* ]] && [[ ",${MODEL,,}," == *",all,"* ]]; then
491529
continue
492530
fi
493531

0 commit comments

Comments
 (0)