Reputation: 374
I am learning Keras and trying to build my layers, so I build a simple Lambda layer which just calculates the mean of the inputs.
TypeError occurred in line 4 when I add this layer to a sequential model. Here is my code:
mean_layer = keras.layers.Lambda(lambda x: tf.reduce_mean(x))
model = keras.models.Sequential()
model.add(keras.layers.InputLayer(input_shape=[10]))
model.add(mean_layer())
model.summary()
TypeError: __call__() missing 1 required positional argument: 'inputs'
However, if I use the functional model, the thing goes well and I get the expected output.
input = keras.layers.Input(shape=[10])
output = mean_layer(input)
model = keras.models.Model(inputs=[input], outputs=[output])
model.summary()
Did I build the model in the wrong way when I use the sequential API? Thanks
Upvotes: 0
Views: 206
Reputation: 56357
Yes you are doing it wrong, it should be like this:
model.add(mean_layer)
Upvotes: 1