Multi-labels using two different LMDB

人盡茶涼 提交于 2019-12-04 08:36:24

As a whole, your code above is Ok but you should notice that:

  1. Your .cpp is to create LEVELDB instead of LMDB, of course this is not the reason that caused your problem, either type is ok.
  2. The "label LMDB" generated by your code is of dimension Nx3x1x1 instead of Nx1x1x3(NumberxChannelxWidthxHeight).
  3. In a learning task using minibatch SGD, as far as I know, it is very useful to shuffle your data for training to get more optimized model. I'm not sure whether you noticed this. But at least your cpp didn't shuffle your "train.data".
  4. Most important of all, the reason that caused your problem here most possibly lied in the data layer in your network which read your data and label lmdb/leveldb files, because you assigned the labels to the float data of datum and the DataLayer in caffe in fact does not read the float data(Only if you used your self-defined data layer). So please also upload your prototxt file which defines your network. Thus we can find out what the problem really was.

At last, I added a "MultiTaskData" layer MultiTaskDataLayer to read multi-labels from datum for multi-task training and you can make simple modifications to add it to your caffe and use like this:

    name: "AgeNet"
    layer {
        name: "Age"
        type: "MultiTaskData"
        top: "data"
        top: "age_label"
        top: "gender_label"
        data_param { 
            source: "age_gender_classification_0_60p_train_leveldb"   
            batch_size: 60 
            task_num: 2
            label_dimension: 1
            label_dimension: 1
        }
        transform_param {
            scale: 0.00390625
            crop_size: 60
            mirror: true
        }
        include:{ phase: TRAIN }
    }
    layer { 
        name: "cls_age" 
        type: "InnerProduct"
        bottom: "data"  
        top: "cls_age" 
        param {
            lr_mult: 1
            decay_mult: 1
        }
        param {
            lr_mult: 2
            decay_mult: 0
        }
        inner_product_param {
            num_output: 7
            weight_filler {
            type: "xavier"
            }    
        bias_filler {      
            type: "constant"
            }  
        }
    }
    layer {  
        name: "age_loss"  
        type: "SoftmaxWithLoss"  
        bottom: "cls_age" 
        bottom: "age_label"
        top: "age_loss"
        include:{ phase: TRAIN }
    }
    layer { 
        name: "cls_gender" 
        type: "InnerProduct"
        bottom: "data"  
        top: "cls_gender" 
        param {
            lr_mult: 1
            decay_mult: 1
        }
        param {
            lr_mult: 2
            decay_mult: 0
        }
        inner_product_param {
            num_output: 2
            weight_filler {
                type: "xavier"
            }    
            bias_filler {      
                type: "constant"
            }  
        }
    }
    layer {  
        name: "gender_loss"  
        type: "SoftmaxWithLoss"  
        bottom: "cls_gender" 
        bottom: "gender_label"
        top: "gender_loss"
        include:{ phase: TRAIN }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!