Caffe中的准确性问题

5

我有一个网络,其中有4个布尔输出。这不是一个分类问题,每一个输出都是有意义的。我希望每一个输出都可以得到0或1。 我目前使用了欧几里德损失函数。

有1000000个样本。在输入文件中,每个样本有144个特征,因此输入大小为1000000*144。 我使用了50个批处理大小,否则处理时间太长。 输出文件的大小为1000000*4,即每个输入会有四个输出。

当我使用准确率层时,它抱怨输出的维度。它只需要一个布尔输出,而不是四个。我认为这是因为它将问题视为分类问题。 我有两个问题。 首先,考虑到准确率层的错误,欧几里德损失函数是否适合这个任务?如何计算网络的准确度? 其次,我想要得到每个变量的预测输出的精确值。我指的是每个测试记录的精确预测值。现在,我只有每个批次的损失值。 请指导我解决这些问题。

谢谢, Afshin

训练网络如下:

{ state {
 phase: TRAIN
}
 layer {
   name: "abbas"
   type: "HDF5Data"
   top: "data"
   top: "label"
   hdf5_data_param {
     source: "/home/afo214/Research/hdf5/simulation/Train-1000-11-     1/Train-Sc-B-1000-11-1.txt"
     batch_size: 50
   } 
 }

 layer {
   name: "ip1"
   type: "InnerProduct"
   bottom: "data"
   top: "ip1"
   inner_product_param {
     num_output: 350
     weight_filler {
       type: "xavier"
     }
   }
 }

 layer {
   name: "sig1"
   bottom: "ip1"
   top: "sig1"
   type: "Sigmoid"
 }

 layer {
   name: "ip2"
   type: "InnerProduct"
   bottom: "sig1"
   top: "ip2"
   inner_product_param {
     num_output: 150
     weight_filler {
       type: "xavier"
     }
   }
 }

测试网络也是:

       state {
       phase: TEST
       }
        layer {
        name: "abbas"
        type: "HDF5Data"
        top: "data"
        top: "label"
        hdf5_data_param {
         source: "/home/afo214/Research/hdf5/simulation/Train-1000-11-         1/Train-Sc-B-1000-11-1.txt"
          batch_size: 50
         }
        }

        layer {
         name: "ip1"
  type: "InnerProduct"
  bottom: "data"
  top: "ip1"
  inner_product_param {
  num_output: 350
  weight_filler {
   type: "xavier"
  }
 }
 }

  layer {
  name: "sig1"
  bottom: "ip1"
   top: "sig1"
   type: "Sigmoid"
 }


   layer {
     name: "ip2"
     type: "InnerProduct"
     bottom: "sig1"
     top: "ip2"
     inner_product_param {
       num_output: 150
       weight_filler {
         type: "xavier"
       }
     }
   }


   layer {
     name: "sig2"
     bottom: "ip2"
     top: "sig2"
     type: "Sigmoid"
   }


   layer {
     name: "ip4"
     type: "InnerProduct"
     bottom: "sig2"
     top: "ip4"
     inner_product_param {
       num_output: 4
       weight_filler {
         type: "xavier"
       }
     }
   }
   layer {
     name: "accuracy"
       type: "Accuracy"
         bottom: "ip4"
          bottom: "label"
             top: "accuracy"
             }


   layer {
     name: "loss"
     type: "EuclideanLoss"
     bottom: "ip4"
     bottom: "label"
     top: "loss"
   }

我遇到了这个错误:

accuracy_layer.cpp:34] Check failed: outer_num_ * inner_num_ ==  bottom[1]->count() (50 vs. 200) Number of labels must match number of   predictions; e.g., if label axis == 1 and prediction shape is (N, C, H,   W), label count (number of labels) must be N*H*W, with integer values in   {0, 1, ..., C-1}.

不使用caffe的准确度层,我可以得到损失值。


你能否发布一下你目前正在使用的预测、损失和准确率层? - Shai
我在这里添加了我的训练层。 - Afshin Oroojlooy
我更感兴趣的是顶层:预测、损失和准确率层。顺便问一下,你的输入“label”的形状是什么? - Shai
@Shai 对不起。 - Afshin Oroojlooy
没有问题,请编辑您的问题以使其更清晰。 - Shai
显示剩余7条评论
1个回答

6

在预测二进制输出时,应该使用"EuclideanLoss"吗?

如果您正在尝试预测离散的二进制标签,则"EuclideanLoss"不是一个很好的选择。这种损失更适用于回归任务,其中您希望预测连续值(例如,估计边界框的坐标等)。
对于预测离散标签,"SoftmaxWithLoss""InfogainLoss"更加适合。通常使用"SoftmaxWithLoss"
对于预测二进制输出,您还可以考虑"SigmoidCrossEntropyLoss"

"Accuracy"层为什么会出现错误?

中,"Accuracy"层期望两个输入("bottom"):一个是预测向量,另一个是期望的离散标签。 在您的情况下,您需要为每个二进制输出提供一个长度为2的向量,其中包含0和1的预测概率,以及单个二进制标签。
layer {
  name: "acc01"
  type: "Accuracy"
  bottom: "predict01"
  bottom: "label01"
  top: "acc01"
}

在这个例子中,您测量单个二进制输出的准确性。输入“predict01”是批处理中每个示例的两个向量(对于batch_size: 50,此blob的形状应为50x2)。
你能做什么?
您正在尝试在单个网络中预测4个不同的输出,因此需要4个不同的损失和准确度层。 首先,您需要将(“Slice”)基本事实标签分成4个标量(而不是单个二进制4向量)。
layer {
  name: "label_split"
  bottom: "label" # name of input 4-vector
  top: "label01"
  top: "label02"
  top: "label03"
  top: "label04"
  type: "Slice"
  slice_param {
    axis: 1
    slice_point: 1
    slice_point: 2
    slice_point: 3
  }
}

现在,您需要为每个二进制标签添加预测、损失和准确率层。
layer {
  name: "predict01"
  type: "InnerProduct"
  bottom: "sig2"
  top: "predict01"
  inner_product_param {
    num_outout: 2 # because you need to predict 2 probabilities one for False, one for True
    ...
}
layer {
  name: "loss01"
  type: "SoftmaxWithLoss"
  bottom: "predict01"
  bottom: "label01"
  top: "loss01"
}
layer {
  name: "acc01"
  type: "Accuracy"
  bottom: "predict01"
  bottom: "label01"
  top: "acc01"
}

现在,您需要为要预测的四个二进制标签中的每一个复制这三个层。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接