def test_gradcheck(self, device, dtype): inp = torch.randn((1, 1, 7, 7, 7), device=device, dtype=dtype) src_box = torch.tensor( [ [ [1.0, 1.0, 1.0], [3.0, 1.0, 1.0], [3.0, 3.0, 1.0], [1.0, 3.0, 1.0], [1.0, 1.0, 2.0], [3.0, 1.0, 2.0], [3.0, 3.0, 2.0], [1.0, 3.0, 2.0], ] ], device=device, dtype=dtype, ) # 1x8x3 dst_box = torch.tensor( [ [ [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.0, 1.0, 1.0], ] ], device=device, dtype=dtype, ) # 1x8x3 inp = utils.tensor_to_gradcheck_var(inp, requires_grad=True) # to var assert gradcheck(kornia.geometry.transform.crop.crop_by_boxes3d, (inp, src_box, dst_box), raise_exception=True)
def test_grad_zca_individual_transforms(self, device, dtype): """ Checks if the gradients of the transforms are correct w.r.t to the input data """ data = torch.tensor([[2, 0], [0, 1], [-2, 0], [0, -1]], device=device, dtype=dtype) data = utils.tensor_to_gradcheck_var(data) def zca_T(x): return kornia.enhance.zca_mean(x)[0] def zca_mu(x): return kornia.enhance.zca_mean(x)[1] def zca_T_inv(x): return kornia.enhance.zca_mean(x, return_inverse=True)[2] assert gradcheck(zca_T, (data,), raise_exception=True) assert gradcheck(zca_mu, (data,), raise_exception=True) assert gradcheck(zca_T_inv, (data,), raise_exception=True)
def test_gradcheck(self, device): input = torch.rand(1, 2, 3, 5, 5).to(device) input = utils.tensor_to_gradcheck_var(input) # to var assert gradcheck(kornia.conv_soft_argmax3d, (input), raise_exception=True)
def test_gradcheck(self, device, dtype): torch.manual_seed(0) # for random reproductibility inputs3d = torch.rand((3, 3, 3), device=device, dtype=dtype) # 3 x 3 x 3 inputs3d = utils.tensor_to_gradcheck_var(inputs3d) # to var assert gradcheck(RandomEqualize3D(p=0.5), (inputs3d,), raise_exception=True)
def test_gradcheck(self, device, dtype): torch.manual_seed(0) # for random reproductibility inp = torch.rand((3, 3, 3), device=device, dtype=dtype) # 3 x 3 inp = utils.tensor_to_gradcheck_var(inp) # to var assert gradcheck(RandomCrop3D(size=(3, 3, 3), p=1.), (inp, ), raise_exception=True)
def test_gradcheck(self, device): batch_size, channels, depth, height, width = 1, 2, 3, 5, 4 img = torch.rand(batch_size, channels, depth, height, width).to(device) img = utils.tensor_to_gradcheck_var(img) # to var assert gradcheck(kornia.filters.spatial_gradient3d, (img,), raise_exception=True)
def test_gradcheck(self, device, dtype): img = torch.rand(1, 2, 5, 4, device=device, dtype=dtype) img = utils.tensor_to_gradcheck_var(img) # to var assert gradcheck(kornia.center_crop, (img, (4, 2),), raise_exception=True)
def test_gradcheck(self, device, dtype): # test parameters new_size = 4 input = torch.rand(1, 2, 3, 4, device=device, dtype=dtype) input = utils.tensor_to_gradcheck_var(input) # to var assert gradcheck(kornia.Resize(new_size), (input,), raise_exception=True)
def test_gradcheck(self, device): input = torch.rand(1, 2, 5, 7).to(device) input = utils.tensor_to_gradcheck_var(input) # to var assert gradcheck(F.random_perspective, (input, 0., 1.), raise_exception=True)
def test_gradcheck(self, device, dtype): image = torch.rand(1, 2, 3, 4, device=device, dtype=dtype) image = utils.tensor_to_gradcheck_var(image) # to var assert gradcheck(kornia.losses.total_variation, (image, ), raise_exception=True)
def test_gradcheck(self, device): matrix = torch.eye(2, 3).to(device)[None] matrix = utils.tensor_to_gradcheck_var(matrix) # to var assert gradcheck(kornia.invert_affine_transform, (matrix, ), raise_exception=True)
def test_gradcheck(self): batch_size, channels, height, width = 1, 1, 13, 13 ori = PatchDominantGradientOrientation(width) patches = torch.rand(batch_size, channels, height, width) patches = utils.tensor_to_gradcheck_var(patches) # to var assert gradcheck(ori, (patches, ), raise_exception=True)
def test_gradcheck(self): batch_size, channels, height, width = 1, 1, 41, 41 patches = torch.rand(batch_size, channels, height, width) patches = utils.tensor_to_gradcheck_var(patches) # to var laf = torch.rand(batch_size, 4, 2, 3) assert gradcheck(PassLAF(), (patches, laf), raise_exception=True)
def test_gradcheck(self, device): batch_size, channels, height, width = 1, 1, 31, 21 patches = torch.rand(batch_size, channels, height, width, device=device) patches = utils.tensor_to_gradcheck_var(patches) # to var assert gradcheck(ScaleSpaceDetector(2).to(device), patches, raise_exception=True, nondet_tol=1e-4)
def test_gradcheck(self): data = torch.rand(3, 5, 5) # 3x5x5 data = utils.tensor_to_gradcheck_var(data) # to var assert gradcheck(kornia.color.YcbcrToRgb(), (data,), raise_exception=True)
def test_gradcheck(self, device): batch_size, channels, height, width = 3, 2, 2, 3 inp = torch.rand(batch_size, channels, height, width, device=device) inp = utils.tensor_to_gradcheck_var(inp) # to var assert gradcheck(kornia.feature.laf_from_three_points, (inp,), raise_exception=True)
def test_gradcheck(self, device): batch_size, channels, height, width = 1, 2, 2, 3 img = torch.rand(batch_size, channels, height, width) img = utils.tensor_to_gradcheck_var(img) # to var assert gradcheck(kornia.feature.get_laf_center, (img,), raise_exception=True)
def test_gradcheck(self, device): input = torch.rand(1, 2, 5, 7).to(device) input = utils.tensor_to_gradcheck_var(input) # to var assert gradcheck(kornia.augmentation.RandomAffine(0.), (input, ), raise_exception=True)
def test_gradcheck(self, device, dtype): input = torch.rand(1, 2, 3, 4, device=device, dtype=dtype) input = utils.tensor_to_gradcheck_var(input) assert gradcheck(kornia.Rescale(2.0), (input,), raise_exception=True)
def test_gradcheck(self, device, dtype): batch_size, channels, height, width = 1, 2, 5, 4 img = torch.rand(batch_size, channels, height, width, device=device, dtype=dtype) img = utils.tensor_to_gradcheck_var(img) # to var assert gradcheck(kornia.filters.box_blur, (img, (3, 3)), raise_exception=True)
def test_gradcheck(self, device): batch_size, channels, height, width = 2, 3, 4, 5 img = torch.ones(batch_size, channels, height, width).to(device) img = utils.tensor_to_gradcheck_var(img) # to var assert gradcheck(kornia.rgb_to_grayscale, (img, ), raise_exception=True)
def test_gradcheck_unnorm(self, device): batch_size, channels, height, width = 1, 2, 5, 4 img = torch.rand(batch_size, channels, height, width).to(device) img = utils.tensor_to_gradcheck_var(img) # to var assert gradcheck(kornia.filters.sobel, (img, False), raise_exception=True)
def test_gradcheck(self, device): input = torch.rand((1, 3, 3)).to(device) # 4 x 4 input = utils.tensor_to_gradcheck_var(input) # to var assert gradcheck(RandomDepthicalFlip3D(p=1.), (input, ), raise_exception=True)
def test_gradcheck(self, device): batch_size, channels, height, width = 2, 1, 32, 32 patches = torch.rand(batch_size, channels, height, width, device=device) patches = utils.tensor_to_gradcheck_var(patches) # to var ori = OriNet().to(device=device, dtype=patches.dtype) assert gradcheck(ori, (patches, ), raise_exception=True)
def test_gradcheck(self, device, dtype): input = torch.rand(1, 2, 3, 4, 5, device=device, dtype=dtype) input = utils.tensor_to_gradcheck_var(input) # to var assert gradcheck(kornia.augmentation.CenterCrop3D(3), (input,), raise_exception=True)
def test_gradcheck(self, device): batch_size, channels, height, width = 1, 2, 5, 4 img = torch.rand(batch_size, channels, height, width, device=device) img = utils.tensor_to_gradcheck_var(img) # to var assert gradcheck(kornia.geometry.transform.imgwarp.angle_to_rotation_matrix, (img,), raise_exception=True)
def test_gradcheck(self, device): input = torch.rand(2, 3, 3, 2).to(device) input = utils.tensor_to_gradcheck_var(input) # to var assert gradcheck(kornia.spatial_soft_argmax2d, (input), raise_exception=True)
def test_gradcheck(self, device): batch_size, channels, height, width = 3, 2, 2, 3 laf = torch.rand(batch_size, channels, height, width, device=device) laf = utils.tensor_to_gradcheck_var(laf) # to var assert gradcheck(kornia.feature.laf_to_boundary_points, (laf), raise_exception=True)
def test_gradcheck(self, device): input = torch.rand(1, 2, 3, 5, 5).to(device) input = utils.tensor_to_gradcheck_var(input) # to var assert gradcheck(kornia.geometry.ConvQuadInterp3d(), (input), raise_exception=True)
def test_gradcheck(self, device): batch_size, channels = 3, 2 xy = utils.tensor_to_gradcheck_var(torch.rand(batch_size, channels, 2, device=device)) ori = utils.tensor_to_gradcheck_var(torch.rand(batch_size, channels, 1, device=device)) scale = utils.tensor_to_gradcheck_var(torch.abs(torch.rand(batch_size, channels, 1, 1, device=device))) assert gradcheck(kornia.feature.laf_from_center_scale_ori, (xy, scale, ori), raise_exception=True)