Skip to content

Commit adb2add

Browse files
committed
Round gaussian_blur outputs before OpenCV reference compare.
OpenCV ground truth in gaussian_blur_opencv_results.pt is uint8 (discrete gray levels). torchvision returns float blur values, so compare rounded outputs to match integer reference semantics at atol=1.0. Example (small image, kernel [3, 5], sigma 0.8, channel 0 at (9, 0)): - OpenCV uint8 reference: 62 - OpenCV float / torchvision fp32: ~61.05 (already within atol=1 vs 62) - torchvision fp16 on ROCm raw: ~60.94 -> |62 - 60.94| = 1.0625 fails atol=1.0 - after round: 61 -> |62 - 61| = 1.0 passes Use round, not a bare .to(torch.uint8) on float outputs: PyTorch truncates float-to-uint8 (60.9375 -> 60), which gives |62 - 60| = 2.0 and fails. round(out) is enough here and keeps assert_close aligned with true_out dtype (.to(tensor) leaves float refs as float). All test_gaussian_blur cases that hit the reference pass with round + atol=1.0.
1 parent 0fba2e8 commit adb2add

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

test/test_functional_tensor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,8 @@ def test_gaussian_blur(device, image_size, dt, ksize, sigma, fn):
10531053
)
10541054

10551055
out = fn(tensor, kernel_size=ksize, sigma=sigma)
1056-
torch.testing.assert_close(out, true_out, rtol=0.0, atol=1.0, msg=f"{ksize}, {sigma}")
1056+
# OpenCV references are uint8; round float outputs before comparing levels.
1057+
torch.testing.assert_close(torch.round(out), true_out, rtol=0.0, atol=1.0, msg=f"{ksize}, {sigma}")
10571058

10581059

10591060
@pytest.mark.parametrize("device", cpu_and_cuda())

0 commit comments

Comments
 (0)