Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions kornia/augmentation/_2d/geometric/thin_plate_spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def __init__(
"padding_mode": SamplePadding.get(padding_mode),
}
self.dist = torch.distributions.Uniform(-scale, scale)
# Pre-create the source control points template
self._src_template = torch.tensor(
[[[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0], [0.0, 0.0]]],
dtype=torch.float32,
)

def generate_parameters(self, shape: Tuple[int, ...]) -> Dict[str, torch.Tensor]:
B, _, _, _ = shape
Expand All @@ -78,11 +83,7 @@ def generate_parameters(self, shape: Tuple[int, ...]) -> Dict[str, torch.Tensor]
dtype = self.dtype

# 5 TPS control points in normalized coordinates
src = torch.tensor(
[[[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0], [0.0, 0.0]]],
device=device,
dtype=dtype,
).expand(B, 5, 2)
src = self._src_template.to(device=device, dtype=dtype).expand(B, 5, 2)

if self.same_on_batch:
noise = self.dist.rsample((1, 5, 2)).to(device=device, dtype=dtype)
Expand Down
Loading