keras-team / keras-preprocessing

Utilities for working with image data, text data, and sequence data.
Other
1.02k stars 444 forks source link

Add scale param to brightness and fix some docs #300

Closed Smankusors closed 4 years ago

Smankusors commented 4 years ago

Summary

This add an option to not scale the image (to 0 - 255) when doing random_brightness. This also might fixes #114.

Code example :

brightness_range = [0.5, 2]
image = random_brightness(image, brightness_range, True) #for enable scale
image = random_brightness(image, brightness_range, False) #for disable scale

#or alternatively
image = random_brightness(image, brightness_range, scale=True)
image = random_brightness(image, brightness_range, scale=False)

#or call the apply_brightness_shift directly
image = apply_brightness_shift(image, 0.5, scale=True)

Related Issues

There's no documentation about this on keras.io...

PR Overview

Dref360 commented 4 years ago

Hello, thanks for the PR, Could you add some tests that check that the new behavior is respected?

Smankusors commented 4 years ago

Hello, thanks for the PR, Could you add some tests that check that the new behavior is respected?

hmm currently I'm on Windows. But I have trouble running tests. I got

E   ModuleNotFoundError: No module named 'resource'

I think I will need to use Linux to run tests? I already tried pip3 install resource but still module not found 😢

Smankusors commented 4 years ago

anyway, what do you think about this?

def test_random_brightness_scale():
    img = np.ones((1, 1, 3)) * 128
    zeros = np.zeros((1, 1, 3))
    assert np.array_equal(img, affine_transformations.random_brightness(img, [1, 1], scale=False))
    assert np.array_equal(zeros, affine_transformations.random_brightness(img, [1, 1], scale=True))
Dref360 commented 4 years ago

Yeah looks good. Yup you need UNIX to run the rest. We should probably change that.

Smankusors commented 4 years ago

alright, I run the tests on the Google Colab 🤣

And I made little changes so the tests can run successfully.