Skip to content

Scipy and Pytorch backends give different results at order=3 #2

@sremedios

Description

@sremedios

When providing order=3 to each backend, the results are wildly different. Here's code:

import numpy as np
import resize.scipy as resize_sp
import resize.pytorch as resize_pt
import torch

x1 = torch.arange(5).float()[:, None]
x2 = torch.arange(7).float()[None, :]
x_pt = (x1 + x2).float()
x_sp = x_pt.numpy()

# Batch, channel for pytorch
x_pt = x_pt[None, None, ...]

dxyz = (0.7, 2.4)

for order in [0, 1, 3]:
    y_pt = resize_pt.resize(x_pt, dxyz, order=order)
    y_sp = resize_sp.resize(x_sp, dxyz, order=order)
    
    print(f"{order=}, Close? {np.allclose(y_pt.numpy(), y_sp)}")

When order=3, the final array values are:

tensor([[[[0.4432, 2.9393, 5.4352],
          [1.0080, 3.5040, 6.0000],
          [1.8460, 4.3420, 6.8380],
          [2.5040, 5.0000, 7.4960],
          [3.1620, 5.6580, 8.1540],
          [4.0000, 6.4960, 8.9920],
          [4.5647, 7.0608, 9.5567]]]])

vs

array([[0.49109966, 2.9585092 , 5.4259186 ],
       [1.0636655 , 3.531075  , 5.9984846 ],
       [1.8582219 , 4.3256316 , 6.793041  ],
       [2.5325904 , 5.        , 7.4674096 ],
       [3.206959  , 5.6743684 , 8.141778  ],
       [4.0015154 , 6.468925  , 8.936335  ],
       [4.5740814 , 7.0414906 , 9.508901  ]], dtype=float32)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions