π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Fix RandomRain crash when no images in the batch are augmented (#3097) (#3103)
plamen-alcatraz450a241c4521
diff --git a/kornia/augmentation/random_generator/_2d/random_rain.py b/kornia/augmentation/random_generator/_2d/random_rain.pyindex 50332f380..d3be61669 100644--- a/kornia/augmentation/random_generator/_2d/random_rain.py+++ b/kornia/augmentation/random_generator/_2d/random_rain.py@@ -64,7 +64,7 @@ class RainGenerator(RandomGeneratorBase):device=_device, dtype=torch.long)coordinates_factor = _adapted_rsampling(- (batch_size, int(number_of_drops_factor.max().item()), 2),+ (batch_size, int(number_of_drops_factor.max().item()) if number_of_drops_factor.numel() > 0 else 0, 2),self.coordinates_sampler,same_on_batch=same_on_batch,).to(device=_device)diff --git a/tests/augmentation/test_augmentation.py b/tests/augmentation/test_augmentation.pyindex ca3b862d5..0f859807e 100644--- a/tests/augmentation/test_augmentation.py+++ b/tests/augmentation/test_augmentation.py@@ -5150,6 +5150,11 @@ class TestRandomRain(BaseTester):assert err_msg in str(errinfo)+ def test_zero_probability(self, device):+ input_data = torch.rand(10, 3, 8, 8, device=device)+ aug = RandomRain(p=0.0, drop_height=(2, 3), drop_width=(2, 3), number_of_drops=(1, 3))+ aug(input_data)+class TestMultiprocessing:torch.manual_seed(0) # for random reproductibility