From 9563a4015f8fcc6e94a605b2d5d9ee1ee8f9b2e7 Mon Sep 17 00:00:00 2001 From: atalman Date: Thu, 8 Dec 2022 07:01:06 -0800 Subject: [PATCH 1/3] Add cuda resnet50 test --- test/smoke_test.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/smoke_test.py b/test/smoke_test.py index f80aba1d19f..878bfcf962a 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -17,7 +17,6 @@ def smoke_test_torchvision() -> None: all(x is not None for x in [torch.ops.image.decode_png, torch.ops.torchvision.roi_align]), ) - 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: @@ -26,13 +25,15 @@ def smoke_test_torchvision_read_decode() -> None: if img_png.ndim != 3 or img_png.numel() < 100: raise RuntimeError(f"Unexpected shape of img_png: {img_png.shape}") +def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None: + from torchvision.io import read_image + from torchvision.models import resnet50, ResNet50_Weights -def smoke_test_torchvision_resnet50_classify() -> None: - img = read_image(str(SCRIPT_DIR / ".." / "gallery" / "assets" / "dog2.jpg")) + img = read_image(str(SCRIPT_DIR / "assets" / "dog2.jpg")).to(device) # Step 1: Initialize model with the best available weights weights = ResNet50_Weights.DEFAULT - model = resnet50(weights=weights) + model = resnet50(weights=weights).to(device) model.eval() # Step 2: Initialize the inference transforms @@ -49,7 +50,9 @@ def smoke_test_torchvision_resnet50_classify() -> None: expected_category = "German shepherd" print(f"{category_name}: {100 * score:.1f}%") if category_name != expected_category: - raise RuntimeError(f"Failed ResNet50 classify {category_name} Expected: {expected_category}") + raise RuntimeError( + f"Failed ResNet50 classify {category_name} Expected: {expected_category}" + ) def main() -> None: @@ -57,6 +60,8 @@ def main() -> None: smoke_test_torchvision() smoke_test_torchvision_read_decode() smoke_test_torchvision_resnet50_classify() + if torch.cuda.is_available(): + smoke_test_torchvision_resnet50_classify("cuda") if __name__ == "__main__": From 06b55d4a9d5db5c0983bc95de9939f0566ccf183 Mon Sep 17 00:00:00 2001 From: atalman Date: Thu, 8 Dec 2022 07:03:31 -0800 Subject: [PATCH 2/3] Fix path --- test/smoke_test.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/smoke_test.py b/test/smoke_test.py index 878bfcf962a..19032f28aba 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -26,10 +26,7 @@ def smoke_test_torchvision_read_decode() -> None: raise RuntimeError(f"Unexpected shape of img_png: {img_png.shape}") def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None: - from torchvision.io import read_image - from torchvision.models import resnet50, ResNet50_Weights - - img = read_image(str(SCRIPT_DIR / "assets" / "dog2.jpg")).to(device) + img = read_image(str(SCRIPT_DIR / ".." / "gallery" / "assets" / "dog2.jpg")).to(device) # Step 1: Initialize model with the best available weights weights = ResNet50_Weights.DEFAULT From 58a305f5fc9564ca6f46d87b148b5a0074f9de5a Mon Sep 17 00:00:00 2001 From: atalman Date: Thu, 8 Dec 2022 07:22:34 -0800 Subject: [PATCH 3/3] Tune vision smoke test --- test/smoke_test.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/smoke_test.py b/test/smoke_test.py index 19032f28aba..9c58add739e 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -45,13 +45,12 @@ def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None: score = prediction[class_id].item() category_name = weights.meta["categories"][class_id] expected_category = "German shepherd" - print(f"{category_name}: {100 * score:.1f}%") + print(f"{category_name} ({device}): {100 * score:.1f}%") if category_name != expected_category: raise RuntimeError( f"Failed ResNet50 classify {category_name} Expected: {expected_category}" ) - def main() -> None: print(f"torchvision: {torchvision.__version__}") smoke_test_torchvision() @@ -60,6 +59,5 @@ def main() -> None: if torch.cuda.is_available(): smoke_test_torchvision_resnet50_classify("cuda") - if __name__ == "__main__": main()