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

Cannot slice axis on tensor with MXNet backend #113

Closed sandeep-krishnamurthy closed 6 years ago

sandeep-krishnamurthy commented 6 years ago

Minimum reproducible code:

import numpy as np

import keras
from keras import backend as K

# In Numpy
data = np.array([[[1,2,3], [4,5,6]]])
data.shape
(1,2,3)
data[:,-1,:].shape
(1,3)

# In Keras with MXNet backend
var1 = K.variable(data)
var1.shape
(1,2,3)
K.eval(var1[:,-1,:])
<<ERROR>>

Check failed: b < e (1 vs. 0) slicing with begin=[1]=1, end[1]=0, and step[1]=1 is invalid

Reason:

MXNet does not support slicing the axis with mx.sym.slice operator. In KerasSymbol, getitem method, we need to special case this kind of slicing and use mx.sym.slice_axis()

sandeep-krishnamurthy commented 6 years ago

One workaround provided by a user (Prabhu) -

ret = x[:, slice(-1, None), :] 
roywei commented 6 years ago

closing as fixed in #158