π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Fixed bugs in patchsequential. Remove fill_diagonal operation for better ONNX support. (#1178)
Jian Shiff585f77f23d
diff --git a/kornia/augmentation/container/patch.py b/kornia/augmentation/container/patch.pyindex b4a0b4532..d14436749 100644--- a/kornia/augmentation/container/patch.py+++ b/kornia/augmentation/container/patch.py@@ -338,19 +338,14 @@ class PatchSequential(ImageSequential):if label is not None and out_label is not None:if len(out_label.shape) == 1:# Wierd the mypy error though it is as same as in the next block- _label = (- torch.ones( # type: ignore- in_shape[0] * in_shape[1], device=out_label.device, out_label=label.dtype- )- * -1- )+ _label = torch.ones(in_shape[0] * in_shape[1], device=out_label.device, dtype=out_label.dtype) * -1_label = labelelse:_label = (torch.ones(in_shape[0], *out_label.shape[1:], device=out_label.device, dtype=out_label.dtype) * -1)_label[:, 0] = label- label[params.indices] = out_label+ _label[params.indices] = out_labelelif label is None and out_label is not None:if len(out_label.shape) == 1:_label = torch.ones(in_shape[0] * in_shape[1], device=out_label.device, dtype=out_label.dtype) * -1@@ -360,7 +355,7 @@ class PatchSequential(ImageSequential):)_label[params.indices] = out_label- return input, label, PatchParamItem(params.indices, param=out_param)+ return input, _label, PatchParamItem(params.indices, param=out_param)def forward_by_params(self, input: torch.Tensor, label: Optional[torch.Tensor], params: List[PatchParamItem]@@ -393,10 +388,7 @@ class PatchSequential(ImageSequential):pad = self.compute_padding(input, self.padding)input = self.extract_patches(input, self.grid_size, pad)- if label is not None:- assert label.dim() == 1- # repeat label as the same number as input patches.- label = torch.stack([label] * self.grid_size[0] * self.grid_size[1]).reshape(-1)+if params is None:params = self.forward_parameters(input.shape)diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.pyindex f0faa58fb..bcfbd43b6 100644--- a/kornia/geometry/transform/imgwarp.py+++ b/kornia/geometry/transform/imgwarp.py@@ -406,10 +406,8 @@ def get_rotation_matrix2d(center: torch.Tensor, angle: torch.Tensor, scale: torc# convert angle and apply scalerotation_matrix: torch.Tensor = angle_to_rotation_matrix(angle)- scaling_matrix: torch.Tensor = (- torch.zeros((2, 2), device=rotation_matrix.device, dtype=rotation_matrix.dtype)- .fill_diagonal_(1)- .repeat(rotation_matrix.size(0), 1, 1)+ scaling_matrix: torch.Tensor = torch.eye(2, device=rotation_matrix.device, dtype=rotation_matrix.dtype).repeat(+ rotation_matrix.size(0), 1, 1)scaling_matrix = scaling_matrix * scale.unsqueeze(dim=2).repeat(1, 1, 2)