Skip to content

Commit dd475df

Browse files
AhmedZeroalinpahontu2912
authored andcommitted
Improve tensor error messages and code readability.
1 parent 28ce621 commit dd475df

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/TorchVision/Functional.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public static Tensor normalize(Tensor input, double[] means, double[] stdevs, bo
555555
if (!input.is_floating_point())
556556
throw new ArgumentException($"Input tensor should be a float tensor. Got {input.dtype}.");
557557
if (input.ndim < 3)
558-
throw new ArgumentException($"Expected tensor to be a tensor image of size (..., C, H, W). Got tensor.size() = {input.size()}");
558+
throw new ArgumentException($"Expected tensor to be a tensor image of size (..., C, H, W). Got tensor.size() = ({string.Join(", ", input.shape)})");
559559
if (!inplace)
560560
input = input.clone();
561561

src/TorchVision/Normalize.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal Normalize(double[] means, double[] stdevs,bool inplace = false)
2323

2424
public Tensor call(Tensor input)
2525
{
26-
var expectedChannels = (input.shape.Length == 4) ? input.size(1) : input.size(0);
26+
var expectedChannels = (input.ndim == 4) ? input.size(1) : input.size(0);
2727
if (expectedChannels != means.Length)
2828
throw new ArgumentException("The number of channels is not equal to the number of means and standard deviations");
2929
return transforms.functional.normalize(input, means, stdevs, inplace);

0 commit comments

Comments
 (0)