Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Fix CUDA failling tests of same device (#2215)

João Gustavo A. Amorimbb5c340766da
diff --git a/kornia/augmentation/auto/operations/base.py b/kornia/augmentation/auto/operations/base.py
index 7c7242cc2..f0d444d77 100644
--- a/kornia/augmentation/auto/operations/base.py
+++ b/kornia/augmentation/auto/operations/base.py
@@ -143,7 +143,7 @@ class OperationBase(Module):
if params is None:
params = self.forward_parameters(input.shape)
- batch_prob = params["batch_prob"][(...,) + ((None,) * (len(input.shape) - 1))]
+ batch_prob = params["batch_prob"][(...,) + ((None,) * (len(input.shape) - 1))].to(device=input.device)
if self._gradient_estimator is not None:
# skip the gradient computation if gradient estimator is provided.
@@ -155,7 +155,6 @@ class OperationBase(Module):
return self._gradient_estimator.apply(input, output)
# If magnitude is not None, make the grad w.r.t the magnitude
return self._gradient_estimator.apply(self.magnitude, output)
-
return batch_prob * self.op(input, params=params) + (1 - batch_prob) * input
@property
diff --git a/kornia/augmentation/random_generator/_2d/cutmix.py b/kornia/augmentation/random_generator/_2d/cutmix.py
index baa33cc23..78a3691d4 100644
--- a/kornia/augmentation/random_generator/_2d/cutmix.py
+++ b/kornia/augmentation/random_generator/_2d/cutmix.py
@@ -118,14 +118,14 @@ class CutmixGenerator(RandomGeneratorBase):
cut_width = cut_width[0]
# Reserve at least 1 pixel for cropping.
- x_start: torch.Tensor = _adapted_rsampling(_gen_shape, self.rand_sampler, same_on_batch) * (
+ x_start = _adapted_rsampling(_gen_shape, self.rand_sampler, same_on_batch).to(device=_device, dtype=_dtype) * (
width - cut_width - 1
)
- y_start: torch.Tensor = _adapted_rsampling(_gen_shape, self.rand_sampler, same_on_batch) * (
+ y_start = _adapted_rsampling(_gen_shape, self.rand_sampler, same_on_batch).to(device=_device, dtype=_dtype) * (
height - cut_height - 1
)
- x_start = x_start.floor().to(device=_device, dtype=_dtype)
- y_start = y_start.floor().to(device=_device, dtype=_dtype)
+ x_start = x_start.floor()
+ y_start = y_start.floor()
crop_src = bbox_generator(x_start.squeeze(), y_start.squeeze(), cut_width, cut_height)