Skip to content

Commit d54400a

Browse files
committed
fix: install mmpose in both cpu and gpu modes
1 parent 2224180 commit d54400a

File tree

5 files changed

+895
-99606
lines changed

5 files changed

+895
-99606
lines changed

.gitlab-ci.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ stages:
1717
- bash scripts/install_uv.sh --no-install --no-weights --cpu
1818

1919
uv-install:
20-
image: python:3.8-buster
20+
image: python:3.8-bullseye
2121
stage: setup
2222
script:
2323
- curl -LsSf https://astral.sh/uv/install.sh | sh
@@ -30,7 +30,7 @@ uv-install:
3030
- docker
3131
ruff-lint:
3232
stage: static-analysis
33-
image: python:3.8-buster
33+
image: python:3.8-bullseye
3434
before_script:
3535
- *default-before-script
3636
- uv pip install -U pip wheel setuptools
@@ -42,10 +42,15 @@ ruff-lint:
4242

4343
pytest:
4444
stage: test
45-
image: python:3.8-buster
45+
image: python:3.8-bullseye
4646
before_script:
47+
- apt-get update -y
48+
- apt-get install -y libgl1-mesa-glx build-essential
4749
- *default-before-script
4850
- uv pip install -U pip wheel setuptools
51+
- uv pip install torch==1.8.0+cpu torchvision==0.9.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
52+
- bash scripts/install_uv.sh --no-weights --cpu
53+
- uv pip install pycocotools "fvcore<0.1.6" "iopath<0.1.10" omegaconf "hydra-core" yacs PyYAML termcolor tabulate cloudpickle future pydot protobuf==3.20.0
4954
- uv sync --group=dev
5055
script:
5156
- uv run --no-sync pytest
@@ -54,7 +59,7 @@ pytest:
5459

5560
ruff-format:
5661
stage: static-analysis
57-
image: python:3.8-buster
62+
image: python:3.8-bullseye
5863
before_script:
5964
- *default-before-script
6065
- uv pip install -U pip wheel setuptools
@@ -66,7 +71,7 @@ ruff-format:
6671

6772
ruff-organize-imports:
6873
stage: static-analysis
69-
image: python:3.8-buster
74+
image: python:3.8-bullseye
7075
before_script:
7176
- *default-before-script
7277
- uv pip install -U pip wheel setuptools
@@ -78,7 +83,7 @@ ruff-organize-imports:
7883

7984
doc:
8085
stage: doc
81-
image: python:3.8-buster
86+
image: python:3.8-bullseye
8287
before_script:
8388
- *default-before-script
8489
- uv pip install -U pip wheel setuptools

pyproject.toml

