Implementation for multi-label with different weighted value in softmax_loss layer

31 views
Skip to first unread message

Jimmy Wu

unread,
Jun 15, 2017, 3:43:30 AM6/15/17
to Caffe Users
Hi,

I want to train the model for some classification. In one batch, the label of each data has different weight. 

That means I need something like

loss = W *log(std::max(prob_data[index],   Dtype(FLT_MIN)));

in which it has different weight value W for each loss of training data.




But softmax_with_loss_layer will accumulate all the loss value, which will later be used for back-pro in one batch.

I slightly modified the code in softmax_loss_layer by giving the third dimension of bottom blob, which is the weight input for each training data.

Also, I defined ExactNumBottomBlobs as 3 to replace the definition of only passing two bottoms in loss_layer.

At last I multiplied the weight like the below. I omit the for loop part for simplicity.

    const Dtype* sample_weight = bottom[2]->cpu_data();

    Dtype w = sample_weight[i * inner_num_ + j];

    loss -= w *log(std::max(prob_data[i * dim + label_value * inner_num_ + j],  Dtype(FLT_MIN)));





But later I got the corrupted double-linked list which looks like this:

*** Error in `/home/jimmyoic/myProgram': corrupted double-linked list: 0x00007fff30003c20 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7ffff58487e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x81f88)[0x7ffff5852f88]
/lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x54)[0x7ffff58545d4]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_Znwm+0x18)[0x7ffff5e3de78]
/home/jimmyoic/caffe-master/lib/libcaffe.so.1.0.0-rc3(_ZN5caffe20BaseConvolutionLayerIfE7ReshapeERKSt6vectorIPNS_4BlobIfEESaIS5_EES9_+0x6e7)[0x7ffff6ce3eb7]
/home/jimmyoic/caffe-master/lib/libcaffe.so.1.0.0-rc3(_ZN5caffe21CuDNNConvolutionLayerIfE7ReshapeERKSt6vectorIPNS_4BlobIfEESaIS5_EES9_+0x32)[0x7ffff6c11962]
/home/jimmyoic/caffe-master/lib/libcaffe.so.1.0.0-rc3(_ZN5caffe3NetIfE13ForwardFromToEii+0xc8)[0x7ffff6da9df8]
/home/jimmyoic/caffe-master/lib/libcaffe.so.1.0.0-rc3(_ZN5caffe3NetIfE7ForwardEPf+0x56)[0x7ffff6daa1d6]
/usr/lib/x86_64-linux-gnu/libboost_thread.so.1.58.0(+0x115d5)[0x7ffff7bc25d5]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7ffff799b6ba]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7ffff58d782d]

======= Memory map: ========
00400000-00860000 r-xp 00000000 08:01 46268632                           /home/jimmyoic/myProgram
00a5f000-00a65000 r--p 0045f000 08:01 46268632                           /home/jimmyoic/myProgram
00a65000-00a68000 rw-p 00465000 08:01 46268632                           /home/jimmyoic/myProgram
.......




Is there anything I haven't be aware of while I need to give softmax-loss layer an additional bottom input?


Thanks!
Jimmy





Reply all
Reply to author
Forward
0 new messages