From e53ed45a19222d90ff6654489e6bf2f0ef9636ad Mon Sep 17 00:00:00 2001 From: Swarup Ghosh Date: Fri, 14 Aug 2020 02:57:44 +0530 Subject: [PATCH] Fixes #825 * fix degenerate image of efficientnet/autoaugment/contrast --- models/official/efficientnet/autoaugment.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/models/official/efficientnet/autoaugment.py b/models/official/efficientnet/autoaugment.py index 0226f75f0..c3a36fc93 100644 --- a/models/official/efficientnet/autoaugment.py +++ b/models/official/efficientnet/autoaugment.py @@ -206,9 +206,10 @@ def contrast(image, factor): # 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 + hist = tf.cast(hist, tf.float32) + mean = tf.reduce_sum(tf.cast(degenerate, tf.float32)) / tf.reduce_sum(hist) + mean = tf.clip_by_value(mean, 0.0, 255.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)