Check failed: axis < ndim && axis >= -ndim axis 1 exceeds the input dimension of 1


#1

Check failed: axis < ndim && axis >= -ndim axis 1 exceeds the input dimension of 1
when i use the mx.sym.sum() as the input of the mx.sym.MakeLoss(),it throw this error.
i don’t know what lead it,do you know?


#2

Do you have sample code that reproduces the problem?


#3

`data = mx.symbol.Variable(‘data’)

label = mx.symbol.Variable(‘softmax_label’)

conv1=mx.symbol.Convolution(data,kernel=(5,5),stride=(1,1),pad=(2,2),num_filter=32)

fc1=mx.symbol.Activation(conv1,act_type=‘relu’)

pool1=mx.symbol.Pooling(fc1,kernel=(2,2),pool_type=‘max’,stride=(2,2))

conv2=mx.symbol.Convolution(pool1,kernel=(5,5),stride=(1,1),pad=(2,2),num_filter=64)

fc2=mx.symbol.Activation(conv2,act_type=‘relu’)

pool2=mx.symbol.Pooling(fc2,kernel=(2,2),pool_type=‘max’,stride=(2,2))

fc3=mx.sym.Reshape(pool2,shape=(-1,7764))

fc4=mx.symbol.FullyConnected(fc3,num_hidden=1024)

fc5=mx.symbol.Activation(fc4,act_type=‘relu’)

drop1=mx.symbol.Dropout(fc5,p=0.5)

fc6=mx.symbol.FullyConnected(drop1,num_hidden=10)

fc7=mx.symbol.softmax(fc6)

out=mx.symbol.MakeLoss(-mx.symbol.sum(label*mx.symbol.log(fc7)))`
i use the mnist dataset with data-shape (-1,1,28,28) and label-shape(-1,10).
after i use the MakeLoss,when i run it,the python doesnt work and kill the kernel.
in ubantu and windows it did the same thing.and the version is mxnet 1.1.0 .
thanks for your reply.


#4

MakeLoss expects a vector as input (One loss value for each example in the batch). So, you should sum along axis 1. Please pass axis=1 as a parameter to the sum operator.


#5

i’m sorry to say that after i do so it reacted the same as with no axis=1.i just want to do like mx.sym.softmax_cross_entropy(),but when i use it,it said there are not enough parameters to call it.i saw it as a bug on the github and they fixed it but i still can’t use it in the lastest version.