Skip to content

Commit 9acf2f4

Browse files
committed
Merge branch 'main' into fix-hardcoded-255
2 parents 8713528 + d95fbaf commit 9acf2f4

20 files changed

+540
-243
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build Linux Conda
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- nightly
8+
workflow_dispatch:
9+
10+
jobs:
11+
generate-matrix:
12+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
13+
with:
14+
package-type: conda
15+
os: linux
16+
test-infra-repository: pytorch/test-infra
17+
test-infra-ref: main
18+
build:
19+
needs: generate-matrix
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
- repository: pytorch/vision
25+
pre-script: ""
26+
post-script: ""
27+
conda-package-directory: packaging/torchvision
28+
smoke-test-script: test/smoke_test.py
29+
package-name: torchvision
30+
name: ${{ matrix.repository }}
31+
uses: pytorch/test-infra/.github/workflows/build_conda_linux.yml@main
32+
with:
33+
conda-package-directory: ${{ matrix.conda-package-directory }}
34+
repository: ${{ matrix.repository }}
35+
ref: ""
36+
test-infra-repository: pytorch/test-infra
37+
test-infra-ref: main
38+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
39+
pre-script: ${{ matrix.pre-script }}
40+
post-script: ${{ matrix.post-script }}
41+
package-name: ${{ matrix.package-name }}
42+
smoke-test-script: ${{ matrix.smoke-test-script }}
43+
# Using "development" as trigger event so these binaries are not uploaded
44+
# to official channels yet
45+
trigger-event: development
46+
secrets:
47+
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build Linux Wheels
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- nightly
8+
workflow_dispatch:
9+
10+
jobs:
11+
generate-matrix:
12+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
13+
with:
14+
package-type: wheel
15+
os: linux
16+
test-infra-repository: pytorch/test-infra
17+
test-infra-ref: main
18+
build:
19+
needs: generate-matrix
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
- repository: pytorch/vision
25+
pre-script: ""
26+
post-script: ""
27+
smoke-test-script: test/smoke_test.py
28+
package-name: torchvision
29+
name: ${{ matrix.repository }}
30+
uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main
31+
with:
32+
repository: ${{ matrix.repository }}
33+
ref: ""
34+
test-infra-repository: pytorch/test-infra
35+
test-infra-ref: main
36+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
37+
pre-script: ${{ matrix.pre-script }}
38+
post-script: ${{ matrix.post-script }}
39+
package-name: ${{ matrix.package-name }}
40+
smoke-test-script: ${{ matrix.smoke-test-script }}
41+
# Using "development" as trigger event so these binaries are not uploaded
42+
# to official channels yet
43+
trigger-event: development
44+
secrets:
45+
AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID: ${{ secrets.AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID }}
46+
AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY: ${{ secrets.AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY }}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build Macos Wheels
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- nightly
8+
workflow_dispatch:
9+
10+
jobs:
11+
generate-matrix:
12+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
13+
with:
14+
package-type: wheel
15+
os: macos
16+
test-infra-repository: pytorch/test-infra
17+
test-infra-ref: main
18+
build:
19+
needs: generate-matrix
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
- repository: pytorch/vision
25+
pre-script: ""
26+
post-script: ""
27+
smoke-test-script: test/smoke_test.py
28+
package-name: torchvision
29+
name: ${{ matrix.repository }}
30+
uses: pytorch/test-infra/.github/workflows/build_wheels_macos.yml@main
31+
with:
32+
repository: ${{ matrix.repository }}
33+
ref: ""
34+
test-infra-repository: pytorch/test-infra
35+
test-infra-ref: main
36+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
37+
pre-script: ${{ matrix.pre-script }}
38+
post-script: ${{ matrix.post-script }}
39+
package-name: ${{ matrix.package-name }}
40+
runner-type: macos-12
41+
smoke-test-script: ${{ matrix.smoke-test-script }}
42+
# Using "development" as trigger event so these binaries are not uploaded
43+
# to official channels yet
44+
trigger-event: development
45+
secrets:
46+
AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID: ${{ secrets.AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID }}
47+
AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY: ${{ secrets.AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY }}

ios/LibTorchvision.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
pytorch_version = '1.12.0'
1+
pytorch_version = '1.13.0'
22

33
Pod::Spec.new do |s|
44
s.name = 'LibTorchvision'
5-
s.version = '0.13.0'
5+
s.version = '0.14.0'
66
s.authors = 'PyTorch Team'
77
s.license = { :type => 'BSD' }
88
s.homepage = 'https://github.com/pytorch/vision'

test/prototype_transforms_kernel_infos.py

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,29 @@ def sample_inputs_horizontal_flip_video():
145145
yield ArgsKwargs(video_loader)
146146

147147

