I want to build a customized layer in keras to do a linear transformation on the output of last layer. For example, I got an output X from last layer, my new layer will output X.dot(W)+b.
The shape of W is (49,10)
, and the shape of X should be (64,49)
, the shape of b is (10,)
However, the shape of X is (?, 7, 7, 64)
, when I am trying to reshape it, it becomes shape=(64, ?)
. What is the meaning of question mark? Could you tell me a proper way to do linear transformation on the output of last layer?
The question mark generally represents the batch size, which has no effect on the model architecture.
You should be able to reshape your
X
withkeras.layers.Reshape((64,49))(X)
.You can wrap arbitrary tensorflow operations such as
tf.matmul
in a Lambda layer to include custom layers in your Keras model. Minimal working example that does the trick: