inputs = tf.keras.Input(shape=input_shape)
# apply data augmentation to the inputs
x = data_augmenter(inputs)
# data preprocessing using the same weights the model was trained on
x = preprocess_input(x)
output:
TypeError Traceback (most recent call last)
<ipython-input-41-11ffc7a7acb3> in <module>
----> 1 model2 = alpaca_model(IMG_SIZE, data_augmentation)
<ipython-input-40-a7e00bcc0585> in alpaca_model(image_shape, data_augmentation)
27
28 # apply data augmentation to the inputs
---> 29 x = data_augmenter(inputs)
30
31 # data preprocessing using the same weights the model was trained on
TypeError: data_augmenter() takes 0 positional arguments but 1 was given
how do i apply the data augmentation to inputs if it is not accepting any positional arguments?
You declare the function assigned to another variable without parameters first, and then you use that variable as you did here instead of the function directly.
# create the input layer (Same as the imageNetv2 input size)
inputs = tf.keras.Input(shape=input_shape)
# apply data augmentation to the inputs
x = data_augmentation
# data preprocessing using the same weights the model was trained on
x = preprocess_input(x)
but there is still error
WARNING:tensorflow:`input_shape` is undefined or non-square, or `rows` is not in [96, 128, 160, 192, 224]. Weights for input shape (224, 224) will be loaded as the default.
Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/mobilenet_v2/mobilenet_v2_weights_tf_dim_ordering_tf_kernels_1.0_224_no_top.h5
9412608/9406464 [==============================] - 0s 0us/step
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-16-11ffc7a7acb3> in <module>
----> 1 model2 = alpaca_model(IMG_SIZE, data_augmentation)
<ipython-input-15-4c90c4d7794f> in alpaca_model(image_shape, data_augmentation)
30
31 # data preprocessing using the same weights the model was trained on
---> 32 x = preprocess_input(x)
33
34 # set training to False to avoid keeping track of statistics in the batch norm layer
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/applications/mobilenet_v2.py in preprocess_input(x, data_format)
500 @keras_export('keras.applications.mobilenet_v2.preprocess_input')
501 def preprocess_input(x, data_format=None):
--> 502 return imagenet_utils.preprocess_input(x, data_format=data_format, mode='tf')
503
504
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/applications/imagenet_utils.py in preprocess_input(x, data_format, mode)
117 else:
118 return _preprocess_symbolic_input(
--> 119 x, data_format=data_format, mode=mode)
120
121
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/applications/imagenet_utils.py in _preprocess_symbolic_input(x, data_format, mode)
261 """
262 if mode == 'tf':
--> 263 x /= 127.5
264 x -= 1.
265 return x
TypeError: unsupported operand type(s) for /=: 'Sequential' and 'float'
Test failed
Expected value
['Functional', (None, 5, 5, 1280), 2257984]
does not match the input value:
['Functional', (None, None, None, 1280), 2257984]
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-19-0346cb4bf847> in <module>
10 ['Dense', (None, 1), 1281, 'linear']] #linear is the default activation
11
---> 12 comparator(summary(model2), alpaca_summary)
13
14 for layer in summary(model2):
~/work/W2A2/test_utils.py in comparator(learner, instructor)
21 "\n\n does not match the input value: \n\n",
22 colored(f"{a}", "red"))
---> 23 raise AssertionError("Error in test")
24 print(colored("All tests passed!", "green"))
25
AssertionError: Error in test
Try to get the benefit of the search option to find similar threads, like this one. You may use keyword like “alpaca_model AssertionError: Error in test” or any other keywords. Update us here.
I have access to my course materials now. To answer the original question, this line of code should reference data_augmentation(…), not data_augmenter(…).
data_augmentation(…) is the helper function that is defined in this cell: