Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions torchvision/transforms/_functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,13 @@ def normalize(tensor: Tensor, mean: List[float], std: List[float], inplace: bool
dtype = tensor.dtype
mean = torch.as_tensor(mean, dtype=dtype, device=tensor.device)
std = torch.as_tensor(std, dtype=dtype, device=tensor.device)
if (std == 0).any():
raise ValueError(f"std evaluated to zero after conversion to {dtype}, leading to division by zero.")

def stdzero():
raise ValueError(
f"std evaluated to zero after conversion to {dtype}, leading to division by zero."
)

torch.cond((std == 0).any(), stdzero, lambda: None)
if mean.ndim == 1:
mean = mean.view(-1, 1, 1)
if std.ndim == 1:
Expand Down
Loading