Week1 assignment 2 error - Inputs to a layer should be tensor

I am getting below error from convolutional_model…


TypeError Traceback (most recent call last)
in
----> 1 conv_model = convolutional_model((64, 64, 3))
2 conv_model.compile(optimizer=‘adam’,
3 loss=‘categorical_crossentropy’,
4 metrics=[‘accuracy’])
5 conv_model.summary()

in convolutional_model(input_shape)
53 ## 6 neurons in output layer. Hint: one of the arguments should be “activation=‘softmax’”
54
—> 55 outputs = tfl.Dense(units=6, activation = “softmax”)(F)
56
57 # YOUR CODE ENDS HERE

c:\python37\venv\imageai\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in call(self, *args, **kwargs)
996 inputs = self._maybe_cast_inputs(inputs, input_list)
997
→ 998 input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
999 if eager:
1000 call_fn = self.call

c:\python37\venv\imageai\lib\site-packages\tensorflow\python\keras\engine\input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
199 # have a shape attribute.
200 if not hasattr(x, ‘shape’):
→ 201 raise TypeError('Inputs to a layer should be tensors. Got: s' (x,))
202
203 if len(inputs) != len(input_spec):

TypeError: Inputs to a layer should be tensors. Got: <tensorflow.python.keras.layers.core.Flatten object at 0x0000021D032B8C08>

outputs = tfl.Dense(units=6, activation = “softmax”)(F)
Try single-quotes around ‘softmax’.

And maybe your value for F is wrong.

Dear TMosh,
Thank for your reply.

It is my very first time using Tensorflow and thus I am not familiar with the usage function(paramters)(input). So i read the instructions in the notebook and take for granted. Now I realize that I need to add respective P2, A2, Z2, etc in each line. It run successfully.

Can some one explain me what is the usage function(parameters)(input) instead of function (input, parameters). The latter is what beginner level people like me are used to but not the former. Is it kind of decorator?

Best

1 Like