From 23bb1951cec4e0859323f2c315ff796039d4a313 Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Wed, 11 May 2022 17:31:17 +0200 Subject: [PATCH 1/3] Clarify TypeError message --- torchvision/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/torchvision/utils.py b/torchvision/utils.py index e82752ab28b..068687664b8 100644 --- a/torchvision/utils.py +++ b/torchvision/utils.py @@ -57,7 +57,11 @@ def make_grid( if not torch.jit.is_scripting() and not torch.jit.is_tracing(): _log_api_usage_once(make_grid) if not (torch.is_tensor(tensor) or (isinstance(tensor, list) and all(torch.is_tensor(t) for t in tensor))): - raise TypeError(f"tensor or list of tensors expected, got {type(tensor)}") + if isinstance(tensor, list): + typ += "a list not containing only tensors" + else: + typ = type(tensor) + raise TypeError(f"tensor or list of tensors expected, got {typ}") if "range" in kwargs.keys(): warnings.warn( From 727d1df1ab52c0f9f0cca9c87a9d94e65a1e75ec Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Wed, 11 May 2022 17:34:26 +0200 Subject: [PATCH 2/3] typo --- torchvision/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/utils.py b/torchvision/utils.py index 068687664b8..ab0f6ed6476 100644 --- a/torchvision/utils.py +++ b/torchvision/utils.py @@ -58,7 +58,7 @@ def make_grid( _log_api_usage_once(make_grid) if not (torch.is_tensor(tensor) or (isinstance(tensor, list) and all(torch.is_tensor(t) for t in tensor))): if isinstance(tensor, list): - typ += "a list not containing only tensors" + typ = "a list not containing only tensors" else: typ = type(tensor) raise TypeError(f"tensor or list of tensors expected, got {typ}") From 172e22b9661725d0313404c19d0be316253319da Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Wed, 11 May 2022 22:39:32 +0200 Subject: [PATCH 3/3] Wrap tye() in repr() so that the type-check stfu --- torchvision/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/utils.py b/torchvision/utils.py index ab0f6ed6476..64e7b481ebf 100644 --- a/torchvision/utils.py +++ b/torchvision/utils.py @@ -60,7 +60,7 @@ def make_grid( if isinstance(tensor, list): typ = "a list not containing only tensors" else: - typ = type(tensor) + typ = repr(type(tensor)) raise TypeError(f"tensor or list of tensors expected, got {typ}") if "range" in kwargs.keys():