pytorch / pytorch/vision

Adding 'crop' option(s) to RandomRotation

Open
#9,147 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🚀 The feature

Adding an option to the RandomRotation Transform to crop its output to an area that does not contain any 'padding' (black corners).

Motivation, pitch

I was working on surface-defect-classification models (and generally models that classify 'flat pane' objects), and it once I implemented it, it proved as a useful augmentation for this kind of paradigm!

Alternatives

The Albumentations library has this option for the analogous Rotate function, but I think having the feature here wouldn't be very difficult either.

Additional context

The most popular implementation for this type of transform just finds an inscribed rectangle with the largest possible area. Albumentations did that, and put the setting as a bool (and honestly, I think that option would more than adequate for us too).

For some niche use cases it might also be useful to add the constraint that the aspect ratio must remain constant. That is something that I used, so the setting could also be a LiteralString...? As you prefer, really!

If you'll allow me, there's even another thing which would actually be very useful for me, which is that we could take advantage of the fact that there are theoretically infinite optimal solutions for non-squares! (Think of it as the inscribed rectangle being able to 'slide around' the rotated one). This could prove useful if used as another random element in the augmentation transform, although I'm unsure right now on how that interface could be implemented 😅

Anyways, I have the implementations for all of these options lying around already, so please let me know if you would like me adding any of these new features to the library :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the RandomRotation transform and compare its intended behavior with the analogous Albumentations Rotate option. Clarify whether the scope is a boolean crop option, aspect-ratio preservation, or randomized placement of an inscribed rectangle. Done means the chosen interface removes black-corner padding while preserving the expected rotation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.