Skip to content

Commit bafda85

Browse files
committed
install: add fcm cttc mode to install all models and dependencies
conforming with MPEG FCM CTTC
1 parent e95efa8 commit bafda85

11 files changed

+143
-39
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@ bash scripts/env_cuda.sh 11.8
5959
```
6060
Then, please run:
6161
```
62-
bash scripts/install.sh
62+
bash scripts/install.sh
6363
```
6464

65+
To install the dependencies in conformance with MPEG FCM Test Conditions, run:
66+
```
67+
bash scripts/install.sh --fcm-cttc
68+
```
69+
70+
6571
For more otions, check:
6672
```
6773
bash scripts/install.sh --help

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ classifiers = [
1717
"Intended Audience :: Science/Research",
1818
"Programming Language :: Python :: 3.8",
1919
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
2021
]
2122
requires-python = ">=3.8,<3.11"
23+
2224
dependencies = [
2325
"hydra-core",
2426
"lap>=0.5.12",

scripts/install.sh

Lines changed: 75 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ set -eu
66
SCRIPT_PATH="${BASH_SOURCE[0]:-${0}}"
77
SCRIPT_DIR=$(cd -- "$(dirname -- "${SCRIPT_PATH}")" &> /dev/null && pwd)
88

9+
# --- Configuration ---
10+
# Central array for all vision models
11+
VISION_MODELS=(detectron2 jde yolox mmpose segment_anything)
12+
13+
# Default versions
914
TORCH_VERSION="2.0.0"
1015
TORCHVISION_VERSION="0.15.1"
1116
CUDA_VERSION=""
@@ -16,6 +21,7 @@ MODELS_PARENT_DIR="${COMPRESSAI_VISION_ROOT_DIR}"
1621
NO_PREPARE="False"
1722
NO_INSTALL="False"
1823
DOWNLOAD_WEIGHTS="True"
24+
FCM_CTTC="False" # Install all models in conformance with MPEG FCM Common Test and Training Conditions
1925

2026
# Constrain DNNL to avoid AVX512, which leads to non-deterministic operation across different CPUs...
2127
export DNNL_MAX_CPU_ISA=AVX2
@@ -43,16 +49,19 @@ RUN OPTIONS:
4349
not required for regular versions derived from cuda and torch versions above.
4450
default:"https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html"]
4551
[--models_dir directory to install vision models to, default: compressai_vision_root]
46-
[--no-install) do not install (i.e. useful for only preparing source code by downloading and patching
52+
[--no-install) do not install (i.e. useful for only preparing source code by downloading and patching
4753
[--no-weights) prevents the installation script from downloading vision model parameters]
54+
[--fcm-cttc) Install all models in conformance with MPEG FCM Common Test and Training Conditions:
55+
Torch 2.0.0, Torchvision 0.15.1, CUDA 11.8]
4856
4957
5058
EXAMPLE [bash install.sh -m detectron2 -t "1.9.1" --cuda_version "11.8" --compressai /path/to/compressai]
59+
FCM EXAMPLE [bash install.sh --fcm-cttc]
5160
5261
_EOF_
5362
exit;
5463
;;
55-
-m|--model) shift; MODEL="$1"; shift; ;;
64+
-m|--model) shift; MODEL="${1//,/ }"; shift; ;;
5665
-t|--torch) shift; TORCH_VERSION="$1"; shift; ;;
5766
--torchvision) shift; TORCHVISION_VERSION="$1"; shift; ;;
5867
--cpu) CPU="True"; shift; ;;
@@ -61,6 +70,7 @@ _EOF_
6170
--no-prepare) NO_PREPARE="True"; shift; ;;
6271
--no-install) NO_INSTALL="True"; shift; ;;
6372
--no-weights) DOWNLOAD_WEIGHTS="False"; shift; ;;
73+
--fcm-cttc) FCM_CTTC="True"; shift; ;;
6474
*) echo "[ERROR] Unknown parameter $1"; exit; ;;
6575
esac;
6676
done;
@@ -112,6 +122,27 @@ detect_env() {
112122
}
113123

114124
main () {
125+
# --- FCM CTTC Installation ---
126+
if [[ "${FCM_CTTC}" == "True" ]]; then
127+
echo "🚀 FCM CTTC Mode Enabled: Enforcing strict versions for all models."
128+
TORCH_VERSION="2.0.0"
129+
# Correct torchvision version for torch 2.0.0
130+
TORCHVISION_VERSION="0.15.1"
131+
CUDA_VERSION="11.8"
132+
MODEL="detectron2 jde yolox"
133+
CPU="False"
134+
135+
# Verify CUDA version
136+
DETECTED_CUDA=$(nvcc --version | sed -n 's/^.*release \([0-9]\+\.[0-9]\+\).*$/\1/p')
137+
if [[ "${DETECTED_CUDA}" != "${CUDA_VERSION}" ]]; then
138+
echo "[ERROR] FCM CTTC Mode requires CUDA v${CUDA_VERSION}, but detected v${DETECTED_CUDA}."
139+
echo "Please ensure that your environment has CUDA v${CUDA_VERSION} installed."
140+
exit 1
141+
fi
142+
echo "CUDA version check passed for FCM CTTC Mode."
143+
fi
144+
# --- End FCM CTTC Mode Logic ---
145+
115146
detect_env
116147

117148
if [[ "${NO_PREPARE}" == "False" ]]; then
@@ -134,26 +165,34 @@ main () {
134165
run_prepare() {
135166
detect_env
136167
mkdir -p "${MODELS_SOURCE_DIR}"
168+
169+
echo "Selected Models to be prepared: ${MODEL}"
137170

138-
# NOTE: We always prepare all packages, even if they are not installed.
139-
# This helps with dependency resolution.
140-
for pkg in cython_bbox detectron2 jde mmpose yolox segment_anything; do
141-
"prepare_${pkg}"
171+
for model in "${VISION_MODELS[@]}"; do
172+
if [[ " ${MODEL,,} " == *" ${model} "* ]] || [[ "${MODEL,,}" == "all" ]]; then
173+
# JDE has a dependency on cython_bbox, so prepare it first.
174+
if [[ "${model}" == "jde" ]]; then
175+
prepare_cython_bbox
176+
fi
177+
"prepare_${model}"
178+
fi
142179
done
143180
}
144181

145182
run_install () {
146183
detect_env
147184
"${PIP[@]}" install -U pip wheel setuptools
185+
186+
echo "Selected Models to be installed: ${MODEL}"
148187

149188
if [[ "${PACKAGE_MANAGER}" == "pip3" ]]; then
150189
install_torch
151190
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
152191
uv sync --extra="${BUILD_SUFFIX}"
153192
fi
154-
155-
for model in detectron2 jde yolox mmpose segment_anything; do
156-
if [[ "${MODEL,,}" == *"${model}"* ]] || [[ " ${MODEL,,} " == *" all "* ]]; then
193+
194+
for model in "${VISION_MODELS[@]}"; do
195+
if [[ " ${MODEL,,} " == *" ${model} "* ]] || [[ "${MODEL,,}" == "all" ]]; then
157196
"install_${model}"
158197
fi
159198
done
@@ -211,12 +250,8 @@ detect_cuda_version () {
211250
}
212251

213252
install_torch () {
214-
if [ "${CPU}" == "True" ]; then
215-
"${PIP[@]}" install "torch==${TORCH_VERSION}" "torchvision==${TORCHVISION_VERSION}" --index-url "https://download.pytorch.org/whl/${BUILD_SUFFIX}"
216-
else
217-
# TODO(refactor): If we use --index-url instead, the "+${BUILD_SUFFIX}" does not need to be explicitly specified.
218-
"${PIP[@]}" install "torch==${TORCH_VERSION}+${BUILD_SUFFIX}" "torchvision==${TORCHVISION_VERSION}+${BUILD_SUFFIX}" --extra-index-url "https://download.pytorch.org/whl/${BUILD_SUFFIX}"
219-
fi
253+
"${PIP[@]}" install "torch==${TORCH_VERSION}" "torchvision==${TORCHVISION_VERSION}" --index-url "https://download.pytorch.org/whl/${BUILD_SUFFIX}"
254+
220255
}
221256

222257
prepare_detectron2 () {
@@ -232,9 +267,10 @@ prepare_detectron2 () {
232267

233268
git clone --single-branch --branch main https://github.com/facebookresearch/detectron2.git "${MODELS_SOURCE_DIR}/detectron2"
234269
cd "${MODELS_SOURCE_DIR}/detectron2"
235-
git -c advice.detachedHead=false checkout 175b2453c2bc4227b8039118c01494ee75b08136
236-
git apply "${SCRIPT_DIR}/patches/0001-detectron2-fpn-bottom-up-separate.patch" || echo "Patch 0001 could not be applied. Possibly already applied."
237-
git apply "${SCRIPT_DIR}/patches/0002-detectron2-setup-defer-torch-import.patch" || echo "Patch 0002 could not be applied. Possibly already applied."
270+
if [[ "${FCM_CTTC}" == "True" ]]; then
271+
git -c advice.detachedHead=false checkout 175b2453c2bc4227b8039118c01494ee75b08136
272+
fi
273+
git apply "${SCRIPT_DIR}/install_utils/patches/0001-detectron2-fpn-bottom-up-separate.patch" || echo "Patch could not be applied. Possibly already applied."
238274
cd "${COMPRESSAI_VISION_ROOT_DIR}"
239275
}
240276

@@ -244,12 +280,14 @@ install_detectron2 () {
244280
echo
245281

246282
cd "${MODELS_SOURCE_DIR}/detectron2"
247-
rm -rf build/ **/*.so
248-
249-
# Install build dependencies first for detectron2
250-
"${PIP[@]}" install setuptools wheel
251-
"${PIP[@]}" install -e . --no-build-isolation
283+
cp ${SCRIPT_DIR}/install_utils/detectron2_pyproject.toml ./pyproject.toml
252284

285+
if [[ "${PACKAGE_MANAGER}" == "pip3" ]]; then
286+
"${PIP[@]}" install --no-build-isolation -e .
287+
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
288+
cd "${COMPRESSAI_VISION_ROOT_DIR}"
289+
uv sync --inexact --group=models-detectron2
290+
fi
253291

254292
cd "${COMPRESSAI_VISION_ROOT_DIR}"
255293
}
@@ -259,7 +297,7 @@ prepare_cython_bbox () {
259297
echo "Preparing cython_bbox for installation"
260298
echo
261299

262-
if [ -n "$(ls -A "${SCRIPT_DIR}/cython_bbox")" ]; then
300+
if [ -d "${SCRIPT_DIR}/cython_bbox" ] && [ -n "$(ls -A "${SCRIPT_DIR}/cython_bbox")" ]; then
263301
echo "Source directory already exists: ${SCRIPT_DIR}/cython_bbox"
264302
return
265303
fi
@@ -268,7 +306,7 @@ prepare_cython_bbox () {
268306
cd "${SCRIPT_DIR}/cython_bbox"
269307
# cython-bbox 0.1.3
270308
git checkout 9badb346a9222c98f828ba45c63fe3b7f2790ea2
271-
git apply "${SCRIPT_DIR}/patches/0001-cython_bbox-compatible-with-numpy-1.24.1.patch" || echo "Patch could not be applied. Possibly already applied."
309+
git apply "${SCRIPT_DIR}/install_utils/patches/0001-cython_bbox-compatible-with-numpy-1.24.1.patch" || echo "Patch could not be applied. Possibly already applied."
272310
cd "${COMPRESSAI_VISION_ROOT_DIR}"
273311
}
274312

@@ -284,8 +322,6 @@ install_cython_bbox() {
284322
"${PIP[@]}" install -e .
285323
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
286324
echo "cython-bbox is installed later during JDE installation."
287-
# "${PIP[@]}" install --no-build-isolation cython
288-
# "${PIP[@]}" install --no-build-isolation .
289325
fi
290326

291327
cd "${COMPRESSAI_VISION_ROOT_DIR}"
@@ -296,16 +332,16 @@ prepare_jde () {
296332
echo "Preparing JDE for installation"
297333
echo
298334

299-
if [ -n "$(ls -A "${MODELS_SOURCE_DIR}/Towards-Realtime-MOT")" ]; then
335+
if [ -d "${MODELS_SOURCE_DIR}/Towards-Realtime-MOT" ] && [ -n "$(ls -A "${MODELS_SOURCE_DIR}/Towards-Realtime-MOT")" ]; then
300336
echo "Source directory already exists: ${MODELS_SOURCE_DIR}/Towards-Realtime-MOT"
301337
return
302338
fi
303339

304340
git clone https://github.com/Zhongdao/Towards-Realtime-MOT.git "${MODELS_SOURCE_DIR}/Towards-Realtime-MOT"
305341
cd "${MODELS_SOURCE_DIR}/Towards-Realtime-MOT"
306342
git -c advice.detachedHead=false checkout c2654cdd7b69d39af669cff90758c04436025fe1
307-
git apply "${SCRIPT_DIR}/patches/0000-jde-package.patch" || echo "Patch could not be applied. Possibly already applied."
308-
git apply "${SCRIPT_DIR}/patches/0001-jde-interface-with-compressai-vision.patch" || echo "Patch could not be applied. Possibly already applied."
343+
git apply "${SCRIPT_DIR}/install_utils/patches/0000-jde-package.patch" || echo "Patch could not be applied. Possibly already applied."
344+
git apply "${SCRIPT_DIR}/install_utils/patches/0001-jde-interface-with-compressai-vision.patch" || echo "Patch could not be applied. Possibly already applied."
309345
cd "${COMPRESSAI_VISION_ROOT_DIR}"
310346
}
311347

@@ -334,7 +370,7 @@ prepare_yolox () {
334370
echo "Preparing YOLOX for installation"
335371
echo
336372

337-
if [ -n "$(ls -A "${MODELS_SOURCE_DIR}/yolox")" ]; then
373+
if [ -d "${MODELS_SOURCE_DIR}/yolox" ] && [ -n "$(ls -A "${MODELS_SOURCE_DIR}/yolox")" ]; then
338374
echo "Source directory already exists: ${MODELS_SOURCE_DIR}/yolox"
339375
return
340376
fi
@@ -354,8 +390,9 @@ install_yolox () {
354390

355391
if [[ "${PACKAGE_MANAGER}" == "pip3" ]]; then
356392
# miminum requirments - no onnx, etc.
357-
cp "${SCRIPT_DIR}/yolox_requirements.txt" requirements.txt
358-
"${PIP[@]}" install -e .
393+
cp "${SCRIPT_DIR}/install_utils/yolox_requirements.txt" requirements.txt
394+
cp ${SCRIPT_DIR}/install_utils/yolox_pyproject.toml ./pyproject.toml
395+
"${PIP[@]}" install --no-build-isolation -e .
359396
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
360397
cd "${COMPRESSAI_VISION_ROOT_DIR}"
361398
uv sync --inexact --group=models-yolox
@@ -369,7 +406,7 @@ prepare_mmpose () {
369406
echo "Preparing MMPOSE for installation"
370407
echo
371408

372-
if [ -n "$(ls -A "${MODELS_SOURCE_DIR}/mmpose")" ]; then
409+
if [ -d "${MODELS_SOURCE_DIR}/mmpose" ] && [ -n "$(ls -A "${MODELS_SOURCE_DIR}/mmpose")" ]; then
373410
echo "Source directory already exists: ${MODELS_SOURCE_DIR}/mmpose"
374411
return
375412
fi
@@ -411,7 +448,7 @@ prepare_segment_anything () {
411448
echo "Preparing Segment Anything for installation"
412449
echo
413450

414-
if [ -n "$(ls -A "${MODELS_SOURCE_DIR}/segment_anything")" ]; then
451+
if [ -d "${MODELS_SOURCE_DIR}/segment_anything" ] && [ -n "$(ls -A "${MODELS_SOURCE_DIR}/segment_anything")" ]; then
415452
echo "Source directory already exists: ${MODELS_SOURCE_DIR}/segment_anything"
416453
return
417454
fi
@@ -444,7 +481,7 @@ download_weights () {
444481
detect_env
445482
mkdir -p "${MODELS_WEIGHT_DIR}"
446483
cd "${MODELS_WEIGHT_DIR}/"
447-
484+
448485
for model in detectron2 jde mmpose yolox segment_anything; do
449486
if ! [[ ",${MODEL,,}," == *",${model},"* ]] && [[ ",${MODEL,,}," != *",all,"* ]]; then
450487
continue
@@ -456,7 +493,7 @@ download_weights () {
456493
echo "Downloading model weights for ${model}..."
457494
echo
458495

459-
FILTER="^[0-9a-fA-F]* ${model}/"
496+
FILTER="^[0-9a-fA-F]* ${model}/"
460497
FILTERED_WEIGHTS=$(echo "$WEIGHTS" | grep "${FILTER}")
461498

462499
echo "${FILTERED_WEIGHTS}" | while read -r entry; do
@@ -491,4 +528,4 @@ download_weights () {
491528

492529
if [[ "${__SOURCE_ONLY__:-0}" -eq 0 ]]; then
493530
main "$@"
494-
fi
531+
fi
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# pyproject.toml
2+
[build-system]
3+
requires = [
4+
"Pillow>=7.1",
5+
"matplotlib",
6+
"pycocotools>=2.0.2",
7+
"termcolor>=1.1",
8+
"yacs>=0.1.8",
9+
"tabulate",
10+
"cloudpickle",
11+
"tqdm>4.29.0",
12+
"tensorboard",
13+
"fvcore<0.1.6,>=0.1.5",
14+
"iopath<0.1.10,>=0.1.7",
15+
"omegaconf<2.4,>=2.1",
16+
"hydra-core>=1.1",
17+
"black",
18+
"packaging",
19+
"numpy",
20+
"pyyaml>=5.1",
21+
"portalocker",
22+
"antlr4-python3-runtime==4.9.*",
23+
"click>=7.1.2",
24+
"appdirs",
25+
"toml>=0.10.1",
26+
"regex>=2020.1.8",
27+
"pathspec<1,>=0.8.1",
28+
"mypy-extensions>=0.4.3",
29+
"contourpy>=1.0.1",
30+
"cycler>=0.10",
31+
"fonttools>=4.22.0",
32+
"kiwisolver>=1.3.1",
33+
"pyparsing>=2.3.1",
34+
"python-dateutil>=2.7",
35+
"six>=1.5",
36+
"absl-py>=0.4",
37+
"grpcio>=1.48.2",
38+
"markdown>=2.6.8",
39+
"protobuf!=4.24.0,>=3.19.6",
40+
"setuptools>=41.0.0",
41+
"tensorboard-data-server<0.8.0,>=0.7.0",
42+
"werkzeug>=1.0.1",
43+
"MarkupSafe>=2.1.1",
44+
]
45+
build-backend = "setuptools.build_meta"
File renamed without changes.

scripts/patches/0001-cython_bbox-compatible-with-numpy-1.24.1.patch renamed to scripts/install_utils/patches/0001-cython_bbox-compatible-with-numpy-1.24.1.patch

File renamed without changes.

scripts/patches/0001-detectron2-fpn-bottom-up-separate.patch renamed to scripts/install_utils/patches/0001-detectron2-fpn-bottom-up-separate.patch

File renamed without changes.

scripts/patches/0001-jde-interface-with-compressai-vision.patch renamed to scripts/install_utils/patches/0001-jde-interface-with-compressai-vision.patch

File renamed without changes.

scripts/patches/0002-detectron2-setup-defer-torch-import.patch renamed to scripts/install_utils/patches/0002-detectron2-setup-defer-torch-import.patch

File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# pyproject.toml
2+
[build-system]
3+
requires = [
4+
"numpy",
5+
"torch>=1.7",
6+
"opencv_python",
7+
"loguru",
8+
"tqdm",
9+
"thop",
10+
"ninja",
11+
"tabulate",
12+
"psutil",
13+
"pycocotools>=2.0.2",
14+
]

0 commit comments

Comments
 (0)