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

[efficientnet/autoaugment/contrast] Op Bug #825

Open
swghosh opened this issue Aug 13, 2020 · 0 comments
Open

[efficientnet/autoaugment/contrast] Op Bug #825

swghosh opened this issue Aug 13, 2020 · 0 comments

Comments

@swghosh
Copy link

swghosh commented Aug 13, 2020

It seems to me that the implementation of contrast enhancement using TF ops (as per it's PIL equivalent) in the EfficientNet codebase has a small bug associated with it which results in incorrect degenerate.

def contrast(image, factor):
"""Equivalent of PIL Contrast."""
degenerate = tf.image.rgb_to_grayscale(image)
# Cast before calling tf.histogram.
degenerate = tf.cast(degenerate, tf.int32)
# Compute the grayscale histogram, then compute the mean pixel value,
# and create a constant image size of that value. Use that as the
# blending degenerate target of the original image.
hist = tf.histogram_fixed_width(degenerate, [0, 255], nbins=256)
mean = tf.reduce_sum(tf.cast(hist, tf.float32)) / 256.0
degenerate = tf.ones_like(degenerate, dtype=tf.float32) * mean
degenerate = tf.clip_by_value(degenerate, 0.0, 255.0)
degenerate = tf.image.grayscale_to_rgb(tf.cast(degenerate, tf.uint8))
return blend(degenerate, image, factor)

Is it intended?

Seems like the following line might need some change!

mean = tf.reduce_sum(tf.cast(hist, tf.float32)) / 256.0

I'd run some tests on this op by comparing the resulting values with its PIL equivalent which can be found in this Colab notebook.

(after changing the said line, tests could pass)

/cc: @tanzhenyu, @mingxingtan, @saberkun

swghosh added a commit to swghosh/tensorflow-tpu that referenced this issue Aug 13, 2020
* fix degenerate image of efficientnet/autoaugment/contrast
@swghosh swghosh mentioned this issue Aug 13, 2020
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

1 participant