Commit 6f068c71 authored by Haoyu Zhang's avatar Haoyu Zhang Committed by Toby Boyd
Browse files

Explicit broadcast in image normalization for better performance (#6551)

With trivial model, it improves the data input pipeline throughput from 12.5K to 15K on a DGX1 V100 machine.
parent 1255d5b9
...@@ -148,7 +148,9 @@ def _mean_image_subtraction(image, means, num_channels): ...@@ -148,7 +148,9 @@ def _mean_image_subtraction(image, means, num_channels):
raise ValueError('len(means) must match the number of channels') raise ValueError('len(means) must match the number of channels')
# We have a 1-D tensor of means; convert to 3-D. # We have a 1-D tensor of means; convert to 3-D.
means = tf.expand_dims(tf.expand_dims(means, 0), 0) # Note(b/130245863): we explicitly call `broadcast` instead of simply
# expanding dimensions for better performance.
means = tf.broadcast_to(means, tf.shape(image))
return image - means return image - means
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment