Train Multiple classes in DetectNet

Posted on Updated on

To train a DetectNet that can recognize multiple classes, you need to modify a few lines of the DetectNet.prototxt. There are total 7 places of the code you need to modify.

 

  1. train_transform layer and val_transform

    In the train_transform layer and val_transform layer(around line 76 and 116)
    add object_class fields that match your number of classes

    For example, if you have 3 classes, you need to add

    object_class: { src: 1 dst: 0}
    object_class: { src: 2 dst: 1}
    object_class: { src: 3 dst: 2}
    
  2. Number of output in convolution parameter

    Change the num_output equal to your number of classes(around line 2379)

    For example, if you have 3 classes, you need to change

    num_output: 3
    
  3. Cluster bboxes’ layer

    add more top layer parameter (around line 2499)

    For example, if you have 3 classes, you need to add

    top: 'bbox-list-class0'
    top: 'bbox-list-class1'
    top: 'bbox-list-class2'
    
  4. param_str value in Cluster bboxes’ layer

    change the last parameter of the param_str

    param_str : ‘1920, 1152, 16, 0.05, 1, 0.02, 22, NUM_OF_CLASSES’

    param_str : '1920, 1152, 16, 0.05, 1, 0.02, 22, 3'
    
  5. Calculate mean average precision’s layer

    add more top layer parameter (around line 2514), just same as the Cluster bboxes’ layer mentioned in step 3.

    For example, if you have 3 classes, you need to add

    top: 'bbox-list-class0'
    top: 'bbox-list-class1'
    top: 'bbox-list-class3'
    
  6. param_str value in Calculate mean average precision’s layer

    change the last parameter of the param_str

    param_str : ‘1920, 1152, 16, NUM_OF_CLASSES’

    param_str : '1920, 1152, 16, 3'
    
  7. Final Output Layer

    Insert the number of output layer that match your number of classes. If you have 3 classes, you need to insert 3 set of the
    layers.

    The name inside bottom layer parameter must be same as above

    An example of 1 set of a layer.
    
    #class 0
    layer {
    type: 'Python'
    name: 'score-class0'
    bottom: 'bbox-list-label-class0'
    bottom: 'bbox-list-class0'
    top: 'bbox-list-scored-class0'
    python_param {
        module: 'caffe.layers.detectnet.mean_ap'
        layer: 'ScoreDetections'
    }
    include: { phase: TEST stage: "val" }
    }
    layer {
    type: 'Python'
    name: 'mAP-class0'
    bottom: 'bbox-list-scored-class0'
    top: 'mAP-class0'
    top: 'precision-class0'
    top: 'recall-class0'
    python_param {
        module: 'caffe.layers.detectnet.mean_ap'
        layer: 'mAP'
        param_str : '1920, 1152, 16'
    }
    include: { phase: TEST stage: "val" }
    }
    

13 thoughts on “Train Multiple classes in DetectNet

    Aaron said:
    2017-07-31 at 5:11 pm

    Hi, can I have your email for ask the question?
    thank!

    Aaron

    Like

    Robert said:
    2017-08-22 at 12:53 pm

    In your example NUM_OF_CLASSES =3, however in step 6 it is 2. Is this a typo, or is it N-1?

    Like

      Lester Lo responded:
      2017-08-22 at 3:10 pm

      yes, it was a typo. It should be 3 in there.

      param_str : ‘1920, 1152, 16, 3’

      Like

    Zack said:
    2018-01-15 at 4:14 pm

    Hi – Thank you for your tutorial. I got this error when I tried to run the code.

    ERROR: Layer ‘cluster’ references bottom ‘bbox-list-label-class0’ at the TEST stage however this blob is not included at that stage. Please consider using an include directive to limit the scope of this layer.

    Can you please give me some guidance to fix it?

    Like

      Zack said:
      2018-01-15 at 4:20 pm

      The error may be due to bottom layer. Do I add bottom layer in step 3 and 5? Like add bbox-list-label-class0 in step 3 and 5.

      Like

        Lester Lo responded:
        2018-03-05 at 11:15 am

        I think yes, you can try this.

        Like

    Harshit Sharma said:
    2018-02-15 at 6:05 pm

    CaffeTrainSanityCheckError: Layer ‘score-class0’ references bottom ‘bbox-list-label-class0’ at the TEST stage however this blob is not included at that stage. Please consider using an include directive to limit the scope of this layer.

    Like

    dqthebt said:
    2018-06-26 at 1:45 pm

    How to label objects in images? As I knew, detectNet using KITTI format, so, How to do if I want to train with my labels, ex: Pepsi, Coca, …?

    Like

    vx said:
    2019-08-30 at 4:03 pm

    does this change method make sense for the segmentation model?

    Like

      Lester Lo responded:
      2020-02-17 at 4:42 pm

      I haven’t test it. You may try it to see the performance.

      Like

Leave a comment