【问题标题】:Accuracy issue in caffecaffe 中的准确性问题
【发布时间】:2016-03-18 00:06:33
【问题描述】:

我有一个有 4 个布尔输出的网络。这不是一个分类问题,它们中的每一个都是有意义的。我希望他们每个人都得到一个零或一个。现在我用的是欧几里得损失函数。

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

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

谢谢, 阿夫辛

火车网络是:

{ 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 我在这里添加了我的训练层。
  • 我对顶层更感兴趣:预测层、损失层和准确度层。顺便说一句,您输入 "label" 的 shape 是什么?
  • @Shai 输入标签是一个大小为 N*200 的表格,但预测标签的大小为 N*50。请注意,50 是我的批量大小,对于每个批次我有 4 个输出,但是 caffe 只给出一个预测。
  • 你很不清楚。请发布您的 prototxt 并解释什么是 N 以及为什么您将批量尺寸与标签尺寸混合在一起(而不是 N*50*4 您有 N*200)??

标签: machine-learning neural-network deep-learning caffe


【解决方案1】:

应该使用"EuclideanLoss" 来预测二进制输出吗?

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

为什么"Accuracy"层有错误?

在 中,“Accuracy" 层需要两个输入(“底部”):一个是预测向量,另一个是预期的基本事实离散 标签。 在您的情况下,您需要为每个二进制输出提供一个长度为 2、预测概率为 0 和 1 的向量,以及一个二进制标签:

layer {
  name: "acc01"
  type: "Accuracy"
  bottom: "predict01"
  bottom: "label01"
  top: "acc01"
}

在本例中,您测量单个二进制输出的准确性。输入 "predict01" 是批处理中每个示例的两个向量(对于 batch_size: 50,此 blob 的形状应为 50×2)。

你能做什么?

您正试图在单个网络中预测 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"
}

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

【讨论】:

    猜你喜欢
    • 2017-05-03
    • 1970-01-01
    • 2016-05-29
    • 2018-08-17
    • 2017-11-18
    • 1970-01-01
    • 2016-02-19
    • 2017-02-26
    • 2018-10-07
    相关资源
    最近更新 更多