I think that the tensorflow version of K.batch_dot is inconsistent with the documentation. Consider the following script:
import keras.backend as K
import numpy as np
x = K.placeholder(shape=(None,100))
y = K.placeholder(shape=(None,100))
res = K.batch_dot(x,y,axes = 1)
f = K.function([x,y], [res])
xv = np.random.random(size = (32, 100))
yv = np.random.random(size = (32, 100))
dots = []
for i in range(32):
dots.append(np.dot(xv[i,:], yv[i,:]))
resv = f([xv,yv])[0].flatten()
dots = np.array(dots)
print(resv.shape)
print(dots.shape)
assert np.allclose(resv, dots)
This runs fine with the theano backend, but the assertion fails for the tensorflow backend.
>>> import tensorflow as tf
>>> tf.__version__
'0.12.0-rc0
>>> import theano
>>> theano.__version__
'0.9.0dev4.dev-ad1310c88830ed96119194c4f2da22b9b37c7622'
>>> keras.__version__
'1.1.2'
Please make sure that the boxes below are checked before you submit your issue. Thank you!
[x] Check that you are up-to-date with the master branch of Keras. You can update with:
pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps
[x] If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with:
pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
[x] Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).
I think the problem is that tf.batch_matmul only supports tensors that are at least 3D, even though the keras documentation doesn't mention this.
TF and theano might have different behaviors. Related issue here #2742
I saw the related issue, but my sense was that discussion concluded with a fix. At the least, K.batch_dot should mention that the tf backend only supports 3D+ tensors. However, I think it's possible to make these consistent, though I don't know what behavior is actually expected so I can't do a PR myself without that knowledge.
K.batch_dot should mention that the tf backend only supports 3D+ tensors
Now included in 52c30ac.
@keunwoochoi Is it? I don't see it there. That commit only touches common.py I think, which is not where batch_dot lives.
Oh, sorry for confusion. I'm working on it but yet PR'ed.
On 10 Dec 2016, at 21:19, Jack Hessel notifications@github.com wrote:
@keunwoochoi Is it? I don't see it there. That commit only touches common.py I think, which is not where batch_dot lives.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
Thanks a bunch! :-)
Added documentation in #4677 address this issue
It's been brought to my attention that my Keras implementation of Shen et al. (2014) does not work for mini-batch training when using TensorFlow as the backend, and I believe it's related to this issue. Using the latest version of Keras does not fix the error.
(for future reference #5132 I think fixes this, though a longer-term solution other than raising an error would probably be better)