I am playing with Keras Code. When i write the code like this,
model = Sequential()
model.add(Dense(64, activation='relu', input_shape=(784,) ))
model.add(Dense(128, activation='relu'))
model.add(Dense(784, activation='relu'))
model.compile(optimizer='adam', loss='mean_squared_error')
it works without any trouble. But If achieve this by passing the previous layer to next layer as a parameter, then i get the error.
layer1 = Dense(64, activation='relu', input_shape=(784,) )
layer2 = Dense(128, activation='relu') (layer1)
layer3 = Dense(784, activation='relu') (layer2)
model = Model(layer1, layer3)
model.compile(optimizer='adam', loss='mean_squared_error')
Below is the error
ValueError: Layer dense_2 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.core.Dense'>. Full input: [<keras.layers.core.Dense object at 0x7f1317396310>]. All inputs to the layer should be tensors.
How can i fix this?