BUG: `RandomContrast` slows down training 6-fold
See original GitHub issueAugmentation will obviously slow down training, but it shouldn’t be a 6-fold slowdown. This happens with the RandomContrast
layer, which makes the training per epoch grow from ~100s to ~600s.
I’d share a Colab notebook but there seems to be an issue with KerasCV on Colab on importing, so here are the steps to reproduce:
import keras_cv
print(f'KerasCV version {keras_cv.__version__}')
import tensorflow as tf
print(f'TF version {tf.__version__}')
from tensorflow import keras
print(f'Keras version {keras.__version__}')
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar10.load_data()
aug = keras.Sequential([
keras_cv.layers.RandomContrast(factor=0.2)
])
model = keras.Sequential([
keras.layers.InputLayer(input_shape=(32, 32, 3)),
aug,
keras.applications.EfficientNetV2B0(weights=None, include_top=False),
keras.layers.GlobalAveragePooling2D(),
keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
model.fit(x_train, y_train)
model = keras.Sequential([
keras.layers.InputLayer(input_shape=(32, 32, 3)),
keras.applications.EfficientNetV2B0(weights=None, include_top=False),
keras.layers.GlobalAveragePooling2D(),
keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
model.fit(x_train, y_train)
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:17 (11 by maintainers)
Top Results From Across the Web
In Tensorflow, adding data augmentation layers to my keras ...
Adding the data_augmentation layer to model slows down training by 13x. Am I using the keras preprocessing layers correctly?
Read more >tf.keras.layers.RandomContrast | TensorFlow v2.11.0
A preprocessing layer which randomly adjusts contrast during training. ... independently for each channel of each image during training.
Read more >lipiodol contrast medium: Topics by Science.gov
Behind the Lipiodol, build-down effect with FF beam was larger than FFF beam because FF beam contained more high energy electrons.
Read more >New strategy for image and video quality assessment
General full-reference (FR) QA criteria such as peak signal-to-noise ratio (PSNR) and mean squared error (MSE) do not accord well with human ...
Read more >Domain Adaptation and Representation Transfer and Medical ...
residual block with two convolutions in between each down-sampling layer. ... training signal, that is the prediction error of future anatomical factors.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It is
contrast_factor
in this example but it is just a case of a more general issue. Just in April the list in Keras-CV was already quite long: https://github.com/tensorflow/tensorflow/issues/55639#issuecomment-1112227581And this will happen every time you will want to randomize an arg, within the batch, of an Op where that arg is scalar by the TF API design.
Then we could tell that it is a TF issue and we don’t care but who have really the resources to change all these API/ops/kernels in TF for your new design needs?
At the same time Keras is no more a multi backed library, users are impacted directly by the performance issues we have with this design and they cannot switch to an alternative “backend”. So the separation logic between Keras issues and TF issues in many cases doesn’t make sense by an user point of view.
So a limit of your within the batch randomization policy it is going to impact directly the Keras-cv user base and the claim that it is a TF (team?) issue it does not solve anyone’s problems.
At the same time we don’t have (public?) experimental data about the accuracy/epochs gain related to the choice to randomize an augmentation over each batch element that it is the design choice that created all these performance overhead considering the TF API design we currently have on many Ops.
@atlanticstarr1 We have started a thread at https://github.com/tensorflow/tensorflow/issues/55639#issuecomment-1233073292
You could try to ping there.