Skip to content

Commit 3d7b5d5

Browse files
authored
Merge branch 'main' into fix-shear-autoaugment
2 parents 6f865b8 + aecbb15 commit 3d7b5d5

File tree

26 files changed

+413
-86
lines changed

26 files changed

+413
-86
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.circleci/config.yml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ jobs:
351351
- install_torchvision
352352
- install_prototype_dependencies
353353
- pip_install:
354-
args: scipy pycocotools
354+
args: scipy pycocotools h5py
355355
descr: Install optional dependencies
356356
- run:
357357
name: Enable prototype tests

.github/process_commit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"module: video",
4444
"Perf",
4545
"Revert(ed)",
46+
"topic: build",
4647
}
4748

4849

docs/source/utils.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ vizualization <sphx_glr_auto_examples_plot_visualization_utils.py>`.
1515
draw_bounding_boxes
1616
draw_segmentation_masks
1717
draw_keypoints
18+
flow_to_image
1819
make_grid
1920
save_image

references/detection/coco_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def convert_to_coco_api(ds):
156156
img_dict["height"] = img.shape[-2]
157157
img_dict["width"] = img.shape[-1]
158158
dataset["images"].append(img_dict)
159-
bboxes = targets["boxes"]
159+
bboxes = targets["boxes"].clone()
160160
bboxes[:, 2:] -= bboxes[:, :2]
161161
bboxes = bboxes.tolist()
162162
labels = targets["labels"].tolist()

test/assets/expected_flow.pt

30 KB
Binary file not shown.

test/builtin_dataset_mocks.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import csv
33
import functools
44
import gzip
5+
import io
56
import itertools
67
import json
78
import lzma
@@ -1312,3 +1313,30 @@ def svhn(info, root, config):
13121313
},
13131314
)
13141315
return num_samples
1316+
1317+
1318+
@register_mock
1319+
def pcam(info, root, config):
1320+
import h5py
1321+
1322+
num_images = {"train": 2, "test": 3, "val": 4}[config.split]
1323+
1324+
split = "valid" if config.split == "val" else config.split
1325+
1326+
images_io = io.BytesIO()
1327+
with h5py.File(images_io, "w") as f:
1328+
f["x"] = np.random.randint(0, 256, size=(num_images, 10, 10, 3), dtype=np.uint8)
1329+
1330+
targets_io = io.BytesIO()
1331+
with h5py.File(targets_io, "w") as f:
1332+
f["y"] = np.random.randint(0, 2, size=(num_images, 1, 1, 1), dtype=np.uint8)
1333+
1334+
# Create .gz compressed files
1335+
images_file = root / f"camelyonpatch_level_2_split_{split}_x.h5.gz"
1336+
targets_file = root / f"camelyonpatch_level_2_split_{split}_y.h5.gz"
1337+
for compressed_file_name, uncompressed_file_io in ((images_file, images_io), (targets_file, targets_io)):
1338+
compressed_data = gzip.compress(uncompressed_file_io.getbuffer())
1339+
with open(compressed_file_name, "wb") as compressed_file:
1340+
compressed_file.write(compressed_data)
1341+
1342+
return num_images

test/test_models_detection_negative_samples.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ def test_forward_negative_sample_retinanet(self):
143143

144144
assert_equal(loss_dict["bbox_regression"], torch.tensor(0.0))
145145

146+
def test_forward_negative_sample_fcos(self):
147+
model = torchvision.models.detection.fcos_resnet50_fpn(
148+
num_classes=2, min_size=100, max_size=100, pretrained_backbone=False
149+
)
150+
151+
images, targets = self._make_empty_sample()
152+
loss_dict = model(images, targets)
153+
154+
assert_equal(loss_dict["bbox_regression"], torch.tensor(0.0))
155+
assert_equal(loss_dict["bbox_ctrness"], torch.tensor(0.0))
156+
146157
def test_forward_negative_sample_ssd(self):
147158
model = torchvision.models.detection.ssd300_vgg16(num_classes=2, pretrained_backbone=False)
148159

test/test_prototype_builtin_datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_home(mocker, tmp_path):
1818

1919

2020
def test_coverage():
21-
untested_datasets = set(datasets.list()) - DATASET_MOCKS.keys()
21+
untested_datasets = set(datasets.list_datasets()) - DATASET_MOCKS.keys()
2222
if untested_datasets:
2323
raise AssertionError(
2424
f"The dataset(s) {sequence_to_str(sorted(untested_datasets), separate_last='and ')} "

test/test_utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,5 +317,30 @@ def test_draw_keypoints_errors():
317317
utils.draw_keypoints(image=img, keypoints=invalid_keypoints)
318318

319319

320+
def test_flow_to_image():
321+
h, w = 100, 100
322+
flow = torch.meshgrid(torch.arange(h), torch.arange(w), indexing="ij")
323+
flow = torch.stack(flow[::-1], dim=0).float()
324+
flow[0] -= h / 2
325+
flow[1] -= w / 2
326+
img = utils.flow_to_image(flow)
327+
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "expected_flow.pt")
328+
expected_img = torch.load(path, map_location="cpu")
329+
assert_equal(expected_img, img)
330+
331+
332+
def test_flow_to_image_errors():
333+
wrong_flow1 = torch.full((3, 10, 10), 0, dtype=torch.float)
334+
wrong_flow2 = torch.full((2, 10), 0, dtype=torch.float)
335+
wrong_flow3 = torch.full((2, 10, 30), 0, dtype=torch.int)
336+
337+
with pytest.raises(ValueError, match="Input flow should have shape"):
338+
utils.flow_to_image(flow=wrong_flow1)
339+
with pytest.raises(ValueError, match="Input flow should have shape"):
340+
utils.flow_to_image(flow=wrong_flow2)
341+
with pytest.raises(ValueError, match="Flow should be of dtype torch.float"):
342+
utils.flow_to_image(flow=wrong_flow3)
343+
344+
320345
if __name__ == "__main__":
321346
pytest.main([__file__])

0 commit comments

Comments
 (0)