Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_gradcheck(self, device):
# test parameters
batch_shape = (2, 3, 11, 7)
kernel_size = (5, 3)
sigma = (1.5, 2.1)
# evaluate function gradient
input = torch.rand(batch_shape).to(device)
input = utils.tensor_to_gradcheck_var(input) # to var
assert gradcheck(
kornia.gaussian_blur2d,
(input, kernel_size, sigma, "replicate"),
raise_exception=True,
)
def test_gradcheck(self, device):
# prepare input data
data = torch.tensor([[[1., 1.],
[1., 1.]],
[[2., 2.],
[2., 2.]],
[[3., 3.],
[3., 3.]]]) # 3x2x2
data = data.to(device)
data = utils.tensor_to_gradcheck_var(data) # to var
assert gradcheck(kornia.color.BgrToRgb(), (data,),
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
assert gradcheck(sift_describe, (patches, 41),
raise_exception=True)
def test_gradcheck(self, device):
input = torch.rand(2, 3, 4, 4).to(device)
input = utils.tensor_to_gradcheck_var(input) # to var
assert gradcheck(kornia.contrib.max_blur_pool2d,
(input, 3,), raise_exception=True)
def test_gradcheck(self):
# prepare input data
data = torch.ones(2, 3, 1, 1)
data += 2
mean = torch.tensor([0.5, 1.0, 2.0]).double()
std = torch.tensor([2., 2., 2.]).double()
data = utils.tensor_to_gradcheck_var(data) # to var
assert gradcheck(kornia.color.Normalize(mean, std), (data,),
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).to(device)
img = utils.tensor_to_gradcheck_var(img) # to var
boxes = torch.tensor([[
[1., 1.],
[2., 1.],
[2., 2.],
[1., 2.],
]]).to(device) # 1x4x2
boxes = utils.tensor_to_gradcheck_var(
boxes, requires_grad=False) # to var
crop_height, crop_width = 4, 2
assert gradcheck(kornia.crop_and_resize,
(img, boxes, (crop_height, crop_width),),
raise_exception=True)
def test_gradcheck(self, size, device):
shape = random_shape(size, max_elem=5) # to shave time on gradcheck
src1 = torch.randn(shape).to(device)
src2 = torch.randn(shape).to(device)
alpha = random.random()
beta = random.random()
gamma = random.random()
src1 = utils.tensor_to_gradcheck_var(src1) # to var
src2 = utils.tensor_to_gradcheck_var(src2) # to var
assert gradcheck(kornia.color.AddWeighted(alpha, beta, gamma), (src1, src2),
raise_exception=True)
def test_gradcheck(self):
batch_size, channels, height, width = 2, 3, 4, 5
img = torch.ones(batch_size, channels, height, width)
img = utils.tensor_to_gradcheck_var(img) # to var
assert gradcheck(kornia.adjust_brightness, (img, 2.),
raise_exception=True)
def test_gradcheck(self, batch_shape, device_type):
# generate input data
device = torch.device(device_type)
eye_size = 3 # identity 3x3
# create checkerboard
patch_src = torch.rand(batch_shape).to(device)
patch_src = utils.tensor_to_gradcheck_var(patch_src) # to var
# create base homography
batch_size, _, height, width = patch_src.shape
dst_homo_src = utils.create_eye_batch(batch_size, eye_size)
dst_homo_src = utils.tensor_to_gradcheck_var(
dst_homo_src, requires_grad=False) # to var
# instantiate warper
warper = kornia.HomographyWarper(height, width)
# evaluate function gradient
assert gradcheck(warper, (patch_src, dst_homo_src,),
raise_exception=True)
def test_gradcheck(self, device):
input = torch.rand(2, 3, 5, 5).to(device)
input = utils.tensor_to_gradcheck_var(input) # to var
assert gradcheck(kornia.conv_soft_argmax2d,
(input), raise_exception=True)