Closed mertorelio closed 2 years ago
Data augmentation is often random (unless there's a random seed set)
Could you post your code/pictures of what's going on?
Is the augmentation working as you expected with your target image?
code is same as the notebook but my output like this.When i use ' Open İn Colab' link, i have same issue. Something Something seems wrong with this title "Adding data augmentation right into the model"
Hello, I'm having the same problem. The images are not being augmented. I found that the experimental commands had now been moved to the tf.keras.layers
section and I changed them to see if that would work, but again no. I tried restarting the kernel multiple times, but it stays the same.
I tried it in a new notebook with another photo not in the set, and it worked. I don't understand what's happening
Wow, thank you all for sharing your issues.
Looks like it's an issue with the newly updated TensorFlow 2.8.0 (as it doesn't look like an issue with TensorFlow 2.7.0).
The layers don't look like they're working as expected.
See the issue posted on the official TensorFlow GitHub from @beneyal here: https://github.com/tensorflow/tensorflow/issues/55113
And his example Colab notebook showcasing the problem here: https://colab.research.google.com/drive/14K2-OgcPjkHRk2aeOMnW1CnaThow6Fia?usp=sharing
The issue seems to be with the recent update to TensorFlow 2.8.0.
As of 08 March 2022, Google Colab uses TensorFlow 2.8.0 by default.
But you can fix the issue (temporarily until TensorFlow releases an update to 2.8.x) by downgrading Google Colab to 2.7.0 like so:
!pip install tensorflow==2.7.0
After installing TensorFlow 2.7.0 you may have to restart your runtime and re-import TensorFlow.
Check that the version is 2.7.0:
# After installing TensorFlow 2.7.0
import tensorflow as tf
tf.__version__
>>> '2.7.0'
Using TensorFlow 2.7.0, the code should run as expected. An update from the TensorFlow team should come to fix it soon.
See an example notebook of doing so here: https://colab.research.google.com/drive/1XrJYpex26GLbn4tVK78cupWm_Ds4CHtR?usp=sharing
when I tried your solution , i have some issue with GPU runtime (like DNN library is not found). I change my runtime to TPU and rerun everything now it seems good. Thank u for help.
Same here, it now says that there is an error
This makes that using a GPU is not possible and therefore doing anything takes an enormous amount of time. It's taking around 130s per epoch training model 2...
Hello, i had the same problem. But after reading a couple of minutes through the TensorFlow documentation i found a solution for this issue. In TensorFlow version 2.8.0 the Keras preprocessing layers, like tf.kersa.layers.RandomRotation
, tf.keras.layers.RandomFlip
or tf.keras.layers.RandomZoom
only influences the image during training. So during inference time those layers will not change the input as long as you call the layer with training =True
. When calling the data_augmentation
model you have to set training=True
. This works for me. Hope, it will help you too.
Hello, i had the same problem. But after reading a couple of minutes through the TensorFlow documentation i found a solution for this issue. In TensorFlow version 2.8.0 the Keras preprocessing layers, like
tf.kersa.layers.RandomRotation
,tf.keras.layers.RandomFlip
ortf.keras.layers.RandomZoom
only influences the image during training. So during inference time those layers will not change the input as long as you call the layer withtraining =True
. When calling thedata_augmentation
model you have to settraining=True
. This works for me. Hope, it will help you too.
thanks, works for me too.
augmented_img = data_augmentation(img,training=True)
Added an example notebook with a fix here: https://colab.research.google.com/drive/1qhCnJZgYAPzSnjq-PhB4fM5CtvqS34UP?usp=sharing
The main fix (for now), until TensorFlow fixes things on their end, is to pass training=True
to a data augmentation model.
See here:
augmented_img = data_augmentation(img, training=True)
This should ensure your images get augmented.
This is because data augmentation is only intended to work during training and not during testing.
Oh.. it helped me!!! Multumesc
augmented_img = data_augmentation(img, training=True)
When i fit Model_1 after fixing the data augmentation, am getting this code warnings as in the pics uploaded yet my code is as given by MrDBurke @mrdburke
input_shape = (224, 224, 3) base_model = tf.keras.applications.EfficientNetB0(include_top=False) base_model.trainable = False
inputs = layers.Input(shape=input_shape, name="input_layer")
x = data_augmentation(inputs, training=True) print(f"Shape after passing inputs through base model: {x.shape}")
x = base_model(x, training=False)
x = layers.GlobalAveragePooling2D(name="global_average_pooling")(x)
outputs = layers.Dense(10, activation="softmax", name="output_layer")(x)
model_1 = keras.Model(inputs, outputs)
model_1.compile(loss="categorical_crossentropy", optimizer=tf.keras.optimizers.Adam(), metrics=["accuracy"])
model_1.fit(train_data_1_percent, epochs=5, steps_per_epoch=len(train_data_1_percent), validation_data=test_data, validation_steps=int(0.25 * len(test_data)), callbacks=[c
reate_tensorboard_callback(dir_name="transfer_learning", experiment_name="1_percent_data_aug")])
@raduga256 Can you share the full code or the notebook? I think there is an error of input shape, it says that the input shape is (None,None,3)
@raduga256 Can you share the full code or the notebook? I think there is an error of input shape, it says that the input shape is (None,None,3) @ishandandekar GoogleColab Link: https://colab.research.google.com/github/raduga256/tensorflow-dp-learning-dev/blob/main/05_transfer_learning_in_tensorflow_fine_tuning.ipynb
Thank You
Solution Code:
data_augmentation_sample = tf.keras.Sequential([ tf.keras.layers.Resizing(224,224), tf.keras.layers.experimental.preprocessing.Rescaling(1/255.0), tf.keras.layers.RandomFlip(mode = "horizontal"), tf.keras.layers.RandomRotation(0.2), tf.keras.layers.RandomZoom(0.2), tf.keras.layers.RandomHeight(0.2), tf.keras.layers.RandomWidth(0.2)], name = "data_augmentation")
for images, labels in train_data_10_percent.take(1): firstimage = images[0] #(Can be changed from 0 to 31 for different images)_
first_image = tf.cast(tf.expand_dims(first_image, 0), tf.float32)
#After running this code I went on the Tensorflow website and adapted one of the examples they had given
plt.figure(figsize=(10, 10))
for i in range(16): augmented_image = data_augmentation_sample(first_image, training = True) ax = plt.subplot(4, 4, i + 1) plt.imshow(augmented_image[0]) plt.axis("off")
This shows the sample of the augmented data in a more detailed manner and also when the model if fitted using the sequential API there are no errors also coming up as @raduga256 had mentioned.
Still gotta update here, For this particular section, the training=True to run the data augmentation remains.
i have same code this notebook but my image is not augmented same as before