I'm trying to do matmul inside the keras graph and got AttributeError: 'NoneType' object has no attribute '_inbound_nodes' error
when compiling the model
from keras import backend as K
from keras.layers import Input, Dense, Reshape
mainInput = Input(shape=(10*10,))
x = Dense(10*10, activation='relu')(x)
x1 = Reshape((10, 10))(x)
x2 = Dense( 2 * 10, activation='relu')(x)
x2 = Reshape((2, 10))(x2)
added = K.dot(x2, x1)
out = Dense(2 * 10, activation='linear')(added)
optimizer = optimizers.adam(lr=0.001)
model = Model(inputs=[mainInput], outputs=[out])
model.compile(loss='mse', metrics = ['mae'], optimizer=optimizer)
What is the reason of this error?
All operations must be inside keras layers:
added = Lambda(lambda x: K.dot(x[1],x[0]))([x1,x2])
I think your Reshape
will fail, because you're trying to reshape (None, 10, 20)
into (None, 2, 10)
.