Skip to content Skip to sidebar Skip to footer

ValueError: Output Tensors To A Model Must Be The Output Of A TensorFlow Layer With Tf.keras Lambda Layer

I'm trying to use the output of a tf.keras.layers.Lambda function as the last layer in a tf.keras model, but tf is interpreting the lambda layer's output as a Tensor(as opposed to

Solution 1:

test is not coming from anywhere considered a Keras layer.

If test intended to be a model's input, it must be:

test = Input(tensor=tf.constant([1.0], shape=(2,2))
#there may be some implications with shape, batch size and other stuff....

As a model with two inputs, you should remember to add it when defining the Model.

If you want a constant value to be used without it being an input, you must not pass it as the "input" of a layer. You just refer to it from inside the layer, or you create it inside the layer.


If you just want to test your Lambda layer:

inp = Input((2,2))
out = mullayer(inp)
testModel = Model(inp,out)

testModel.predict(np.ones((1,2,2)))

Post a Comment for "ValueError: Output Tensors To A Model Must Be The Output Of A TensorFlow Layer With Tf.keras Lambda Layer"