Skip to content
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

Non-random draw_grid #712

Open
cm107 opened this issue Aug 26, 2020 · 1 comment
Open

Non-random draw_grid #712

cm107 opened this issue Aug 26, 2020 · 1 comment

Comments

@cm107
Copy link

cm107 commented Aug 26, 2020

I can create a grid of images to show what happens to an image if you apply a particular augmentation with random parameters.
Example:

import cv2
from imgaug import augmenters as iaa

img = cv2.imread('cat.png')
aug = iaa.Sharpen(alpha=(0.0, 1.0), lightness=(1.0, 1.0))
grid_img = aug.draw_grid(images=[img], rows=5, cols=5)
cv2.imwrite('preview.png', img=grid_img)

This is convenient for getting a general idea of what the augmentation is doing, but it is hard to identify what the image will look like at the "strongest" augmentation setting, as well as what the image will look like at the "weakest" augmentation setting.
It would help me a lot when I'm tweaking each individual augmentation's parameters before training my model if I could see a grid whose cells are ordered from the "weakest" setting to the "strongest" setting. My ultimate goal is to ensure that the objects that I am training my model to detect is still identifiable by a human after augmentation.

I understand that it can get complicated to fit everything on one grid when there are multiple parameters to step through, but if you specify which parameter you want to look at I think it would be feasible.
For example:

aug = iaa.Sharpen(alpha=(0.0, 1.0), lightness=(0.0, 1.0))
grid_img = aug.draw_grid(
    images=[img],
    rows=5, cols=5,
    strength_dict={
        'alpha': 'weak',
        'lightness': 'variable'
    }
)

In the above example, the 'alpha' parameter would be fixed at the weak value 0.0, while the 'lightness' parameter would be stepped through in order from 'weakest' (0.0) to 'strongest' (1.0).

I realize that this can be done using brute force like this:

row_img_list = []
for val in [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]:
    aug = iaa.Sharpen(alpha=(0.0, 0.0), lightness=(val, val))
    aug_img = aug(images=[image])[0]
    row_img_list.append(aug_img)
row = cv2.hconcat(row_img_list)

But this feels too tedious, and it becomes a hassle when there are a lot of parameters that need to be looked at and compared.

Is there a more efficient and elegant way to achieve what I am looking for?

@jspaezp
Copy link

jspaezp commented Sep 18, 2020

I feel like you coul use imgaug.parameters.DeterministicList for this purpose.

https://imgaug.readthedocs.io/en/latest/source/api_parameters.html?highlight=choice#imgaug.parameters.DeterministicList

You could set the max and min parameters to the elements of the list and you would generate them one after another.
something like this perhaps ...

import cv2
from imgaug import augmenters as iaa
import imgaug.parameters as iap

test_params = iap.DeterministicList([0.0, 0.2, 0.4, 0.6, 0.8, 1.0])
aug = iaa.Sharpen(alpha=(0.0, 0.0), lightness=test_params )

row_img_list = aug(images = len(test_params)*[image])
row = cv2.hconcat(row_img_list)

let me know if this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants