mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Number of output from the mx.sym.SoftmaxOutput

Open EsraaRagaa opened this issue 9 years ago • 4 comments

I am training a model using CNN to classify images between class 1 and 0, but after prediction, I get number of classes equal to number of nodes in the fully connected layer which precedes the softmax layer

This is the code I use for building the model:

data = mx.sym.var('data') conv1 = mx.sym.Convolution(data=data, kernel=(3,3), num_filter=6) relu1 = mx.sym.Activation(data=conv1, act_type="relu") pool1 = mx.sym.Pooling(data=relu1, pool_type="max", kernel=(2,2), stride=(2,2)) conv2 = mx.sym.Convolution(data=pool1, kernel=(6,6), num_filter=12) relu2 = mx.sym.Activation(data=conv2, act_type="relu") pool2 = mx.sym.Pooling(data=relu2, pool_type="max", kernel=(2,2), stride=(2,2)) flatten = mx.sym.flatten(data=pool2) fc1 = mx.symbol.FullyConnected(data=flatten, num_hidden=48) lenet = mx.sym.SoftmaxOutput(data=fc1,name='softmax') lenet_model = mx.mod.Module(symbol=lenet, context=mx.cpu()) lenet_model.fit(train_iterator, ..... num_epoch=10)

The solutions I tried to use to fix the problem:

1- lables = mx.sym.Variable('softmax_label') lenet = mx.sym.SoftmaxOutput(data=fc1,label=lables,name='softmax')

  • result: did not fix the problem, still after prediciton the number probability coresponding to the classes=48

2- lables = mx.sym.Variable('softmax_label') lenet = mx.sym.SoftmaxOutput(data=fc1,label=lables, preserve_shape=True, name='softmax')

  • result: did not fix the problem, still after prediciton the number probability coresponding to the classes=48

3- lables = mx.sym.Variable('softmax_label') lenet = mx.sym.SoftmaxOutput(data=fc1,label=lables, preserve_shape=True, multi_output=True, name='softmax')

  • result: did not fix the problem, still after prediciton the number probability coresponding to the classes=48

4- lables = [0,1] lenet = mx.sym.SoftmaxOutput(data=fc1,label=lables, preserve_shape=True, multi_output=True, name='softmax')

  • result: error, lables should be a symbole

5- adding an extra hidden layer after fc1and pass it to the softmax extra_hidden_2nods = mx.symbol.FullyConnected(data=fc1, num_hidden=2) lenet = mx.sym.SoftmaxOutput(data=extra_hidden_2nods, name='softmax')

  • result: fixed the problem but this is not what I want

Environment info

I am using the last version of mxnet, python, anaconda, win10, cpu

Thanks in advance

EsraaRagaa avatar Nov 06 '17 20:11 EsraaRagaa

what you need:

...
fc1_act = xxx
fc2 = mx.symbol.FullyConnected(data=fc1_act, num_hidden=2)
lenet = mx.sym.SoftmaxOutput(data=fc2,name='softmax')
...

zhreshold avatar Nov 08 '17 02:11 zhreshold

@apache/mxnet-committers: This issue has been inactive for the past 90 days. It has no label and needs triage.

For general "how-to" questions, our user forum (and Chinese version) is a good place to get help.

szha avatar Feb 07 '18 12:02 szha

Hi @EsraaRagaa are you still facing the same issue?

lanking520 avatar Jun 08 '18 23:06 lanking520

Thanks, I found that I should edit my network.

EsraaRagaa avatar Jun 09 '18 21:06 EsraaRagaa