From f1bffe1f7858c1f28c3446d9fc7c4ba1fc6df71e Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Mon, 1 May 2023 23:08:55 +0200 Subject: [PATCH 1/2] add decode_jpeg_cuda to smoke test --- test/smoke_test.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/smoke_test.py b/test/smoke_test.py index 1f1364512ee..649e097e9c8 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -1,13 +1,11 @@ """Run smoke tests""" -import os import sys from pathlib import Path import torch -import torch.nn as nn import torchvision -from torchvision.io import read_image +from torchvision.io import decode_jpeg, read_file, read_image from torchvision.models import resnet50, ResNet50_Weights SCRIPT_DIR = Path(__file__).parent @@ -29,6 +27,13 @@ def smoke_test_torchvision_read_decode() -> None: raise RuntimeError(f"Unexpected shape of img_png: {img_png.shape}") +def smoke_test_torchvision_decode_jpeg_cuda(): + img_jpg_data = read_file(str(SCRIPT_DIR / "assets" / "encode_jpeg" / "grace_hopper_517x606.jpg")) + img_jpg = decode_jpeg(img_jpg_data, device="cuda") + if img_jpg.ndim != 3 or img_jpg.numel() < 100: + raise RuntimeError(f"Unexpected shape of img_jpg: {img_jpg.shape}") + + def smoke_test_compile() -> None: try: model = resnet50().cuda() @@ -77,6 +82,7 @@ def main() -> None: smoke_test_torchvision_read_decode() smoke_test_torchvision_resnet50_classify() if torch.cuda.is_available(): + smoke_test_torchvision_decode_jpeg_cuda() smoke_test_torchvision_resnet50_classify("cuda") smoke_test_compile() From b3008b0a44569ed9225690d324163b332a63025d Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Tue, 2 May 2023 12:47:56 +0200 Subject: [PATCH 2/2] make shape checks more strict --- test/smoke_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/smoke_test.py b/test/smoke_test.py index 649e097e9c8..bfcb4a0a772 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -20,17 +20,17 @@ def smoke_test_torchvision() -> None: def smoke_test_torchvision_read_decode() -> None: img_jpg = read_image(str(SCRIPT_DIR / "assets" / "encode_jpeg" / "grace_hopper_517x606.jpg")) - if img_jpg.ndim != 3 or img_jpg.numel() < 100: + if img_jpg.shape != (3, 606, 517): raise RuntimeError(f"Unexpected shape of img_jpg: {img_jpg.shape}") img_png = read_image(str(SCRIPT_DIR / "assets" / "interlaced_png" / "wizard_low.png")) - if img_png.ndim != 3 or img_png.numel() < 100: + if img_png.shape != (4, 471, 354): raise RuntimeError(f"Unexpected shape of img_png: {img_png.shape}") def smoke_test_torchvision_decode_jpeg_cuda(): img_jpg_data = read_file(str(SCRIPT_DIR / "assets" / "encode_jpeg" / "grace_hopper_517x606.jpg")) img_jpg = decode_jpeg(img_jpg_data, device="cuda") - if img_jpg.ndim != 3 or img_jpg.numel() < 100: + if img_jpg.shape != (3, 606, 517): raise RuntimeError(f"Unexpected shape of img_jpg: {img_jpg.shape}")