diff --git a/test/smoke_test.py b/test/smoke_test.py index 9c58add739e..81166309a8b 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -17,6 +17,7 @@ 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: @@ -25,6 +26,7 @@ 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: img = read_image(str(SCRIPT_DIR / ".." / "gallery" / "assets" / "dog2.jpg")).to(device) @@ -47,9 +49,8 @@ def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None: expected_category = "German shepherd" print(f"{category_name} ({device}): {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: print(f"torchvision: {torchvision.__version__}") @@ -59,5 +60,6 @@ def main() -> None: if torch.cuda.is_available(): smoke_test_torchvision_resnet50_classify("cuda") + if __name__ == "__main__": main() diff --git a/torchvision/models/efficientnet.py b/torchvision/models/efficientnet.py index 05414c93150..3877dff6a0a 100644 --- a/torchvision/models/efficientnet.py +++ b/torchvision/models/efficientnet.py @@ -779,7 +779,9 @@ def efficientnet_b0( weights = EfficientNet_B0_Weights.verify(weights) inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_b0", width_mult=1.0, depth_mult=1.0) - return _efficientnet(inverted_residual_setting, 0.2, last_channel, weights, progress, **kwargs) + return _efficientnet( + inverted_residual_setting, kwargs.pop("dropout", 0.2), last_channel, weights, progress, **kwargs + ) @register_model() @@ -808,7 +810,9 @@ def efficientnet_b1( weights = EfficientNet_B1_Weights.verify(weights) inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_b1", width_mult=1.0, depth_mult=1.1) - return _efficientnet(inverted_residual_setting, 0.2, last_channel, weights, progress, **kwargs) + return _efficientnet( + inverted_residual_setting, kwargs.pop("dropout", 0.2), last_channel, weights, progress, **kwargs + ) @register_model() @@ -837,7 +841,9 @@ def efficientnet_b2( weights = EfficientNet_B2_Weights.verify(weights) inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_b2", width_mult=1.1, depth_mult=1.2) - return _efficientnet(inverted_residual_setting, 0.3, last_channel, weights, progress, **kwargs) + return _efficientnet( + inverted_residual_setting, kwargs.pop("dropout", 0.3), last_channel, weights, progress, **kwargs + ) @register_model() @@ -866,7 +872,14 @@ def efficientnet_b3( weights = EfficientNet_B3_Weights.verify(weights) inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_b3", width_mult=1.2, depth_mult=1.4) - return _efficientnet(inverted_residual_setting, 0.3, last_channel, weights, progress, **kwargs) + return _efficientnet( + inverted_residual_setting, + kwargs.pop("dropout", 0.3), + last_channel, + weights, + progress, + **kwargs, + ) @register_model() @@ -895,7 +908,14 @@ def efficientnet_b4( weights = EfficientNet_B4_Weights.verify(weights) inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_b4", width_mult=1.4, depth_mult=1.8) - return _efficientnet(inverted_residual_setting, 0.4, last_channel, weights, progress, **kwargs) + return _efficientnet( + inverted_residual_setting, + kwargs.pop("dropout", 0.4), + last_channel, + weights, + progress, + **kwargs, + ) @register_model() @@ -926,7 +946,7 @@ def efficientnet_b5( inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_b5", width_mult=1.6, depth_mult=2.2) return _efficientnet( inverted_residual_setting, - 0.4, + kwargs.pop("dropout", 0.4), last_channel, weights, progress, @@ -963,7 +983,7 @@ def efficientnet_b6( inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_b6", width_mult=1.8, depth_mult=2.6) return _efficientnet( inverted_residual_setting, - 0.5, + kwargs.pop("dropout", 0.5), last_channel, weights, progress, @@ -1000,7 +1020,7 @@ def efficientnet_b7( inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_b7", width_mult=2.0, depth_mult=3.1) return _efficientnet( inverted_residual_setting, - 0.5, + kwargs.pop("dropout", 0.5), last_channel, weights, progress, @@ -1038,7 +1058,7 @@ def efficientnet_v2_s( inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_v2_s") return _efficientnet( inverted_residual_setting, - 0.2, + kwargs.pop("dropout", 0.2), last_channel, weights, progress, @@ -1076,7 +1096,7 @@ def efficientnet_v2_m( inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_v2_m") return _efficientnet( inverted_residual_setting, - 0.3, + kwargs.pop("dropout", 0.3), last_channel, weights, progress, @@ -1114,7 +1134,7 @@ def efficientnet_v2_l( inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_v2_l") return _efficientnet( inverted_residual_setting, - 0.4, + kwargs.pop("dropout", 0.4), last_channel, weights, progress,