Caffe Multilabel没有按预期工作

时间:2018-04-27 09:35:33

标签: deep-learning caffe

我和Caffe玩了很长时间但从未做过多标签分类,而且我似乎陷入困境:

我正在使用

  • 首先,我创建了lmdb(train_lmdbval_lmdb),标签(labels_train_lmdblabels_val_lmdb)和平均值({{1} })Caffe-LMDBCreation-MultiLabel
  • 该模型有7类大约13000张图像。
  • 2000个图像有两个类(例如,向量是[1,0,0,1,0,0,0]
  • 其余图片只有一个类(例如,矢量为[0,0,1,0,0,0,0]

我期待的是

我期望至少从火车数据集中获取图像,例如:

  

img1.jpg 0 0 0 1 0 0 0

对其进行分类,其值类似于[0.0,1.0,0.0,0.0,0.0,0.0,0.0]

我改为

对于上面的图片(img1.jpg),我有这些类型的结果:

mean_lmdb.binaryproto

没有意义。我尝试了几个快照(每10000次迭代一次),结果相似,所有快照都接近0.50

我的[0.48112139105796814, 0.5486980676651001, 0.5396456122398376, 0.44233766198158264, 0.5605107545852661, 0.3539462387561798, 0.5215630531311035]

train_val.prototxt

prototxt

deploy.prototxt

name: "multi-class-alexnet"
# --------------------------------- TRAIN -------------------------------
# -----------------------------------------------------------------------
layer {
  name: "data"
  type: "Data"
  top: "data"
  include {
    phase: TRAIN
  }
  transform_param {
    mirror: true
    crop_size: 180
    mean_file: "./mean_lmdb.binaryproto"
  }
  data_param {
    source: "./train_lmdb"
    batch_size: 64
    backend: LMDB
  }
}

# ---------------------------- TRAIN LABELS -----------------------------
# -----------------------------------------------------------------------

layer {
  name: "data"
  type: "Data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
    scale: 0.00390625
    mean_value: 0
  }
  data_param {
    source: "./labels_train_lmdb"
    batch_size: 64
    backend: LMDB
  }
}

# ---------------------------------- VAL --------------------------------
# -----------------------------------------------------------------------

layer {
  name: "data"
  type: "Data"
  top: "data"
  include {
    phase: TEST
  }
  transform_param {
    mirror: false
    crop_size: 180
    mean_file: "./mean_lmdb.binaryproto"
  }
  data_param {
    source: "./val_lmdb"
    batch_size: 32
    backend: LMDB
  }
}

# ----------------------------- VAL LABELS ------------------------------
# -----------------------------------------------------------------------

layer {
  name: "data"
  type: "Data"
  top: "label"
  include {
    phase: TEST
  }
  transform_param {
    scale: 0.00390625
    mean_value: 0
  }
  data_param {
    source: "./labels_val_lmdb"
    batch_size: 32
    backend: LMDB
  }
}

layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 96
    kernel_size: 11
    stride: 4
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "norm1"
  type: "LRN"
  bottom: "pool1"
  top: "norm1"
  lrn_param {
    local_size: 5
    alpha: 0.0001
    beta: 0.75
  }
}
layer {
  name: "conv2"
  type: "Convolution"
  bottom: "norm1"
  top: "conv2"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 256
    pad: 2
    kernel_size: 5
    group: 2
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 1
    }
  }
}
layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2"
  top: "conv2"
}
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "norm2"
  type: "LRN"
  bottom: "pool2"
  top: "norm2"
  lrn_param {
    local_size: 5
    alpha: 0.0001
    beta: 0.75
  }
}
layer {
  name: "conv3"
  type: "Convolution"
  bottom: "norm2"
  top: "conv3"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 384
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu3"
  type: "ReLU"
  bottom: "conv3"
  top: "conv3"
}
layer {
  name: "conv4"
  type: "Convolution"
  bottom: "conv3"
  top: "conv4"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 384
    pad: 1
    kernel_size: 3
    group: 2
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 1
    }
  }
}
layer {
  name: "relu4"
  type: "ReLU"
  bottom: "conv4"
  top: "conv4"
}
layer {
  name: "conv5"
  type: "Convolution"
  bottom: "conv4"
  top: "conv5"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
    group: 2
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 1
    }
  }
}
layer {
  name: "relu5"
  type: "ReLU"
  bottom: "conv5"
  top: "conv5"
}
layer {
  name: "pool5"
  type: "Pooling"
  bottom: "conv5"
  top: "pool5"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "fc6_"
  type: "InnerProduct"
  bottom: "pool5"
  top: "fc6_"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  inner_product_param {
    num_output: 4096
    weight_filler {
      type: "gaussian"
      std: 0.005
    }
    bias_filler {
      type: "constant"
      value: 1
    }
  }
}
layer {
  name: "relu6"
  type: "ReLU"
  bottom: "fc6_"
  top: "fc6_"
}
layer {
  name: "drop6"
  type: "Dropout"
  bottom: "fc6_"
  top: "fc6_"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "fc7"
  type: "InnerProduct"
  bottom: "fc6_"
  top: "fc7"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  inner_product_param {
    num_output: 4096
    weight_filler {
      type: "gaussian"
      std: 0.005
    }
    bias_filler {
      type: "constant"
      value: 1
    }
  }
}
layer {
  name: "relu7"
  type: "ReLU"
  bottom: "fc7"
  top: "fc7"
}
layer {
  name: "drop7"
  type: "Dropout"
  bottom: "fc7"
  top: "fc7"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "latent"
  type: "InnerProduct"
  bottom: "fc7"
  top: "latent"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  inner_product_param {
    num_output: 48
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "latent"
  top: "latent_sigmoid"
  name: "latent_sigmoid"
  type: "Sigmoid"
}
layer {
  name: "fc9"
  type: "InnerProduct"
  bottom: "latent_sigmoid"
  top: "fc9"
  param {
    lr_mult: 10
    decay_mult: 1
  }
  param {
    lr_mult: 20
    decay_mult: 0
  }
  inner_product_param {
    num_output: 7
    weight_filler {
      type: "gaussian"
      std: 0.2
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "accuracy"
  type: "MultiLabelAccuracy"
  bottom: "fc9"
  bottom: "label"
  top: "accuracy"
  include {
    phase: TEST
  }
}
# ----------------------------------------------------------------
# ----------------- Multi-label Loss Function  -------------------
# ----------------------------------------------------------------
layer {
  name: "loss"
  type: "SigmoidCrossEntropyLoss"
  bottom: "fc9"
  bottom: "label"
  top: "loss"
}

损失函数

  • 不知何故,我的模型显示了两个损失,我不明白,输出#0和#5的损失。这些是最后一行的name: "multi-class-alexnet" input: "data" input_shape { dim: 10 dim: 3 dim: 180 dim: 180 } layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { num_output: 96 kernel_size: 11 stride: 4 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } } layer { name: "relu1" type: "ReLU" bottom: "conv1" top: "conv1" } layer { name: "pool1" type: "Pooling" bottom: "conv1" top: "pool1" pooling_param { pool: MAX kernel_size: 3 stride: 2 } } layer { name: "norm1" type: "LRN" bottom: "pool1" top: "norm1" lrn_param { local_size: 5 alpha: 0.0001 beta: 0.75 } } layer { name: "conv2" type: "Convolution" bottom: "norm1" top: "conv2" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { num_output: 256 pad: 2 kernel_size: 5 group: 2 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 1 } } } layer { name: "relu2" type: "ReLU" bottom: "conv2" top: "conv2" } layer { name: "pool2" type: "Pooling" bottom: "conv2" top: "pool2" pooling_param { pool: MAX kernel_size: 3 stride: 2 } } layer { name: "norm2" type: "LRN" bottom: "pool2" top: "norm2" lrn_param { local_size: 5 alpha: 0.0001 beta: 0.75 } } layer { name: "conv3" type: "Convolution" bottom: "norm2" top: "conv3" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { num_output: 384 pad: 1 kernel_size: 3 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } } layer { name: "relu3" type: "ReLU" bottom: "conv3" top: "conv3" } layer { name: "conv4" type: "Convolution" bottom: "conv3" top: "conv4" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { num_output: 384 pad: 1 kernel_size: 3 group: 2 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 1 } } } layer { name: "relu4" type: "ReLU" bottom: "conv4" top: "conv4" } layer { name: "conv5" type: "Convolution" bottom: "conv4" top: "conv5" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { num_output: 256 pad: 1 kernel_size: 3 group: 2 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 1 } } } layer { name: "relu5" type: "ReLU" bottom: "conv5" top: "conv5" } layer { name: "pool5" type: "Pooling" bottom: "conv5" top: "pool5" pooling_param { pool: MAX kernel_size: 3 stride: 2 } } layer { name: "fc6_" type: "InnerProduct" bottom: "pool5" top: "fc6_" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 4096 weight_filler { type: "gaussian" std: 0.005 } bias_filler { type: "constant" value: 1 } } } layer { name: "relu6" type: "ReLU" bottom: "fc6_" top: "fc6_" } layer { name: "drop6" type: "Dropout" bottom: "fc6_" top: "fc6_" dropout_param { dropout_ratio: 0.5 } } layer { name: "fc7" type: "InnerProduct" bottom: "fc6_" top: "fc7" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 4096 weight_filler { type: "gaussian" std: 0.005 } bias_filler { type: "constant" value: 1 } } } layer { name: "relu7" type: "ReLU" bottom: "fc7" top: "fc7" } layer { name: "drop7" type: "Dropout" bottom: "fc7" top: "fc7" dropout_param { dropout_ratio: 0.5 } } layer { name: "latent_" type: "InnerProduct" bottom: "fc7" top: "latent_" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 7 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } } layer { bottom: "latent_" top: "latent_sigmoid" name: "latent_sigmoid" type: "Sigmoid" } (超过110000次迭代):

输出#0

  

I0427 10:20:04.475754 1817 solver.cpp:238]火车净输出#0:损失= 0.0867133(* 1 = 0.0867133损失)

     

I0427 10:20:38.257825 1817 solver.cpp:238]火车净输出#0:损失= 0.0477974(* 1 = 0.0477974损失)

     

I0427 10:21:11.794013 1817 solver.cpp:238]火车净输出#0:损失= 0.0390092(* 1 = 0.0390092损失)

     

I0427 10:21:45.620671 1817 solver.cpp:238]火车净输出#0:损失= 0.039954(* 1 = 0.039954损失)

     

I0427 10:22:19.271747 1817 solver.cpp:238]火车净输出#0:损失= 0.0477802(* 1 = 0.0477802损失)

     

I0427 10:22:53.160802 1817 solver.cpp:238]列车净输出#0:损失= 0.0406158(* 1 = 0.0406158损失)

     

I0427 10:23:26.843694 1817 solver.cpp:238]火车净输出#0:损失= 0.0355715(* 1 = 0.0355715损失)

     

I0427 10:24:31.727321 1817 solver.cpp:238]火车净输出#0:损失= 0.0396538(* 1 = 0.0396538损失)

     

I0427 10:25:05.019598 1817 solver.cpp:238]火车净输出#0:损失= 0.037121(* 1 = 0.037121损失)

     

I0427 10:25:38.730303 1817 solver.cpp:238]火车净输出#0:损失= 0.0362058(* 1 = 0.0362058损失)

输出#5

  

I0427 09:26:52.251719 1817 solver.cpp:398]测试净输出#5:损失= 6.98116(* 1 = 6.98116损失)

     

I0427 09:33:01.639736 1817 solver.cpp:398]测试净输出#5:损失= 6.99285(* 1 = 6.99285损失)

     

I0427 09:39:09.991879 1817 solver.cpp:398]测试净输出#5:损失= 7.02165(* 1 = 7.02165损失)

     

I0427 09:45:18.013739 1817 solver.cpp:398]测试净输出#5:损失= 7.01533(* 1 = 7.01533损失)

     

I0427 09:51:27.065721 1817 solver.cpp:398]测试净输出#5:损失= 7.02347(* 1 = 7.02347损失)

     

I0427 09:58:13.271441 1817 solver.cpp:398]测试净输出#5:损失= 6.98176(* 1 = 6.98176损失)

     

I0427 10:05:31.896226 1817 solver.cpp:398]测试净输出#5:损失= 6.99103(* 1 = 6.99103损失)

     

I0427 10:12:12.693677 1817 solver.cpp:398]测试净输出#5:损失= 7.02868(* 1 = 7.02868损失)

     

I0427 10:18:23.250385 1817 solver.cpp:398]测试净输出#5:损失= 7.03427(* 1 = 7.03427损失)

     

I0427 10:24:31.239820 1817 solver.cpp:398]测试净输出#5:损失= 6.97721(* 1 = 6.97721损失)

0 个答案:

没有答案