Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layer called with an input that isn't a symbolic tensor keras

Tags:

I'm trying to pass the output of one layer into two different layers and then join them back together. However, I'm being stopped by this error which is telling me that my input isn't a symbolic tensor.

Received type: <class 'keras.layers.recurrent.LSTM'>. All inputs to the layers should be tensors. 

However, I believe I'm following the documentation quite closely: https://keras.io/getting-started/functional-api-guide/#multi-input-and-multi-output-models

and am not entirely sure why this is wrong?

net_input = Input(shape=(maxlen, len(chars)), name='net_input') lstm_out = LSTM(128, input_shape=(maxlen, len(chars)))  book_out = Dense(len(books), activation='softmax', name='book_output')(lstm_out) char_out = Dense(len(chars-4), activation='softmax', name='char_output')(lstm_out)  x = keras.layers.concatenate([book_out, char_out]) net_output = Dense(len(chars)+len(books), activation='sigmoid', name='net_output')  model = Model(inputs=[net_input], outputs=[net_output]) 

Thanks

like image 969
tryingtolearn Avatar asked Jun 30 '17 17:06

tryingtolearn


People also ask

Do you need an input layer keras?

It is generally recommend to use the Keras Functional model via Input , (which creates an InputLayer ) without directly using InputLayer . When using InputLayer with the Keras Sequential model, it can be skipped by moving the input_shape parameter to the first layer after the InputLayer .

What is a keras symbolic tensor?

1. According to the tensorflow.org website, "A Tensor is a symbolic handle to one of the outputs of an Operation. It does not hold the values of that operation's output, but instead provides a means of computing those values in a TensorFlow tf.

What is TensorFlow layer dense?

dense() is an inbuilt function of Tensorflow. js library. This function is used to create fully connected layers, in which every output depends on every input. Syntax: tf.layers.dense(args)


2 Answers

It looks like you're not actually giving an input to your LSTM layer. You specify the number of recurrent neurons and the shape of the input, but do not provide an input. Try:

lstm_out = LSTM(128, input_shape=(maxlen, len(chars)))(net_input) 
like image 91
Aditya Gune Avatar answered Sep 25 '22 18:09

Aditya Gune


I know, documentation can be confusing, but Concatenate actually only requires "axis" as parameter, while you passed the layers. The layers need to be passed as argument to the result of it as follow:

Line to modify:

x = keras.layers.concatenate([book_out, char_out])

How it should be:

x = keras.layers.Concatenate()([book_out, char_out])

like image 23
Alessio Mauro Avatar answered Sep 25 '22 18:09

Alessio Mauro