148+
def reference_horizontal_flip_bounding_box(bounding_box, *, format, spatial_size):
149+
affine_matrix = np.array(
150+
[
151+
[-1, 0, spatial_size[1]],
152+
[0, 1, 0],
153+
],
154+
dtype="float32",
155+
)
156+
157+
expected_bboxes = reference_affine_bounding_box_helper(bounding_box, format=format, affine_matrix=affine_matrix)
158+
159+
return expected_bboxes
160+
161+
162+
def reference_inputs_flip_bounding_box():
163+
for bounding_box_loader in make_bounding_box_loaders(extra_dims=[()]):
164+
yield ArgsKwargs(
165+
bounding_box_loader,
166+
format=bounding_box_loader.format,
167+
spatial_size=bounding_box_loader.spatial_size,
168+
)
169+
170+
148171
KERNEL_INFOS.extend(
149172
[
150173
KernelInfo(
@@ -158,6 +181,8 @@ def sample_inputs_horizontal_flip_video():
158181
KernelInfo(
159182
F.horizontal_flip_bounding_box,
160183
sample_inputs_fn=sample_inputs_horizontal_flip_bounding_box,
184+
reference_fn=reference_horizontal_flip_bounding_box,
185+
reference_inputs_fn=reference_inputs_flip_bounding_box,
161186
),
162187
KernelInfo(
163188
F.horizontal_flip_mask,
@@ -409,15 +434,13 @@ def _compute_affine_matrix(angle, translate, scale, shear, center):
409434
return true_matrix
410435

411436

412-
def reference_affine_bounding_box(bounding_box, *, format, spatial_size, angle, translate, scale, shear, center=None):
413-
if center is None:
414-
center = [s * 0.5 for s in spatial_size[::-1]]
415-
416-
def transform(bbox):
417-
affine_matrix = _compute_affine_matrix(angle, translate, scale, shear, center)
418-
affine_matrix = affine_matrix[:2, :]
419-
420-
bbox_xyxy = F.convert_format_bounding_box(bbox, old_format=format, new_format=features.BoundingBoxFormat.XYXY)
437+
def reference_affine_bounding_box_helper(bounding_box, *, format, affine_matrix):
438+
def transform(bbox, affine_matrix_, format_):
439+
# Go to float before converting to prevent precision loss in case of CXCYWH -> XYXY and W or H is 1
440+
in_dtype = bbox.dtype
441+
bbox_xyxy = F.convert_format_bounding_box(
442+
bbox.float(), old_format=format_, new_format=features.BoundingBoxFormat.XYXY, inplace=True
443+
)
421444
points = np.array(
422445
[
423446
[bbox_xyxy[0].item(), bbox_xyxy[1].item(), 1.0],
@@ -426,22 +449,24 @@ def transform(bbox):
426449
[bbox_xyxy[2].item(), bbox_xyxy[3].item(), 1.0],
427450
]
428451
)
429-
transformed_points = np.matmul(points, affine_matrix.T)
452+
transformed_points = np.matmul(points, affine_matrix_.T)
430453
out_bbox = torch.tensor(
431454
[
432455
np.min(transformed_points[:, 0]).item(),
433456
np.min(transformed_points[:, 1]).item(),
434457
np.max(transformed_points[:, 0]).item(),
435458
np.max(transformed_points[:, 1]).item(),
436459
],
437-
dtype=bbox.dtype,
438460
)
439-
return F.convert_format_bounding_box(out_bbox, old_format=features.BoundingBoxFormat.XYXY, new_format=format)
461+
out_bbox = F.convert_format_bounding_box(
462+
out_bbox, old_format=features.BoundingBoxFormat.XYXY, new_format=format, inplace=True
463+
)
464+
return out_bbox.to(dtype=in_dtype)
440465

441466
if bounding_box.ndim < 2:
442467
bounding_box = [bounding_box]
443468

444-
expected_bboxes = [transform(bbox) for bbox in bounding_box]
469+
expected_bboxes = [transform(bbox, affine_matrix, format) for bbox in bounding_box]
445470
if len(expected_bboxes) > 1:
446471
expected_bboxes = torch.stack(expected_bboxes)
447472
else:
@@ -450,6 +475,18 @@ def transform(bbox):
450475
return expected_bboxes
451476

452477

478+
def reference_affine_bounding_box(bounding_box, *, format, spatial_size, angle, translate, scale, shear, center=None):
479+
if center is None:
480+
center = [s * 0.5 for s in spatial_size[::-1]]
481+
482+
affine_matrix = _compute_affine_matrix(angle, translate, scale, shear, center)
483+
affine_matrix = affine_matrix[:2, :]
484+
485+
expected_bboxes = reference_affine_bounding_box_helper(bounding_box, format=format, affine_matrix=affine_matrix)
486+
487+
return expected_bboxes
488+
489+
453490
def reference_inputs_affine_bounding_box():
454491
for bounding_box_loader, affine_kwargs in itertools.product(
455492
make_bounding_box_loaders(extra_dims=[()]),
@@ -536,12 +573,12 @@ def sample_inputs_convert_format_bounding_box():
536573

537574
def reference_convert_format_bounding_box(bounding_box, old_format, new_format):
538575
return torchvision.ops.box_convert(
539-
bounding_box, in_fmt=old_format.kernel_name.lower(), out_fmt=new_format.kernel_name.lower()
540-
)
576+
bounding_box, in_fmt=old_format.name.lower(), out_fmt=new_format.name.lower()
577+
).to(bounding_box.dtype)
541578

542579

543580
def reference_inputs_convert_format_bounding_box():
544-
for args_kwargs in sample_inputs_convert_color_space_image_tensor():
581+
for args_kwargs in sample_inputs_convert_format_bounding_box():
545582
if len(args_kwargs.args[0].shape) == 2:
546583
yield args_kwargs
547584

@@ -643,6 +680,20 @@ def sample_inputs_vertical_flip_video():
643680
yield ArgsKwargs(video_loader)
644681

645682

683+
def reference_vertical_flip_bounding_box(bounding_box, *, format, spatial_size):
684+
affine_matrix = np.array(
685+
[
686+
[1, 0, 0],
687+
[0, -1, spatial_size[0]],
688+
],
689+
dtype="float32",
690+
)
691+
692+
expected_bboxes = reference_affine_bounding_box_helper(bounding_box, format=format, affine_matrix=affine_matrix)
693+
694+
return expected_bboxes
695+
696+
646697
KERNEL_INFOS.extend(
647698
[
648699
KernelInfo(
@@ -656,6 +707,8 @@ def sample_inputs_vertical_flip_video():
656707
KernelInfo(
657708
F.vertical_flip_bounding_box,
658709
sample_inputs_fn=sample_inputs_vertical_flip_bounding_box,
710+
reference_fn=reference_vertical_flip_bounding_box,
711+
reference_inputs_fn=reference_inputs_flip_bounding_box,
659712
),
660713
KernelInfo(
661714
F.vertical_flip_mask,

test/smoke_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import torch
1+
"""Run smoke tests"""
2+
23
import torchvision
3-
import torchvision.datasets as dset
4-
import torchvision.transforms
4+
5+
print("torchvision version is ", torchvision.__version__)

test/test_prototype_transforms_functional.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def script(fn):
3838

3939
def make_info_args_kwargs_params(info, *, args_kwargs_fn, test_id=None):
4040
args_kwargs = list(args_kwargs_fn(info))
41+
if not args_kwargs:
42+
raise pytest.UsageError(
43+
f"Couldn't collect a single `ArgsKwargs` for `{info.id}`{f' in {test_id}' if test_id else ''}"
44+
)
4145
idx_field_len = len(str(len(args_kwargs)))
4246
return [
4347
pytest.param(

test/test_video_gpu_decoder.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
import pytest
55
import torch
6-
from torchvision.io import _HAS_GPU_VIDEO_DECODER, VideoReader
6+
import torchvision
7+
from torchvision import _HAS_GPU_VIDEO_DECODER
8+
from torchvision.io import VideoReader
79

810
try:
911
import av
@@ -29,8 +31,9 @@ class TestVideoGPUDecoder:
2931
],
3032
)
3133
def test_frame_reading(self, video_file):
34+
torchvision.set_video_backend("cuda")
3235
full_path = os.path.join(VIDEO_DIR, video_file)
33-
decoder = VideoReader(full_path, device="cuda")
36+
decoder = VideoReader(full_path)
3437
with av.open(full_path) as container:
3538
for av_frame in container.decode(container.streams.video[0]):
3639
av_frames = torch.tensor(av_frame.to_rgb(src_colorspace="ITU709").to_ndarray())
@@ -54,7 +57,8 @@ def test_frame_reading(self, video_file):
5457
],
5558
)
5659
def test_seek_reading(self, keyframes, full_path, duration):
57-
decoder = VideoReader(full_path, device="cuda")
60+
torchvision.set_video_backend("cuda")
61+
decoder = VideoReader(full_path)
5862
time = duration / 2
5963
decoder.seek(time, keyframes_only=keyframes)
6064
with av.open(full_path) as container:
@@ -79,8 +83,9 @@ def test_seek_reading(self, keyframes, full_path, duration):
7983
],
8084
)
8185
def test_metadata(self, video_file):
86+
torchvision.set_video_backend("cuda")
8287
full_path = os.path.join(VIDEO_DIR, video_file)
83-
decoder = VideoReader(full_path, device="cuda")
88+
decoder = VideoReader(full_path)
8489
video_metadata = decoder.get_metadata()["video"]
8590
with av.open(full_path) as container:
8691
video = container.streams.video[0]

0 commit comments

Comments
 (0)