### Caffe中的精度问题

我有一个网络,它有4个布尔输出。这不是一个分类问题,每个输出都有意义。我希望每个输出都是零或一。目前我使用的是欧几里得损失函数。

样本总共有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会给我损失值。


回答:

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

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

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

中,”Accuracy"层期望两个输入(”bottom”s):一个是预测向量,另一个是预期的离散标签。在您的案例中,您需要为每个二进制输出提供一个长度为2的向量,包含0和1的预测概率,以及一个单一的二进制标签:

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

在这个例子中,您测量的是一个单一二进制输出的精度。输入"predict01"是批次中每个样本的二向量(对于batch_size: 50,这个blob的形状应该是50-by-2)。

您可以做些什么?

您试图在一个网络中预测4个不同的输出,因此,您需要4不同的损失和精度层。
首先,您需要将真实标签分割("Slice")成4个标量(而不是一个单一的二进制4向量):

layer {  name: "label_split"  bottom: "label" # 输入4向量的名称  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 # 因为您需要预测2个概率,一个为False,一个为True    ...}layer {  name: "loss01"  type: "SoftmaxWithLoss"  bottom: "predict01"  bottom: "label01"  top: "loss01"}layer {  name: "acc01"  type: "Accuracy"  bottom: "predict01"  bottom: "label01"  top: "acc01"}

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

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注