Skip to content

Commit 2106ed1

Browse files
ppwwyyxxfacebook-github-bot
authored andcommitted
download mini data in OSS CI, and enable more tests
Summary: Pull Request resolved: #3689 Differential Revision: D32410043 Pulled By: ppwwyyxx fbshipit-source-id: 6e75bddfb6899a9a294a3f2d927cdf806db54120
1 parent 3fd63b2 commit 2106ed1

File tree

11 files changed

+56
-36
lines changed

11 files changed

+56
-36
lines changed

.circleci/config.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ version_parameters: &version_parameters
4545
TORCHVISION_VERSION: << parameters.torchvision_version >>
4646
PYTORCH_INDEX: << parameters.pytorch_index >>
4747
PYTHON_VERSION: << parameters.python_version>>
48+
# point datasets to ~/.torch so it's cached in CI
49+
DETECTRON2_DATASETS: ~/.torch/datasets
4850

4951
# -------------------------------------------------------------------------------------
5052
# Re-usable commands
@@ -105,10 +107,13 @@ install_linux_dep: &install_linux_dep
105107
- run:
106108
name: Install Dependencies
107109
command: |
110+
# disable crash coredump, so unittests fail fast
111+
sudo systemctl stop apport.service
108112
# install from github to get latest; install iopath first since fvcore depends on it
109113
pip install --progress-bar off -U 'git+https://github.com/facebookresearch/iopath'
110114
pip install --progress-bar off -U 'git+https://github.com/facebookresearch/fvcore'
111-
pip install --progress-bar off ninja opencv-python-headless pytest-xdist tensorboard pycocotools
115+
# Don't use pytest-xdist: cuda tests are unstable under multi-process workers.
116+
pip install --progress-bar off ninja opencv-python-headless pytest tensorboard pycocotools
112117
pip install --progress-bar off torch==$PYTORCH_VERSION -f $PYTORCH_INDEX
113118
if [[ "$TORCHVISION_VERSION" == "master" ]]; then
114119
pip install git+https://github.com/pytorch/vision.git
@@ -123,16 +128,17 @@ install_detectron2: &install_detectron2
123128
- run:
124129
name: Install Detectron2
125130
command: |
126-
# Remove if it's in cache
131+
# Remove first, in case it's in the CI cache
127132
pip uninstall -y detectron2
128133
pip install --progress-bar off -e .[all]
129134
python -m detectron2.utils.collect_env
135+
./datasets/prepare_for_tests.sh
130136
131137
run_unittests: &run_unittests
132138
- run:
133139
name: Run Unit Tests
134140
command: |
135-
pytest -n 1 -v --durations=15 tests # parallel causes some random failures
141+
pytest -v --durations=15 tests # parallel causes some random failures
136142
137143
# -------------------------------------------------------------------------------------
138144
# Jobs to run

.github/workflows/workflow.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ jobs:
4545
torchvision: "0.10"
4646
- torch: "1.10"
4747
torchvision: "0.11.1"
48+
env:
49+
# point datasets to ~/.torch so it's cached by CI
50+
DETECTRON2_DATASETS: ~/.torch/datasets
4851
steps:
4952
- name: Checkout
5053
uses: actions/checkout@v2
@@ -73,5 +76,6 @@ jobs:
7376
run: |
7477
CC=clang CXX=clang++ python -m pip install -e .[all]
7578
python -m detectron2.utils.collect_env
79+
./datasets/prepare_for_tests.sh
7680
- name: Run unittests
77-
run: python -m pytest -n 4 -v tests/
81+
run: python -m pytest -n 4 --durations=15 -v tests/

datasets/prepare_for_tests.sh

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
#!/bin/bash -e
22
# Copyright (c) Facebook, Inc. and its affiliates.
33

4-
# Download some files needed for running tests.
4+
# Download the mini dataset (coco val2017_100, with only 100 images)
5+
# to be used in unittests & integration tests.
56

67
cd "${0%/*}"
78

89
BASE=https://dl.fbaipublicfiles.com/detectron2
9-
mkdir -p coco/annotations
10+
ROOT=${DETECTRON2_DATASETS:-./}
11+
ROOT=${ROOT/#\~/$HOME} # expand ~ to HOME
12+
mkdir -p $ROOT/coco/annotations
1013

1114
for anno in instances_val2017_100 \
12-
person_keypoints_val2017_100 \
13-
instances_minival2014_100 \
14-
person_keypoints_minival2014_100; do
15+
person_keypoints_val2017_100 ; do
1516

16-
dest=coco/annotations/$anno.json
17+
dest=$ROOT/coco/annotations/$anno.json
1718
[[ -s $dest ]] && {
1819
echo "$dest exists. Skipping ..."
1920
} || {
2021
wget $BASE/annotations/coco/$anno.json -O $dest
2122
}
2223
done
24+
25+
dest=$ROOT/coco/val2017_100.tgz
26+
[[ -d $ROOT/coco/val2017 ]] && {
27+
echo "$ROOT/coco/val2017 exists. Skipping ..."
28+
} || {
29+
wget $BASE/annotations/coco/val2017_100.tgz -O $dest
30+
tar xzf $dest -C $ROOT/coco/ && rm -f $dest
31+
}

detectron2/data/datasets/builtin.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"coco_2014_train": ("coco/train2014", "coco/annotations/instances_train2014.json"),
3737
"coco_2014_val": ("coco/val2014", "coco/annotations/instances_val2014.json"),
3838
"coco_2014_minival": ("coco/val2014", "coco/annotations/instances_minival2014.json"),
39-
"coco_2014_minival_100": ("coco/val2014", "coco/annotations/instances_minival2014_100.json"),
4039
"coco_2014_valminusminival": (
4140
"coco/val2014",
4241
"coco/annotations/instances_valminusminival2014.json",
@@ -62,10 +61,6 @@
6261
"coco/val2014",
6362
"coco/annotations/person_keypoints_valminusminival2014.json",
6463
),
65-
"keypoints_coco_2014_minival_100": (
66-
"coco/val2014",
67-
"coco/annotations/person_keypoints_minival2014_100.json",
68-
),
6964
"keypoints_coco_2017_train": (
7065
"coco/train2017",
7166
"coco/annotations/person_keypoints_train2017.json",
@@ -255,7 +250,7 @@ def register_all_ade20k(root):
255250
# Internally at fb, we register them elsewhere
256251
if __name__.endswith(".builtin"):
257252
# Assume pre-defined datasets live in `./datasets`.
258-
_root = os.getenv("DETECTRON2_DATASETS", "datasets")
253+
_root = os.path.expanduser(os.getenv("DETECTRON2_DATASETS", "datasets"))
259254
register_all_coco(_root)
260255
register_all_lvis(_root)
261256
register_all_cityscapes(_root)

detectron2/utils/testing.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def get_sample_coco_image(tensor=True):
5555
raise FileNotFoundError()
5656
except IOError:
5757
# for public CI to run
58-
file_name = "http://images.cocodataset.org/train2017/000000000009.jpg"
58+
file_name = PathManager.get_local_path(
59+
"http://images.cocodataset.org/train2017/000000000009.jpg"
60+
)
5961
ret = read_image(file_name, format="BGR")
6062
if tensor:
6163
ret = torch.from_numpy(np.ascontiguousarray(ret.transpose(2, 0, 1)))

projects/DensePose/setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
try:
66
import torch # noqa: F401
7-
except ImportError:
7+
except ImportError as e:
88
raise Exception(
99
"""
1010
You must install PyTorch prior to installing DensePose:
@@ -13,7 +13,7 @@
1313
For more information:
1414
https://pytorch.org/get-started/locally/
1515
"""
16-
)
16+
) from e
1717

1818

1919
def get_detectron2_current_version():

tests/data/test_coco_evaluation.py

-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ def test_fast_eval(self):
123123
msg = "%s: comparing COCO APIs, %s differs by %f" % (name, k, abs_diff)
124124
self.assertTrue(abs_diff < 1e-4, msg=msg)
125125

126-
@unittest.skipIf(os.environ.get("CI"), "Require COCO data.")
127126
def test_unknown_category(self):
128127
dataset = "coco_2017_val_100"
129128
evaluator = COCOEvaluator(dataset)

tests/data/test_dataset.py

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def test_pickleability(self):
7373
self.assertEqual(ds[0], 2)
7474

7575

76-
@unittest.skipIf(os.environ.get("CI"), "Skipped OSS testing due to COCO data requirement.")
7776
class TestDataLoader(unittest.TestCase):
7877
def _get_kwargs(self):
7978
# get kwargs of build_detection_train_loader

tests/test_engine.py

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def test_writer_hooks(self):
8484

8585
self.assertIn("eta: 0:00:00", logs.output[-1], "Last ETA must be 0!")
8686

87-
@unittest.skipIf(os.environ.get("CI"), "Require COCO data.")
8887
def test_default_trainer(self):
8988
# TODO: this test requires manifold access, so changed device to CPU. see: T88318502
9089
cfg = get_cfg()

tests/test_export_caffe2.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
import torch
99

1010
from detectron2 import model_zoo
11+
from detectron2.export import Caffe2Model, Caffe2Tracer, add_export_config
1112
from detectron2.utils.logger import setup_logger
1213
from detectron2.utils.testing import get_sample_coco_image
1314

1415

15-
@unittest.skipIf(os.environ.get("CI"), "Require COCO data and model zoo.")
16+
# TODO: this test requires manifold access, see: T88318502
17+
# Running it on CircleCI causes crash, not sure why.
18+
@unittest.skipIf(os.environ.get("CIRCLECI"), "Caffe2 tests crash on CircleCI.")
1619
class TestCaffe2Export(unittest.TestCase):
1720
def setUp(self):
1821
setup_logger()
1922

2023
def _test_model(self, config_path, device="cpu"):
21-
# requires extra dependencies
22-
from detectron2.export import Caffe2Model, add_export_config, Caffe2Tracer
23-
2424
cfg = model_zoo.get_config(config_path)
2525
add_export_config(cfg)
2626
cfg.MODEL.DEVICE = device
@@ -29,27 +29,25 @@ def _test_model(self, config_path, device="cpu"):
2929
inputs = [{"image": get_sample_coco_image()}]
3030
tracer = Caffe2Tracer(cfg, model, copy.deepcopy(inputs))
3131

32-
c2_model = tracer.export_caffe2()
33-
3432
with tempfile.TemporaryDirectory(prefix="detectron2_unittest") as d:
35-
c2_model.save_protobuf(d)
36-
c2_model.save_graph(os.path.join(d, "test.svg"), inputs=copy.deepcopy(inputs))
33+
if not os.environ.get("CI"):
34+
# This requires onnx, which is not yet available on public CI
35+
c2_model = tracer.export_caffe2()
36+
c2_model.save_protobuf(d)
37+
c2_model.save_graph(os.path.join(d, "test.svg"), inputs=copy.deepcopy(inputs))
3738

38-
c2_model = Caffe2Model.load_protobuf(d)
39-
c2_model(inputs)[0]["instances"]
39+
c2_model = Caffe2Model.load_protobuf(d)
40+
c2_model(inputs)[0]["instances"]
4041

4142
ts_model = tracer.export_torchscript()
4243
ts_model.save(os.path.join(d, "model.ts"))
4344

4445
def testMaskRCNN(self):
45-
# TODO: this test requires manifold access, see: T88318502
4646
self._test_model("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
4747

4848
@unittest.skipIf(not torch.cuda.is_available(), "CUDA not available")
4949
def testMaskRCNNGPU(self):
50-
# TODO: this test requires manifold access, see: T88318502
5150
self._test_model("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml", device="cuda")
5251

5352
def testRetinaNet(self):
54-
# TODO: this test requires manifold access, see: T88318502
5553
self._test_model("COCO-Detection/retinanet_R_50_FPN_3x.yaml")

tests/test_export_torchscript.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,30 @@
1818
from detectron2.modeling.postprocessing import detector_postprocess
1919
from detectron2.modeling.roi_heads import KRCNNConvDeconvUpsampleHead
2020
from detectron2.structures import Boxes, Instances
21+
from detectron2.utils.env import TORCH_VERSION
2122
from detectron2.utils.testing import (
2223
assert_instances_allclose,
2324
convert_scripted_instances,
2425
get_sample_coco_image,
2526
random_boxes,
2627
)
2728

28-
2929
"""
3030
https://detectron2.readthedocs.io/tutorials/deployment.html
3131
contains some explanations of this file.
3232
"""
3333

34+
SLOW_PUBLIC_CPU_TEST = unittest.skipIf(
35+
os.environ.get("CI") and not torch.cuda.is_available(),
36+
"The test is too slow on CPUs and will be executed on CircleCI's GPU jobs.",
37+
)
38+
3439

3540
class TestScripting(unittest.TestCase):
3641
def testMaskRCNNFPN(self):
3742
self._test_rcnn_model("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
3843

44+
@SLOW_PUBLIC_CPU_TEST
3945
def testMaskRCNNC4(self):
4046
self._test_rcnn_model("COCO-InstanceSegmentation/mask_rcnn_R_50_C4_3x.yaml")
4147

@@ -100,13 +106,16 @@ def inference_func(model, image):
100106

101107
self._test_model("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml", inference_func)
102108

109+
@SLOW_PUBLIC_CPU_TEST
103110
def testMaskRCNNC4(self):
104111
def inference_func(model, image):
105112
inputs = [{"image": image}]
106113
return model.inference(inputs, do_postprocess=False)[0]
107114

108115
self._test_model("COCO-InstanceSegmentation/mask_rcnn_R_50_C4_3x.yaml", inference_func)
109116

117+
# bug fixed by https://github.com/pytorch/pytorch/pull/67734
118+
@unittest.skipIf(TORCH_VERSION == (1, 10) and os.environ.get("CI"), "1.10 has bugs.")
110119
def testRetinaNet(self):
111120
def inference_func(model, image):
112121
return model.forward([{"image": image}])[0]["instances"]

0 commit comments

Comments
 (0)