-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CutAndPaste #1297
Closed
Closed
Add CutAndPaste #1297
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry for the additional correction. |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
About PR
This PR tries to implement Cut And Paste Augmentation "Simple Copy-Paste is a Strong Data Augmentation Method for Instance Segmentation".
It includes multiple image blending methods given in "Poisson Image Editing".
See also: #1225
Blending Demo
The
A.paste
function supports the following four image blending method.Figure: The result of different methods: GAUSSIAN, NORMAL_CLONE, MIXED_CLONE, MONOCHROME_TRANSFER (Left to right)
CutAndPaste Transform Demo
This is an example of the CutAndPaste Transform usage.
It requires paste_image_dir parameters, which include objects to be pasted. The transform randomly selects multiple files (objects) from the paste_image_dir directory. So in this version, the user needs to prepare images so that each image includes a single object.
The transform also requires a function parameter
get_label_from_path
, which returns label information from a given object file path. Since the transform could not know the label information of randomly selected objects, theget_label_from_path
is used to extract label information from the object file path. This means that the user should include label information in the object path. And provide the function to extract the information from the path.The followings are the results of different trials with a fixed base image.
Sample Notebook
You can reproduce the same result in this notebook on Colab:
https://colab.research.google.com/drive/1sFCAhS8FTyp7dLIdJgUJwbB5JnGBYoq3
Note and Limitation
1. The user needs to prepare object files as RGBA PNG images.
As described above, the user needs to prepare object files (images to be pasted) in advance.
2. The object file path should include label information
Since the transform identifies the label information from the object path, the user needs to include label information in the object path and provide the function
get_label_from_path
as a parameter, which extracts label information from the path.For example, when the object path is like a
path/to/object/{object_id}_{label_id}.png
, aget_label_from_path
could be:3. Returned masks become binary masks
Even if the input masks are non-binary masks, the transformed masks are binary masks. (The values are 0 or 1)
I think I can remove this limitation with extra work.
About Implementation
1. A new rotation method,
rotate_bound
is added.A new rotation function,
rotate_bound
is introduced to rotate object images.While the standard
rotate
function causes unwanted crops, therotate_bound
expands the input's shape depending on the rotation. See the following examples.2. Augmentation to the masks are actually done inside the
get_params_dependent_on_targets
Augmented masks are needed to calculate the bbox augmentation. But I could not find a better place where both the bboxes and masks are accessible except for
get_params_dependent_on_targets
.So I implement the masks augmentation in the
get_params_dependent_on_targets