Closed sameerkhurana10 closed 3 years ago
I have the same problem. I don't get it. I'm not changing the size of the array, but I still get this error. Logged BEFORE/AFTER are using get_shape()
Doing it with TensorFlow works. char_emb_reshape = tf.reshape(char_emb, [-1, 20, 15*100])
BEFORE char_emb (?, 20, 15, 100) AFTER char_emb (?, 20, 1500)
But with Keras, "total size of new array must be unchanged" error:
char_emb_reshape = Reshape((-1, 20, 15*100))(char_emb)
And apparently it wants me to change the '20' dimension to a '1', which makes the error go away but leaves me with an array that I don't know what to do with.
The output dim of the embedding layer isn't right. I'm guessing this is what makes Reshape throw the error. model.output.shape
and model.output_shape
do not have the same dimension.
model = Sequential()
model.add(Embedding(257, 128, input_shape=(50, 5)))
print model.output_shape # => (None, 50, 128) should be (None, 50, 5, 128)
print model.ouput.shape # => TensorShape([Dimension(None), Dimension(50), Dimension(5), Dimension(128)])
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.
I have the same problem. As @suryasumukh said, "the output dim of the embedding layer isn't right".
model.add(Embedding(257, 128, input_shape=(50, 5)))
print model.output_shape # => (None, 50, 128) should be (None, 50, 5, 128)
print model.ouput.shape # => TensorShape([Dimension(None), Dimension(50), Dimension(5), Dimension(128)])
model.add(Reshape(50,2,64)) # this would work
model.add(Reshape(50,5*128,1)) # this would give the error "total size should not be changed"
However, although that reshape can work, it gives an error with "Incompatible shapes" at the end. I have no idea how to workaround. It seems that this may be a bug in keras.
Trying to Reshape the Output from the Embedding Layer but unsuccessful. below is the code:
Error that I get at the Reshape step:
What am I doing wrong?