Hi, does Accuracy_layer.cpp support multi-label classification?

96 views
Skip to first unread message

Alec Wang

unread,
Jul 16, 2016, 8:54:38 AM7/16/16
to Caffe Users
Hi, I am new to Caffe, now my task is to train a multi label classifier. And I modified the convert-imageset.cpp and some other layers, mainly change CONST INT LABEL to CONST STD::VECTOR<INT> label. So, I am succeed to generate the LEVELDB file by the input .txt file like following:
images/train/1.jpg 10 15
images/train/2.jpg 3
images/train/4.jpg 0 3 5
...

Two parts, one is the path of the image. And followed by its labels: such as 10 15 .

But I am not so clear about the accuracy layer? Below is my prototx:
layer{
    name: "data"
    type: "Data"
    top: "data"
    top: "label"
    include {
        phase: TRAIN
    }
    transform_param {
        mean_file: "mean.binaryproto"
        mirror: true
        crop_size: 224
    }
    data_param {
        source: "train_vgg_cnnf_leveldb"
        batch_size: 128
        backend: LEVELDB
    }
}

layer {
    name: "data"
    type: "Data"
    top: "data"
    top: "label"
    include {
        phase: TEST
    }
    transform_param {
        mean_file: "mean.binaryproto"
        mirror: false
        crop_size: 224
    }
    data_param {
        source: "test_vgg_cnnf_leveldb"
        batch_size: 100
        backend: LEVELDB
    }
}






layer {
  bottom: "data"
  top: "conv1"
  name: "conv1"
  type: "Convolution"
  convolution_param {
    num_output: 64
    kernel_size: 11
    stride: 4
  }
}
layer {
  bottom: "conv1"
  top: "conv1"
  name: "relu1"
  type: "ReLU"
}
layer {
  bottom: "conv1"
  top: "norm1"
  name: "norm1"
  type: "LRN"
  lrn_param {
    local_size: 5
    alpha: 0.0005
    beta: 0.75
    k: 2
  }
}
layer {
  bottom: "norm1"
  top: "pool1"
  name: "pool1"
  type: "Pooling"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  bottom: "pool1"
  top: "conv2"
  name: "conv2"
  type: "Convolution"
  convolution_param {
    num_output: 256
    pad: 2
    kernel_size: 5
  }
}
layer {
  bottom: "conv2"
  top: "conv2"
  name: "relu2"
  type: "ReLU"
}
layer {
  bottom: "conv2"
  top: "norm2"
  name: "norm2"
  type: "LRN"
  lrn_param {
    local_size: 5
    alpha: 0.0005
    beta: 0.75
    k: 2
  }
}
layer {
  bottom: "norm2"
  top: "pool2"
  name: "pool2"
  type: "Pooling"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  bottom: "pool2"
  top: "conv3"
  name: "conv3"
  type: "Convolution"
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
  }
}
layer {
  bottom: "conv3"
  top: "conv3"
  name: "relu3"
  type: "ReLU"
}
layer {
  bottom: "conv3"
  top: "conv4"
  name: "conv4"
  type: "Convolution"
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
  }
}
layer {
  bottom: "conv4"
  top: "conv4"
  name: "relu4"
  type: "ReLU"
}
layer {
  bottom: "conv4"
  top: "conv5"
  name: "conv5"
  type: "Convolution"
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
  }
}
layer {
  bottom: "conv5"
  top: "conv5"
  name: "relu5"
  type: "ReLU"
}
layer {
  bottom: "conv5"
  top: "pool5"
  name: "pool5"
  type: "Pooling"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  bottom: "pool5"
  top: "fc6"
  name: "fc6"
  type: "InnerProduct"
  inner_product_param {
    num_output: 4096
  }
}
layer {
  bottom: "fc6"
  top: "fc6"
  name: "relu6"
  type: "ReLU"
}
layer {
  bottom: "fc6"
  top: "fc6"
  name: "drop6"
  type: "Dropout"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  bottom: "fc6"
  top: "fc7"
  name: "fc7"
  type: "InnerProduct"
  inner_product_param {
    num_output: 4096
  }
}
layer {
  bottom: "fc7"
  top: "fc7"
  name: "relu7"
  type: "ReLU"
}
layer {
  bottom: "fc7"
  top: "fc7"
  name: "drop7"
  type: "Dropout"
  dropout_param {
    dropout_ratio: 0.5
  }
}

layer {
    bottom: "fc7"
    top: "fc8_32"
    name: "fc8_32"
    type: "InnerProduct"
    param {
    lr_mult: 1
    decay_mult: 1
    }
    param {
    lr_mult: 2
    decay_mult: 0
    }
    inner_product_param {
        num_output: 32
        weight_filler {
            type: "gaussian"
            std: 0.1
        }
        bias_filler {
            type: "constant"
        } 
    }
}

layer {
    bottom: "fc8_32"
    top: "fc8-classification"
    name: "fc8-classification"
    type: "InnerProduct"
    param {
    lr_mult: 1
    decay_mult: 1
    }
    param {
    lr_mult: 2
    decay_mult: 0
    }
    inner_product_param {
        num_output: 81
        weight_filler {
            type: "gaussian"
            std: 0.1
        }
        bias_filler {
            type: "constant"
        } 
    }
}

layer {
  name: "accuracy"
  type: "Accuracy" 
  bottom: "fc8-classification"
  bottom: "label"
  top: "accuracy"
  include {
        phase: TEST
    }
}

layer {
  name: "loss"
  type: "SoftmaxWithLoss"  # Should this be replaced by sigmoid_cross_entropy_loss_layer??
  bottom: "fc8-classification"
  bottom: "label"
  top: "loss"
}








Reply all
Reply to author
Forward
0 new messages