awslabs / keras-apache-mxnet

[DEPRECATED] Amazon Deep Learning's Keras with Apache MXNet support
https://github.com/awslabs/keras-apache-mxnet/wiki
Other
290 stars 65 forks source link

Result from K.equal has wrong shape? #174

Closed y-lu closed 6 years ago

y-lu commented 6 years ago

Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or join the Keras Slack channel and ask there instead of filing a GitHub issue.

Thank you!

Here's how to reproduce the problem:

import mxnet as mx, keras.backend as K

a = mx.nd.ones(3)

a.shape # return (3,) as expected mx.nd.equal(a,a).shape # return (3,) as expected

K.equal(a,a).shape # returns (3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), which is wrong

The same problem happens with other comparison operators (greater, etc.)

roywei commented 6 years ago

@y-lu thanks for the issue, I was able to reproduce, we will take a look.

In general, we should not pass mxnet nd arrays into Keras operator. mxnet nd arrays is only used in the backend and hidden from user. Please use numpy arrays as inputs.

a = np.ones(3)
K.equal(a, a).shape 
>>>(3,)
kalyc commented 6 years ago

Closing this issue. @y-lu please feel free to re-open if you have any other questions.