Week 2 Assignment 2: alpaca_model() Preprocessing Input Error

While executing the alpaca_model function in the week 2 2nd assignment of the CNN course, I am getting the following error. I am not understanding why is this error. Kindly help.

TypeError: unsupported operand type(s) for /=: ‘Sequential’ and ‘float’

Please post the entire assert log.

Here you go –


TypeError Traceback (most recent call last)
in
----> 1 model2 = alpaca_model(IMG_SIZE, data_augmentation)

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’

I suspect there is an error in the ‘x’ value you’re passing to preprocess_input().

So the error might be in the previous line of code, where you apply data augmentation.

2 Likes

One possible error would be not passing an input to the data augmenter, so that the output value of that function is a sequential object and not a tensor. That would probably cause the error message you are showing.

1 Like

Dear Sir Paul and TMosh,

Yes, the error was in the data_augmentation step. I have been able to resolve it now. Thank you very much.

Thanks,
Naren Mohan

i have the same issue, i am trying to pass x to the data_agumentor for augmentation. it is giving this error of type error above

i tried to pass inputs to the data_augmentor, but it is not accepting any inputs, it is saying 0 positional arguments expected

whats the solution? i didnt understand

@saifkhanengr can you help on this?

Better if you start a new thread, this one has been idle for 2 years.

ok created