🐍 Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix(augmentation)!: draw per-frame params for nested containers in VideoSequential (#5518)
Rızgar Ozanaef9eb213528
diff --git a/changelog.d/5518.breaking.md b/changelog.d/5518.breaking.mdnew file mode 100644index 000000000..cf13e937a--- /dev/null+++ b/changelog.d/5518.breaking.md@@ -0,0 +1,5 @@+`VideoSequential(same_on_frame=False)` now draws separate parameters for every frame in a nested container, such+as an `ImageSequential`, as it already did for augmentations placed in it directly. It used to draw one set per+video. With a single video, every frame got that same set. With several videos, the call raised, for example+`grid_sampler(): expected grid and input to have same batch size` for `RandomAffine`, or a flip gave every frame of+every video the same result. A nested `RandomCrop` raised `IndexError` in both cases.diff --git a/kornia/augmentation/container/video.py b/kornia/augmentation/container/video.pyindex b2f449db6..0d70691a2 100644--- a/kornia/augmentation/container/video.py+++ b/kornia/augmentation/container/video.py@@ -254,7 +254,9 @@ class VideoSequential(ImageSequential):param = ParamItem(name, mod_param)elif isinstance(module, (SequentialBase,)):- seq_param = module.forward_parameters(batch_shape)+ # Frames are flattened to (B * T, ...) before the nested container runs, so it+ # needs one draw per frame, like the unnested branch above.+ seq_param = module.forward_parameters(torch.Size([batch_shape[0] * frame_num, *batch_shape[1:]]))if self.same_on_frame:raise ValueError("nn.Sequential is currently unsupported for ``same_on_frame``.")param = ParamItem(name, seq_param)diff --git a/tests/augmentation/container/test_video_sequential.py b/tests/augmentation/container/test_video_sequential.pyindex 4be7b341d..23fac7459 100644--- a/tests/augmentation/container/test_video_sequential.py+++ b/tests/augmentation/container/test_video_sequential.py@@ -114,6 +114,8 @@ class TestVideoSequential:[K.RandomCrop((2, 2), padding=2)],[K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0)],[K.RandomAffine(360, p=0.0), K.ImageSequential(K.RandomAffine(360, p=0.0))],+ [K.ImageSequential(K.RandomAffine(360, p=1.0))],+ [K.RandomAffine(360, p=1.0), K.ImageSequential(K.RandomAffine(360, p=0.5))],],)@pytest.mark.parametrize("data_format", ["BCTHW", "BTCHW"])