Closed EsraaRagaa closed 6 years ago
what you need:
...
fc1_act = xxx
fc2 = mx.symbol.FullyConnected(data=fc1_act, num_hidden=2)
lenet = mx.sym.SoftmaxOutput(data=fc2,name='softmax')
...
@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.
Hi @EsraaRagaa are you still facing the same issue?
Thanks, I found that I should edit my network.
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')
2- lables = mx.sym.Variable('softmax_label') lenet = mx.sym.SoftmaxOutput(data=fc1,label=lables, preserve_shape=True, name='softmax')
3- lables = mx.sym.Variable('softmax_label') lenet = mx.sym.SoftmaxOutput(data=fc1,label=lables, preserve_shape=True, multi_output=True, name='softmax')
4- lables = [0,1] lenet = mx.sym.SoftmaxOutput(data=fc1,label=lables, preserve_shape=True, multi_output=True, name='softmax')
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')
Environment info
I am using the last version of mxnet, python, anaconda, win10, cpu
Thanks in advance