caffe中的准确性问题
Accuracy issue in caffe
我有一个有 4 个布尔输出的网络。这不是一个分类问题,它们中的每一个都是有意义的。我希望每个人都能得到零或一。现在我已经使用了欧氏损失函数。
有 1000000 个样本。在输入文件中,每个都有 144 个特征,因此输入的大小为 1000000*144。
我使用了 50 的批量大小,否则处理时间太多。
输出文件的大小为 1000000*4,即每个输入有四个输出。
当我使用精度层时,它会抱怨输出的维度。它只需要一个布尔输出,而不是四个。我认为这是因为它将问题视为分类问题。
我有两个问题。
首先,考虑到accuracy layer的误差,欧几里得损失函数适合这个任务吗?以及如何获得网络的准确性?
其次,我将获得四个变量中每个变量的预测输出的准确值。我的意思是我需要每个测试记录的准确预测值。现在,我只有每批次的损失值。
请指导我解决这些问题。
谢谢,
阿夫欣
火车网络是:
{ 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"
或 更适合。通常使用"SoftmaxWithLoss"
。
对于预测二进制输出,您还可以考虑 .
为什么"Accuracy"
层有错误?
在caffe中,“Accuracy"
层需要两个输入(“底部”):一个是预测向量,另一个是地面真相预期 discrete 标签。
在您的情况下,您需要为每个二进制输出 提供一个长度为 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"
}
现在您需要为要预测的四个二进制标签中的每一个复制这三个层。
我有一个有 4 个布尔输出的网络。这不是一个分类问题,它们中的每一个都是有意义的。我希望每个人都能得到零或一。现在我已经使用了欧氏损失函数。
有 1000000 个样本。在输入文件中,每个都有 144 个特征,因此输入的大小为 1000000*144。 我使用了 50 的批量大小,否则处理时间太多。 输出文件的大小为 1000000*4,即每个输入有四个输出。
当我使用精度层时,它会抱怨输出的维度。它只需要一个布尔输出,而不是四个。我认为这是因为它将问题视为分类问题。 我有两个问题。 首先,考虑到accuracy layer的误差,欧几里得损失函数适合这个任务吗?以及如何获得网络的准确性? 其次,我将获得四个变量中每个变量的预测输出的准确值。我的意思是我需要每个测试记录的准确预测值。现在,我只有每批次的损失值。 请指导我解决这些问题。
谢谢, 阿夫欣
火车网络是:
{ 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"
或 "SoftmaxWithLoss"
。
对于预测二进制输出,您还可以考虑
为什么"Accuracy"
层有错误?
在caffe中,“Accuracy"
层需要两个输入(“底部”):一个是预测向量,另一个是地面真相预期 discrete 标签。
在您的情况下,您需要为每个二进制输出 提供一个长度为 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"
}
现在您需要为要预测的四个二进制标签中的每一个复制这三个层。