Lines changed: 7 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,7 @@ cpu = [
7474
"torch>=2.0.0",
7575
"torchvision>=0.15.1",
7676
]
77-
cu118 = [
78-
"torch>=2.0.0",
79-
"torchvision>=0.15.1",
80-
]
81-
cu128 = [
82-
"torch>=2.7.0 ; python_version >= '3.9'",
83-
"torchvision>=0.22.0 ; python_version >= '3.9'",
84-
]
85-
models-detectron2 = [
86-
"detectron2==0.6",
87-
]
8877
models-jde = [
89-
"cython-bbox", # Encourages local cython-bbox source.
9078
"jde",
9179
]
9280
models-mmpose = [
@@ -129,11 +117,7 @@ tutorials = [
129117
"ipywidgets",
130118
"jupyter",
131119
]
132-
models-detectron2 = [
133-
"detectron2==0.6",
134-
]
135120
models-jde = [
136-
"cython-bbox", # Encourages local cython-bbox source.
137121
"jde",
138122
]
139123
models-mmpose = [
@@ -162,16 +146,8 @@ skip_gitignore = true
162146
known_third_party = "PIL,torchvision,torch"
163147

164148
[tool.uv]
165-
conflicts = [
166-
[
167-
{ extra = "cpu" },
168-
{ extra = "cu118" },
169-
{ extra = "cu128" },
170-
],
171-
]
172149
no-build-isolation-package = [
173150
"chumpy", # build-system.requires: pip
174-
"detectron2", # build-system.requires: Cython, numpy, setuptools
175151
"mmpose", # build-system.requires: numpy, torch
176152
"xtcocotools", # build-system.requires: Cython, numpy
177153
"yolox", # build-system.requires: pycocotools, torch, yolox, ...
@@ -187,29 +163,6 @@ requires-dist = [
187163
"six",
188164
]
189165

190-
[[tool.uv.dependency-metadata]]
191-
name = "detectron2"
192-
version = "0.6"
193-
requires-dist = [
194-
# From https://github.com/facebookresearch/detectron2/blob/main/setup.py
195-
"Pillow>=7.1",
196-
"matplotlib",
197-
"pycocotools>=2.0.2",
198-
"termcolor>=1.1",
199-
"yacs>=0.1.8",
200-
"tabulate",
201-
"cloudpickle",
202-
"tqdm>4.29.0",
203-
"tensorboard",
204-
"fvcore>=0.1.5,<0.1.6",
205-
"iopath>=0.1.7,<0.1.10",
206-
"future",
207-
"pydot",
208-
"dataclasses; python_version<'3.7'",
209-
"omegaconf>=2.1",
210-
"hydra-core>=1.1",
211-
# "black==21.4b2",
212-
]
213166

214167
[[tool.uv.dependency-metadata]]
215168
name = "mmpose"
@@ -273,34 +226,17 @@ name = "pytorch-cpu"
273226
url = "https://download.pytorch.org/whl/cpu"
274227
explicit = true
275228

276-
[[tool.uv.index]]
277-
name = "pytorch-cu118"
278-
url = "https://download.pytorch.org/whl/cu118"
279-
explicit = true
229+
[tool.uv.overrides]
230+
jde = { path = "models/Towards-Realtime-MOT" }
231+
yolox = { path = "models/yolox" }
232+
segment_anything = { path = "models/segment_anything" }
280233

281-
[[tool.uv.index]]
282-
name = "pytorch-cu128"
283-
url = "https://download.pytorch.org/whl/cu128"
284-
explicit = true
234+
torch = { index = "pytorch-cpu" }
235+
torchvision = { index = "pytorch-cpu" }
285236

286237
[tool.uv.sources]
287238
compressai = { workspace = true }
288-
cython-bbox = { path = "scripts/cython_bbox" }
289-
detectron2 = { path = "models/detectron2" }
290-
jde = { path = "models/Towards-Realtime-MOT" }
291-
mmpose = { path = "models/mmpose" }
292-
yolox = { path = "models/yolox" }
293-
segment_anything = { path = "models/segment_anything" }
294-
torch = [
295-
{ index = "pytorch-cpu", extra = "cpu" },
296-
{ index = "pytorch-cu118", extra = "cu118" },
297-
{ index = "pytorch-cu128", extra = "cu128" },
298-
]
299-
torchvision = [
300-
{ index = "pytorch-cpu", extra = "cpu" },
301-
{ index = "pytorch-cu118", extra = "cu118" },
302-
{ index = "pytorch-cu128", extra = "cu128" },
303-
]
239+
304240

305241
[tool.uv.workspace]
306242
members = [

scripts/install.sh

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,16 @@ $ python3 -m venv venv
3333
$ source venv/bin/activate
3434
3535
RUN OPTIONS:
36-
[-m|--model, vision models to install, (detectron2/jde/yolox/mmpose/segment-anything/all) default=all]
36+
[-m|--model, vision models to install, (jde/yolox/mmpose/segment-anything/all) default=all]
3737
[-t|--torch torch version, default="2.0.0"]
3838
[--torchvision torchvision version, default="0.15.1"]
3939
[--cpu) build for cpu only)]
4040
[--cuda_version) provide cuda version e.g. "11.8", default: check nvcc output)]
41-
[--detectron2_url use this if you want to specify a pre-built detectron2 (find at
42-
"https://detectron2.readthedocs.io/en/latest/tutorials/install.html#install-pre-built-detectron2-linux-only"),
43-
not required for regular versions derived from cuda and torch versions above.
44-
default:"https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html"]
4541
[--models_dir directory to install vision models to, default: compressai_vision_root]
4642
[--no-install) do not install (i.e. useful for only preparing source code by downloading and patching
4743
[--no-weights) prevents the installation script from downloading vision model parameters]
4844
4945
50-
EXAMPLE [bash install.sh -m detectron2 -t "1.9.1" --cuda_version "11.8" --compressai /path/to/compressai]
5146
5247
_EOF_
5348
exit;
@@ -67,11 +62,6 @@ done;
6762

6863

6964
WEIGHTS="
70-
3c25caca37baabbff3e22cc9eb0923db165a0c18b867871a3bf3570bac9b7ef0 detectron2/COCO-Detection/faster_rcnn_R_50_FPN_3x/137849458/model_final_280758.pkl https://dl.fbaipublicfiles.com/detectron2/COCO-Detection/faster_rcnn_R_50_FPN_3x/137849458/model_final_280758.pkl
71-
fe5ad56ff746aa55c5f453b01f8395134e9281d240dbeb473411d4a6b262c9dc detectron2/COCO-Detection/faster_rcnn_X_101_32x8d_FPN_3x/139173657/model_final_68b088.pkl https://dl.fbaipublicfiles.com/detectron2/COCO-Detection/faster_rcnn_X_101_32x8d_FPN_3x/139173657/model_final_68b088.pkl
72-
9a737e290372f1f70994ebcbd89d8004dbb3ae30a605fd915a190fa4a782dd66 detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl
73-
12f6e1811baf1b4d329c3f5ac5ec52d8f634d3cedc82a13fff55d0c05d84f442 detectron2/COCO-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_3x/139653917/model_final_2d9806.pkl https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_3x/139653917/model_final_2d9806.pkl
74-
808c675e647298688589c895c9581f7f3963995c5708bc53f66449200321d147 detectron2/COCO-PanopticSegmentation/panoptic_fpn_R_101_3x/139514519/model_final_cafdb1.pkl https://dl.fbaipublicfiles.com/detectron2/COCO-PanopticSegmentation/panoptic_fpn_R_101_3x/139514519/model_final_cafdb1.pkl
7565
6b135b0affa38899b607010c86c2f8dbc1c06956bad9ca1edd45b01e626933f1 jde/jde.1088x608.uncertainty.pt https://drive.usercontent.google.com/download?export=download&confirm=t&id=1nlnuYfGNuHWZztQHXwVZSL_FvfE551pA
7666
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
7767
b5905e9faf500a2608c93991f91a41a6150bcd2dd30986865a73becd94542fa1 yolox/darknet53/yolox_darknet.pth https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_darknet.pth
@@ -181,8 +171,7 @@ run_install () {
181171
if [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
182172
echo
183173
echo "Detect differences from uv.lock:"
184-
echo "uv sync --inexact --extra=${BUILD_SUFFIX} --dry-run"
185-
uv sync --inexact --extra="${BUILD_SUFFIX}" --dry-run
174+
echo "uv sync --inexact --extra=${BUILD_SUFFIX}"
186175
uv sync --inexact --extra="${BUILD_SUFFIX}"
187176
fi
188177
}
@@ -205,15 +194,6 @@ detect_cuda_version () {
205194
echo "Detected CUDA version: ${CUDA_VERSION}"
206195
}
207196

208-
install_torch () {
209-
if [ "${CPU}" == "True" ]; then
210-
"${PIP[@]}" install "torch==${TORCH_VERSION}" "torchvision==${TORCHVISION_VERSION}" --index-url "https://download.pytorch.org/whl/${BUILD_SUFFIX}"
211-
else
212-
# TODO(refactor): If we use --index-url instead, the "+${BUILD_SUFFIX}" does not need to be explicitly specified.
213-
"${PIP[@]}" install "torch==${TORCH_VERSION}+${BUILD_SUFFIX}" "torchvision==${TORCHVISION_VERSION}+${BUILD_SUFFIX}" --extra-index-url "https://download.pytorch.org/whl/${BUILD_SUFFIX}"
214-
fi
215-
}
216-
217197
prepare_detectron2 () {
218198
echo
219199
echo "Preparing detectron2 for installation"
@@ -226,28 +206,37 @@ prepare_detectron2 () {
226206

227207
git clone --single-branch --branch main https://github.com/facebookresearch/detectron2.git "${MODELS_SOURCE_DIR}/detectron2"
228208
cd "${MODELS_SOURCE_DIR}/detectron2"
229-
git -c advice.detachedHead=false checkout 175b2453c2bc4227b8039118c01494ee75b08136
209+
git -c advice.detachedHead=false checkout c554533136231a94971a995185501539f5c808f9
230210
git apply "${SCRIPT_DIR}/patches/0001-detectron2-fpn-bottom-up-separate.patch" || echo "Patch could not be applied. Possibly already applied."
231211
cd "${COMPRESSAI_VISION_ROOT_DIR}"
232212
}
233213

234214
install_detectron2 () {
235215
echo
236-
echo "Installing detectron2"
216+
echo "Installing detectron2 (reference: https://github.com/facebookresearch/detectron2)"
237217
echo
238218

239219
cd "${MODELS_SOURCE_DIR}/detectron2"
240220

241221
if [[ "${PACKAGE_MANAGER}" == "pip3" ]]; then
242222
"${PIP[@]}" install -e .
243223
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
244-
cd "${COMPRESSAI_VISION_ROOT_DIR}"
245-
uv sync --inexact --group=models-detectron2
224+
"${PIP[@]}" install -e .
246225
fi
247226

248227
cd "${COMPRESSAI_VISION_ROOT_DIR}"
249228
}
250229

230+
install_torch () {
231+
if [ "${CPU}" == "True" ]; then
232+
"${PIP[@]}" install "torch==${TORCH_VERSION}" "torchvision==${TORCHVISION_VERSION}" --index-url "https://download.pytorch.org/whl/${BUILD_SUFFIX}"
233+
else
234+
# TODO(refactor): If we use --index-url instead, the "+${BUILD_SUFFIX}" does not need to be explicitly specified.
235+
"${PIP[@]}" install "torch==${TORCH_VERSION}+${BUILD_SUFFIX}" "torchvision==${TORCHVISION_VERSION}+${BUILD_SUFFIX}" --extra-index-url "https://download.pytorch.org/whl/${BUILD_SUFFIX}"
236+
fi
237+
}
238+
239+
251240
prepare_cython_bbox () {
252241
echo
253242
echo "Preparing cython_bbox for installation"
@@ -339,6 +328,15 @@ prepare_yolox () {
339328
cd "${COMPRESSAI_VISION_ROOT_DIR}"
340329
}
341330

331+
install_mmcv () {
332+
echo
333+
echo "Installing mmcv"
334+
echo
335+
local torch_version_url_part="torch${TORCH_VERSION%.*}"
336+
local find_links_url="https://download.openmmlab.com/mmcv/dist/${BUILD_SUFFIX}/${torch_version_url_part}/index.html"
337+
"${PIP[@]}" install "mmcv==2.0.1" --find-links "${find_links_url}"
338+
}
339+
342340
install_yolox () {
343341
echo
344342
echo "Installing YOLOX (reference: https://github.com/Megvii-BaseDetection/YOLOX)"
@@ -375,6 +373,7 @@ prepare_mmpose () {
375373
}
376374

377375
install_mmpose () {
376+
378377
echo
379378
echo "Installing MMPOSE (reference: https://github.com/open-mmlab/mmpose/tree/main)"
380379
echo
@@ -394,7 +393,8 @@ install_mmpose () {
394393
uv sync --inexact --group=models-mmpose
395394
fi
396395

397-
"${MIM[@]}" install "mmcv==2.0.1"
396+
install_mmcv
397+
398398
"${MIM[@]}" install "mmdet==3.1.0"
399399

400400
cd "${COMPRESSAI_VISION_ROOT_DIR}"
@@ -439,7 +439,7 @@ download_weights () {
439439
mkdir -p "${MODELS_WEIGHT_DIR}"
440440
cd "${MODELS_WEIGHT_DIR}/"
441441

442-
for model in detectron2 jde mmpose yolox segment_anything; do
442+
for model in jde mmpose yolox segment_anything; do
443443
if ! [[ ",${MODEL,,}," == *",${model},"* ]] && [[ ",${MODEL,,}," != *",all,"* ]]; then
444444
continue
445445
fi

tests/evaluators/test_evaluators.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,36 @@
3636

3737
from compressai_vision.evaluators import COCOEVal
3838

39+
3940
def mock_coco_api(annotation_file):
4041
# Create a mock COCO API object
4142
coco_api = MagicMock()
42-
coco_api.anns = {1: {'image_id': 1, 'category_id': 1, 'bbox': [10, 10, 50, 50]}}
43+
coco_api.anns = {1: {"image_id": 1, "category_id": 1, "bbox": [10, 10, 50, 50]}}
4344
return coco_api
4445

46+
4547
@pytest.fixture
4648
def mock_dataset():
4749
dataset = MagicMock()
4850
dataset.dataset_name = "mock_coco_dataset"
4951
dataset.annotation_path = "mock_annotations.json"
50-
with open(dataset.annotation_path, 'w') as f:
51-
json.dump({
52-
'images': [{'id': 1, 'width': 640, 'height': 480}],
53-
'annotations': [{'id': 1, 'image_id': 1, 'category_id': 1, 'bbox': [10, 10, 50, 50]}],
54-
'categories': [{'id': 1, 'name': 'person'}]
55-
}, f)
52+
with open(dataset.annotation_path, "w") as f:
53+
json.dump(
54+
{
55+
"images": [{"id": 1, "width": 640, "height": 480}],
56+
"annotations": [
57+
{"id": 1, "image_id": 1, "category_id": 1, "bbox": [10, 10, 50, 50]}
58+
],
59+
"categories": [{"id": 1, "name": "person"}],
60+
},
61+
f,
62+
)
5663
yield dataset
5764
os.remove(dataset.annotation_path)
5865

59-
@patch('detectron2.evaluation.COCOEvaluator', autospec=True)
60-
@patch('compressai_vision.evaluators.evaluators.deccode_compressed_rle')
66+
67+
@patch("detectron2.evaluation.COCOEvaluator", autospec=True)
68+
@patch("compressai_vision.evaluators.evaluators.deccode_compressed_rle")
6169
def test_coco_eval(mock_deccode, mock_evaluator, mock_dataset):
6270
# Configure the mock to have the expected attributes
6371
mock_coco_api_obj = MagicMock()
@@ -70,11 +78,13 @@ def test_coco_eval(mock_deccode, mock_evaluator, mock_dataset):
7078
datacatalog_name="MPEGOIV6",
7179
dataset_name="mock_coco_dataset",
7280
dataset=mock_dataset,
73-
output_dir="./test_output"
81+
output_dir="./test_output",
7482
)
7583

76-
gt = [{'image_id': 1, 'width': 640, 'height': 480, 'image': torch.zeros(3, 480, 640)}]
77-
pred = [{'instances': MagicMock()}]
84+
gt = [
85+
{"image_id": 1, "width": 640, "height": 480, "image": torch.zeros(3, 480, 640)}
86+
]
87+
pred = [{"instances": MagicMock()}]
7888

7989
evaluator.digest(gt, pred)
8090
mock_evaluator.return_value.process.assert_called_once_with(gt, pred)

0 commit comments

Comments
 (0)