0.12.5
Node v8.9.1
I am using Tensorflow.js to predict on a model I trained in Keras. However, when I feed in my 4-dimensional tensor I get the following error:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: dot support for x of rank 4 is not yet implemented: x shape = 32,1,1,100
I assume this means the functionality is not available yet to do tf.dot with a 4d vector. However, I am calling tf.model.predict so I guess tf.dot is called internally? Does this mean it is _impossible_ to run predictions on 4d vectors at this point? It just seems strange that I haven't been able to find anything about this on the web or in the docs...
If you want to reproduce the bug, here is a simple github project with my model and relevant code.
Otherwise, here is the relevant code:
noise_tensor.print(true)
generated_images = model.predict(noise_tensor) //error occours here
...and this is the print output of noise_tensor:
Tensor
dtype: float32
rank: 4
shape: [64,1,1,100]
values:
[ [ [[0.3799773 , -0.0252707, 0.0118336 , ..., 0.1703698 , -0.0649208, 0.2152225 ],]],
[ [[0.219656 , 0.2850143 , -0.1078744, ..., 0.1627689 , -0.0838831, -0.1112608],]],
[ [[-0.1295149, -0.08308 , 0.1872116 , ..., -0.2033772, -0.4184959, -0.3357461],]],
...
[ [[0.0029674 , 0.0422036 , 0.067896 , ..., 0.1368463 , 0.1122015 , -0.0395375],]],
[ [[0.043546 , -0.0281712, 0.0898769 , ..., 0.205565 , 0.1444133 , 0.0067788 ],]],
[ [[-0.1089588, -0.0161969, -0.0724337, ..., 0.1427118 , -0.2577117, 0.0013836 ],]]]
In my repository, I put the python code I used to train (and predict) my model with Keras. I'm not sure if it's relevant, but if you want to take a look, it's here.
Looks like that error message is coming from the dot() function in tfjs_backend.ts in tfjs-layers FYI @caisq @bileschi @ericdnielsen. Thanks!
I'm able to reproduce the problem, working on adding the missing nd mat feature
FYI @98mprice , in the mean time if you are interested in a hack to keep you going forward, you can see how the 3d multiplication for 'x' is special cased, reshaping to a 2d, multiplying and reshaping back. This might work as a temporary splint while the more general fix is going in.
@bileschi Thanks- forgive me if I misunderstood but even if I reshape my x into a lower dimension, won't my call to model.predict still fail though because it's expecting a 4-dimensional tensor as part of my model structure?
For example, running the following code for my model:
generated_images = model.predict(tf.ones([1, 1, 100]))
gives me the following error:
Error: Error when checking : expected dense_1_input to have 4 dimension(s), but got array with shape [1,1,100]
@98mprice Hi, yes, sorry, I didn't mean to reshape x. I meant you would need to edit the internals of tfjs and use your own custom tfjs package temporarily. It's definitely a bit much and I can see if you'd rather wait on a fix that should be in a minor version probably this week. Will ping here with developments.
This should be fixed at the next minor release.