Skip to content

Commit

Permalink
[enhance] improve flipping and cropping speed (kornia#2179)
Browse files Browse the repository at this point in the history
* init

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* restore wrong file

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
shijianjian and pre-commit-ci[bot] authored Jan 26, 2023
1 parent 400ee69 commit f11c301
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 2 additions & 1 deletion kornia/augmentation/_2d/geometric/crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def precrop_padding(
if padding is None:
padding = self.compute_padding(input.shape)

input = pad(input, padding, value=flags["fill"], mode=flags["padding_mode"])
if any(padding):
input = pad(input, padding, value=flags["fill"], mode=flags["padding_mode"])

return input

Expand Down
6 changes: 2 additions & 4 deletions kornia/geometry/transform/flips.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ def hflip(input: Tensor) -> Tensor:
Returns:
The horizontally flipped image tensor.
"""
w = input.shape[-1]
return input[..., torch.arange(w - 1, -1, -1, device=input.device)]
return input.flip(-1).contiguous()


def vflip(input: Tensor) -> Tensor:
Expand All @@ -141,5 +140,4 @@ def vflip(input: Tensor) -> Tensor:
Returns:
The vertically flipped image tensor.
"""
h = input.shape[-2]
return input[..., torch.arange(h - 1, -1, -1, device=input.device), :]
return input.flip(-2).contiguous()

0 comments on commit f11c301

Please sign in to comment.