mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Could somebody tell me how to use softmaxoutput function exactly?

Open lugui2009 opened this issue 10 years ago • 4 comments

Hi everyone.I have a question about the realization the softmaxoutput of loss layer which confuses me a lot. I wrote a simple CNN network below.just three convolution layers.

data=mx.symbol.Variable('data')
conv1=mx.symbol.Convolution(data=data,kernel=(9,9),pad=(0,0),num_filter=64,name="conv1")
relu1=mx.symbol.Activation(data=conv1,act_type="relu",name="relu1")
conv2=mx.symbol.Convolution(data=relu1,kernel=(1,1),pad=(0,0),num_filter=32,name="conv2")
relu2=mx.symbol.Activation(data=conv2,act_type="relu",name="relu2")
conv3=mx.symbol.Convolution(data=relu2,kernel=(5,5),pad=(0,0),num_filter=1,name="conv3")
softmax=mx.symbol.SoftmaxOutput(data=conv3,name='softmax')
mynet=softmax

I used the infer_shape() method to get the dimension of label ,here I suppose my size of data is (50,1,33,33)

arg,out,aux=mynet.infer_shape(data=(50,1,33,33)) I get the result: arg [(50L, 1L, 33L, 33L), (64L, 1L, 9L, 9L), (64L,), (32L, 64L, 1L, 1L), (32L,), (1L, 32L, 5L, 5L), (1L,), (50L, 1L, 21L)]

Actually I really don't know why the dimension of label becomes (50L,1L,21L) , I am not familar with the fuction of softmax,in my mind ,the softmax is just a combination of exp() and normalization.

I refer to the "numpy_softmax.py" in the file of example/numpy-ops .here,I see the code which seems like softmax.However, the function doesn't seem to reduce the dimention of label.

def forward(self, in_data, out_data): x = in_data[0] y = out_data[0] y[:] = np.exp(x - x.max(axis=1).reshape((x.shape[0], 1))) y /= y.sum(axis=1).reshape((x.shape[0], 1))

So I have two methods.One is that I should know exactly the softmaxout in the mxnet,then use the same method to change my label,and reduce the dimention of label.But I am new to the MXnet,could someone tell me the principle of softmaxout fuction,why the dimension of label reduces. Another method I want to ask is whether I need to use the softmaxoutput ,can I make the conv3 data to be my output,and how? I hope some experts can give me some advice , thank you so much.

lugui2009 avatar Jul 05 '16 05:07 lugui2009

label is integer indexes ranging over the classes

piiswrong avatar Jul 05 '16 06:07 piiswrong

@piiswrong thank you for your reply. After some reading ,I may understand.In the common classification problem of network,we will setup the number of neurons as same as the number of classification indexes.After softmaxoutput ,we have a max() function and get only one index.So Can I get the conclusion that the softmaxoutput is only suitable for classification.

lugui2009 avatar Jul 05 '16 10:07 lugui2009

@piiswrong Let's say that I have 3 classes. Does it mean that my labels should be 0, 1 and 2? Thanks!

KCHWang avatar Jul 26 '16 02:07 KCHWang

This issue is closed due to lack of activity in the last 90 days. Feel free to reopen if this is still an active issue. Thanks!

phunterlau avatar Sep 28 '17 06:09 phunterlau