Transfer_learning_with_MobileNet_v1 Exercise 1 - data_augmenter

Hi folks,
I have written this code for data augmentation:
def data_augmenter():
‘’’
Create a Sequential model composed of 2 layers
Returns:
tf.keras.Sequential
‘’’
### START CODE HERE
data_augmentation = tf.keras.Sequential([
data_augmentation.add.RandomFlip(‘horizontal’),
data_augmentation.add.RandomRotation(0.2)
])
### END CODE HERE

return data_augmentation

But I received this error:
UnboundLocalError Traceback (most recent call last)
in
----> 1 augmenter = data_augmenter()
2
3 assert(augmenter.layers[0].name.startswith(‘random_flip’)), “First layer must be RandomFlip”
4 assert augmenter.layers[0].mode == ‘horizontal’, “RadomFlip parameter must be horizontal”
5 assert(augmenter.layers[1].name.startswith(‘random_rotation’)), “Second layer must be RandomRotation”

in data_augmenter()
9 ### START CODE HERE
10 data_augmentation = tf.keras.Sequential([
—> 11 data_augmentation.add.RandomFlip(‘horizontal’),
12 data_augmentation.add.RandomRotation(0.2)
13 ])

UnboundLocalError: local variable ‘data_augmentation’ referenced before assignment

what should I do?
I know the solution to this error is to assign a value to ‘data_augmentation’, but based on the template, it shows that the code should be in 3 lines.

1 Like

In this exercise, you don’t need square brackets or commas for the Sequential model.

This is because we’re using the ‘.add’ method, instead of creating a static list.

2 Likes

Thank you, but when I write the code in the below syntax I confronted with a mentioned error. what’s wong with RadomFlip? I wrote like Tensorflow setup in tuturial.
code:
data_augmentation = tf.keras.Sequential
data_augmentation.add.RadomFlip(‘horizontal’)
data_augmentation.add.RandomRotation(0.2)

error:
AttributeError Traceback (most recent call last)
in
----> 1 augmenter = data_augmenter()
2
3 assert(augmenter.layers[0].name.startswith(‘random_flip’)), “First layer must be RandomFlip”
4 assert augmenter.layers[0].mode == ‘horizontal’, “RadomFlip parameter must be horizontal”
5 assert(augmenter.layers[1].name.startswith(‘random_rotation’)), “Second layer must be RandomRotation”

in data_augmenter()
9 ### START CODE HERE
10 data_augmentation = tf.keras.Sequential
—> 11 data_augmentation.add.RadomFlip(‘horizontal’)
12 data_augmentation.add.RandomRotation(0.2)
13 ### END CODE HERE

AttributeError: ‘function’ object has no attribute ‘RadomFlip’

Hi @efanrzee
It seems you are facing a syntax error.
In addition to what @TMosh said, you can make use of the pointed keras doc link and check how to correctly call the two data augmentation functions.

I saw the doc file and write the code in this form:
data_augmentation = tf.keras.Sequential()
data_augmentation.add()(RandomFlip=‘horizontal’),
data_augmentation.add()(RandomRotation=0.2)

but I recieved this error?!
what should i do?

@efanrzee , you can check this link

Your syntax for add is wrong also: you don’t need those extra empty parentheses. Also the point is that RandomFlip and RandomRotation are functions which take arguments, right?

Note that they literally wrote out the correct invocation of those two functions for you in the instructions. Now all you have to do is figure out how to pass them to the Sequential “add” method.

3 Likes

Thanks. I found the soloution