Skip to content

Commit 3e23333

Browse files
committed
Merge branch 'main' into revamp-prototype-features-transforms
2 parents 0e7cc3a + b94004a commit 3e23333

File tree

19 files changed

+318
-39
lines changed

19 files changed

+318
-39
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

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
@@ -1316,3 +1317,30 @@ def svhn(info, root, config):
13161317
},
13171318
)
13181319
return num_samples
1320+
1321+
1322+
@register_mock
1323+
def pcam(info, root, config):
1324+
import h5py
1325+
1326+
num_images = {"train": 2, "test": 3, "val": 4}[config.split]
1327+
1328+
split = "valid" if config.split == "val" else config.split
1329+
1330+
images_io = io.BytesIO()
1331+
with h5py.File(images_io, "w") as f:
1332+
f["x"] = np.random.randint(0, 256, size=(num_images, 10, 10, 3), dtype=np.uint8)
1333+
1334+
targets_io = io.BytesIO()
1335+
with h5py.File(targets_io, "w") as f:
1336+
f["y"] = np.random.randint(0, 2, size=(num_images, 1, 1, 1), dtype=np.uint8)
1337+
1338+
# Create .gz compressed files
1339+
images_file = root / f"camelyonpatch_level_2_split_{split}_x.h5.gz"
1340+
targets_file = root / f"camelyonpatch_level_2_split_{split}_y.h5.gz"
1341+
for compressed_file_name, uncompressed_file_io in ((images_file, images_io), (targets_file, targets_io)):
1342+
compressed_data = gzip.compress(uncompressed_file_io.getbuffer())
1343+
with open(compressed_file_name, "wb") as compressed_file:
1344+
compressed_file.write(compressed_data)
1345+
1346+
return num_images

test/test_prototype_builtin_datasets.py

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

2626

2727
def test_coverage():
28-
untested_datasets = set(datasets.list()) - DATASET_MOCKS.keys()
28+
untested_datasets = set(datasets.list_datasets()) - DATASET_MOCKS.keys()
2929
if untested_datasets:
3030
raise AssertionError(
3131
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__])

torchvision/csrc/io/decoder/gpu/demuxer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class Demuxer {
119119
" in demuxer.h\n");
120120
}
121121
}
122+
122123
~Demuxer() {
123124
if (!fmtCtx) {
124125
return;
@@ -223,7 +224,7 @@ class Demuxer {
223224
int64_t time = timestamp * AV_TIME_BASE;
224225
TORCH_CHECK(
225226
0 <= av_seek_frame(fmtCtx, -1, time, flag),
226-
"avformat_open_input() failed at line ",
227+
"av_seek_frame() failed at line ",
227228
__LINE__,
228229
" in demuxer.h\n");
229230
}

torchvision/prototype/datasets/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
from ._home import home
1212

1313
# Load this last, since some parts depend on the above being loaded first
14-
from ._api import register, _list as list, info, load, find # usort: skip
14+
from ._api import register, list_datasets, info, load, find # usort: skip
1515
from ._folder import from_data_folder, from_image_folder

0 commit comments

Comments
 (0)