Open michelegalante opened 6 years ago
@michelegalante Hi, thank you for submitting this issue. We will take a look. Seems like the shape information is wrong when passed to Conv1D after Lambda in MXNet backend.
Mean while, maybe there is some work arounds to explore for your use case? How about creating another input with x[:,:,1,:] and concatenate to your network.
Hi roywei,
after some research I found this workaround:
import keras
def select_axis(x):
return keras.backend.reshape(x[:,:,1,:], (-1,NFEATURES,NSTEPS))
NSTEPS=100
NFEATURES=10
NGROUPS=3
a = keras.layers.Input((NFEATURES,NGROUPS,NSTEPS))
print(a.shape)
b = keras.layers.Lambda(select_axis)(a)
print(b.shape)
c = keras.layers.Conv1D(8, 5)(b)
print(c.shape)
I suspect the problem is related to #113 and #120 (incorrect shape after slice operation).
@michelegalante Yes, the shape information is lost after slicing in Lambda, during infer_shape_partial() on mxnet symbol. Please use the workaround now while we fix it. @sandeep-krishnamurthy could you help verify? Seems #120 still exists
Can you please install MXNet master build to get the fix. You can do with --pre option in pypi
pip install mxnet-mkl --pre # For CPU
pip install mxnet-cu90 --pre # For GPU
On my side with mxnet-mkl --pre it's failing with the following error:
Traceback (most recent call last):
File "/Users/lawei/Documents/Workspace/roywei/keras/keras/backend/test.py", line 86, in <module>
c = keras.layers.Conv1D(8, 5)(b)
File "/Users/lawei/Documents/Workspace/roywei/keras/keras/engine/base_layer.py", line 432, in __call__
self.build(input_shapes[0])
File "/Users/lawei/Documents/Workspace/roywei/keras/keras/layers/convolutional.py", line 142, in build
constraint=self.kernel_constraint)
File "/Users/lawei/Documents/Workspace/roywei/keras/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/Users/lawei/Documents/Workspace/roywei/keras/keras/engine/base_layer.py", line 252, in add_weight
constraint=constraint)
File "/Users/lawei/Documents/Workspace/roywei/keras/keras/backend/mxnet_backend.py", line 235, in variable
if hasattr(value, "shape") and value.shape == (1,):
File "/Users/lawei/Documents/Workspace/roywei/keras/keras/backend/mxnet_backend.py", line 3946, in shape
return self._get_shape()
File "/Users/lawei/Documents/Workspace/roywei/keras/keras/backend/mxnet_backend.py", line 3955, in _get_shape
_, out_shape, _, _ = self.symbol.infer_shape_partial()
ValueError: not enough values to unpack (expected 4, got 3)
This code uses a Lambda layer to select a subset of the input (data format is
channels_first
):With tensorflow backend I get this output, as expected:
But with mxnet backend I get an error in Conv1D: