Why Am I Getting This Valueerror?
Solution 1:
Here we are since you know MatMul
operations is classic Matrix Multiplication operation so if we want to multiply two matrices, M1
and M2
, with shape AxB
and BxC
respectively, we should have same shapes B
when we want to multiplication and in result:
M1 x M2
results in a matrix R
with shape AxC
.
So in your case you try to multiplication two matrices with shape 4x1
and 4x32
, so it throws an error of shape problem, you should transpose the first tensor, then you have:
1x4
MatMul 4x32
result in 1x32
matrix.
Your code here:
h_layer1 = tensorflow.add(tensorflow.matmul(input_layer, w_layer1),b_layer1)
Use like this:
h_layer1 = tensorflow.add(tensorflow.matmul(tf.transpose(input_layer), w_layer1),b_layer1)
For more detailed answer, you can print the shapes of tensors in each stage like:
print h_layer1.get_shape()
And see the shapes, then you can modify your shapes and inputs.
Good Luck.
Post a Comment for "Why Am I Getting This Valueerror?"