Skip to content

Commit

Permalink
[Fix] Fix UT to be compatible with pytorch 1.6 (#8707)
Browse files Browse the repository at this point in the history
* Update

* Update

* force reinstall pycocotools

* Fix build_cuda

* docker install git

* Update

* comment other job to speedup process

* update

* uncomment

* Update

* Update

* Add comments for --force-reinstall
  • Loading branch information
jbwang1997 authored and ZwwWayne committed Sep 26, 2022
1 parent a5bda9a commit 99ce362
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
14 changes: 9 additions & 5 deletions .circleci/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ jobs:
- run: pip install "protobuf <= 3.20.1" && sudo apt-get update && sudo apt-get -y install libprotobuf-dev protobuf-compiler cmake
- run:
name: Install mmdet dependencies
# numpy may be downgraded after building pycocotools, which causes `ImportError: numpy.core.multiarray failed to import`
# force reinstall pycocotools to ensure pycocotools being built under the currenct numpy
command: |
python -m pip install git+ssh://git@github.com/open-mmlab/mmengine.git@main
python -m pip install << parameters.mmcv >>
pip install -r requirements/tests.txt -r requirements/optional.txt
pip install --force-reinstall pycocotools
pip install albumentations>=0.3.2 --no-binary imgaug,albumentations
pip install git+https://github.com/cocodataset/panopticapi.git
- run:
Expand Down Expand Up @@ -111,17 +114,18 @@ jobs:
command: |
docker build .circleci/docker -t mmdetection:gpu --build-arg PYTORCH=<< parameters.torch >> --build-arg CUDA=<< parameters.cuda >> --build-arg CUDNN=<< parameters.cudnn >>
docker run --gpus all -t -d -v /home/circleci/project:/mmdetection -v /home/circleci/mmengine:/mmengine -w /mmdetection --name mmdetection mmdetection:gpu
docker exec mmdetection apt-get install -y git
- run:
name: Install mmdet dependencies
# pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch${{matrix.torch_version}}/index.html
command: |
docker exec mmdetection pip install -e /mmengine
docker exec mmdetection pip install << parameters.mmcv >>
pip install -r requirements/tests.txt -r requirements/optional.txt
pip install pycocotools
pip install albumentations>=0.3.2 --no-binary imgaug,albumentations
pip install git+https://github.com/cocodataset/panopticapi.git
python -c 'import mmcv; print(mmcv.__version__)'
docker exec mmdetection pip install -r requirements/tests.txt -r requirements/optional.txt
docker exec mmdetection pip install pycocotools
docker exec mmdetection pip install albumentations>=0.3.2 --no-binary imgaug,albumentations
docker exec mmdetection pip install git+https://github.com/cocodataset/panopticapi.git
docker exec mmdetection python -c 'import mmcv; print(mmcv.__version__)'
- run:
name: Build and install
command: |
Expand Down
2 changes: 1 addition & 1 deletion mmdet/datasets/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ def transform(self, results: dict) -> dict:
if patch[2] == patch[0] or patch[3] == patch[1]:
continue
overlaps = boxes.overlaps(
HorizontalBoxes(patch.reshape(-1, 4)),
HorizontalBoxes(patch.reshape(-1, 4).astype(np.float32)),
boxes).numpy().reshape(-1)
if len(overlaps) > 0 and overlaps.min() < min_iou:
continue
Expand Down
8 changes: 4 additions & 4 deletions tests/test_datasets/test_transforms/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ def setUp(self):

def test_transform(self):
transform = RandomErasing(
n_patches=(1, 5), ratio=(0.2, 0.5), img_border_value=0)
n_patches=(1, 5), ratio=(0.4, 0.8), img_border_value=0)
results = transform(copy.deepcopy(self.results))
self.assertTrue(results['img'].sum() < self.results['img'].sum())

Expand All @@ -1519,14 +1519,14 @@ def test_transform_with_boxlist(self):
src_results['gt_bboxes'] = HorizontalBoxes(src_results['gt_bboxes'])

transform = RandomErasing(
n_patches=(1, 5), ratio=(0.2, 0.5), img_border_value=0)
n_patches=(1, 5), ratio=(0.4, 0.8), img_border_value=0)
results = transform(copy.deepcopy(src_results))
self.assertTrue(results['img'].sum() < src_results['img'].sum())

transform = RandomErasing(
n_patches=1, ratio=0.999, img_border_value=255)
results = transform(copy.deepcopy(src_results))
self.assertTrue(results['img'].sum() > self.results['img'].sum())
self.assertTrue(results['img'].sum() > src_results['img'].sum())
# test empty results
empty_results = copy.deepcopy(src_results)
empty_results['gt_bboxes'] = HorizontalBoxes([], dtype=torch.float32)
Expand All @@ -1536,7 +1536,7 @@ def test_transform_with_boxlist(self):
empty_results['gt_seg_map'] = np.ones_like(
empty_results['gt_seg_map']) * 255
results = transform(copy.deepcopy(empty_results))
self.assertTrue(results['img'].sum() > self.results['img'].sum())
self.assertTrue(results['img'].sum() > src_results['img'].sum())

def test_repr(self):
transform = RandomErasing(n_patches=(1, 5), ratio=(0, 0.2))
Expand Down
10 changes: 5 additions & 5 deletions tests/test_engine/test_hooks/test_visualization_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
def _rand_bboxes(num_boxes, h, w):
cx, cy, bw, bh = torch.rand(num_boxes, 4).T

tl_x = ((cx * w) - (w * bw / 2)).clip(0, w)
tl_y = ((cy * h) - (h * bh / 2)).clip(0, h)
br_x = ((cx * w) + (w * bw / 2)).clip(0, w)
br_y = ((cy * h) + (h * bh / 2)).clip(0, h)
tl_x = ((cx * w) - (w * bw / 2)).clamp(0, w)
tl_y = ((cy * h) - (h * bh / 2)).clamp(0, h)
br_x = ((cx * w) + (w * bw / 2)).clamp(0, w)
br_y = ((cy * h) + (h * bh / 2)).clamp(0, h)

bboxes = torch.vstack([tl_x, tl_y, br_x, br_y]).T
bboxes = torch.stack([tl_x, tl_y, br_x, br_y], dim=0).T
return bboxes


Expand Down
2 changes: 1 addition & 1 deletion tests/test_visualization/test_local_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _rand_bboxes(num_boxes, h, w):
br_x = ((cx * w) + (w * bw / 2)).clamp(0, w)
br_y = ((cy * h) + (h * bh / 2)).clamp(0, h)

bboxes = torch.vstack([tl_x, tl_y, br_x, br_y]).T
bboxes = torch.stack([tl_x, tl_y, br_x, br_y], dim=0).T
return bboxes


Expand Down

0 comments on commit 99ce362

Please sign in to comment.