Week 2 - Tensorflow question (Alpaca classifier)

Hello,

for the assignment, we’re doing data augmentation, using the methods RandomFlip and RandomRotation, imported from tensorflow.keras.layers.experimental.preprocessing.

My question is the following: how are we supposed to know that we can’t use the method directly from tf.keras.layers? Because it seems from this doc that the method exists, and also, when I go to this doc page (corresponding to tensorflow.keras.layers.experimental.preprocessing) and then click on the RandomFlip class, it throws me back to tensorflow.keras.layers documentation…
Finally, I did try in the code of the assignment to use data_augmentation.add(tf.keras.layers.RandomRotation(0.2)) instead of data_augmentation.add(tf.keras.layers.experimental.preprocessing.RandomRotation(0.2)), and I get the error message AttributeError: module ‘tensorflow.keras.layers’ has no attribute ‘RandomRotation’ which I totally don’t understand, since it appears on the page of ‘tensorflow.keras.layers’.

I think my problem is that I can’t properly interpret the documentations, tha’s why I need your help!

Thank you :slight_smile:

Hi, @Goudout!

Beware of the documentation and the package version you are using. The experimental module is usually the “sandbox” in which developers try new implementations that are later release in the “common modules” like the default tf.keras.layers.
For instance, tf <2.6 only had the random rotation in experimental. It was first introduced in the tf v2.6 in tf.keras.layers

Right! The courses here are more than a year old (last major update in April 2021), so the versions of things are not current. You can see what version is being used in a given notebook this way:

print(f"TF version {tf.__version__}")

Things change pretty fast in this space …

Ooooh okay!

So I was not totally crazy :smiley: Thanks for you answers! Now I can safely browse the documentation of tf v2.3, and indeed, there’s no RandomRotation or RandomFlip in tf.keras.layers for this version.

Everything is right again! Thank you :+1:

Élie