def test_equal_numpy_biort2(): h = biort('near_sym_b')[0] im = barbara[:, 52:407, 30:401] im_t = torch.unsqueeze(torch.tensor(im, dtype=torch.float32), dim=0).to(dev) ref = ref_colfilter(im, h) y = colfilter(im_t, prep_filt(h, 1).to(dev)) np.testing.assert_array_almost_equal(y[0].cpu(), ref, decimal=4)
def test_gradients(): h = biort('near_sym_b')[0] im_t = torch.unsqueeze(torch.tensor(barbara, dtype=torch.float32, requires_grad=True), dim=0) y_t = colfilter(im_t, prep_filt(h, 1)) dy = np.random.randn(*tuple(y_t.shape)).astype('float32') torch.autograd.grad(y_t, im_t, grad_outputs=torch.tensor(dy))
def test_equal_numpy_biort1(): h = biort('near_sym_b')[0] ref = ref_colfilter(barbara, h) y = colfilter(barbara_t, prep_filt(h, 1).to(dev)) np.testing.assert_array_almost_equal(y[0].cpu(), ref, decimal=4)
def test_biort(): h = biort('antonini')[0] y_op = colfilter(barbara_t, prep_filt(h, 1).to(dev)) assert list(y_op.shape)[1:] == bshape