准确度始终为 1 Caffe 回归 [英] Accuracy always 1 Caffe Regression

查看:19
本文介绍了准确度始终为 1 Caffe 回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据集包含 400 张 32x32x3 的图像,标签包含浮点数 (-1,1).示例:

My dataset contains 400 images 32x32x3 and the labels contain float number (-1,1). Example:

faceCroppedImages/img1.jpg 0
faceCroppedImages/img2.jpg 0.0128
faceCroppedImages/img3.jpg 0.0128
faceCroppedImages/img4.jpg 0.0128
faceCroppedImages/img22.jpg 0.0128
faceCroppedImages/img23.jpg 0.0085
faceCroppedImages/img24.jpg 0.0077
faceCroppedImages/img25.jpg 0.0077
faceCroppedImages/img293.jpg -0.023
faceCroppedImages/img294.jpg -0.023
faceCroppedImages/img295.jpg -0.0204
faceCroppedImages/img296.jpg -0.0179
faceCroppedImages/img297.jpg -0.017
faceCroppedImages/img298.jpg -0.0128

我的'solver.prototxt'是:

net: "train_test_hdf5.prototxt"
test_iter: 100
test_interval: 500
base_lr: 0.003
momentum: 0.9
weight_decay: 0.0005
lr_policy: "inv"
gamma: 0.0001
power: 0.75
display: 100
max_iter: 10000
snapshot: 5000
snapshot_prefix: "lenet_hdf5"
solver_mode: CPU

'train_test_hdf5.prototxt'是:

name: "MSE regression"
layer{
  name: "data"
  type: "HDF5Data"
  top: "data"
  top: "label"
  hdf5_data_param {
    source: "train_hdf5file.txt"
    batch_size: 64
    shuffle: true
  }
  include: { phase: TRAIN }
}

layer{
  name: "data"
  type: "HDF5Data"
  top: "data"
  top: "label"
  hdf5_data_param {
    source: "test_hdf5file.txt"
    batch_size: 128
  }
  include: { phase: TEST }
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  param { lr_mult: 1 }
  param { lr_mult: 2 }
  convolution_param {
    num_output: 20
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
    }
    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: 2
    stride: 2
  }
}
layer {
  name: "dropout1"
  type: "Dropout"
  bottom: "pool1"
  top: "pool1"
  dropout_param {
    dropout_ratio: 0.1
  }
}

layer{
  name: "fc1"
  type: "InnerProduct"
  bottom: "pool1"
  top: "fc1"
  param { lr_mult: 1 decay_mult: 1 }
  param { lr_mult: 2 decay_mult: 0 }
  inner_product_param {
    num_output: 500
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "dropout2"
  type: "Dropout"
  bottom: "fc1"
  top: "fc1"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer{
  name: "fc2"
  type: "InnerProduct"
  bottom: "fc1"
  top: "fc2"
  param { lr_mult: 1 decay_mult: 1 }
  param { lr_mult: 2 decay_mult: 0 }
  inner_product_param {
    num_output: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
 }
}
layer {
  name: "accuracy1"
  type: "Accuracy"
  bottom: "fc2"
  bottom: "label"
  top: "accuracy1"
  include {
    phase: TEST
  }
}
layer{
  name: "loss"
  type: "EuclideanLoss"
  bottom: "fc2"
  bottom: "label"
  top: "loss"
}

但是,当我测试数据时,准确度始终为 1:

However when I'm testing the data the accuracy is always 1:

我尝试使用整数标签将当前标签乘以 1000,但出现 nan 错误:

I tried using integer labels my multiplying my current labels by 1000, but I'm getting the nan error:

你能告诉我我哪里做错了吗?我是咖啡和神经网络的初学者.任何建议都会很有价值.TIA.

Can you please tell me where I'm doing wrong? I'm a beginner in caffe and neural networks. Any suggestions will be valuable. TIA.

推荐答案

使用 "Accuracy" 层进行回归任务没有意义:该层衡量分类输出的准确性.
例如,如果您试图预测 L 标签之一,fc2 层的 num_output 将是 L -也就是说,预测每个类别的概率.然后"Accuracy"层检查l-th条目的概率,对应于预期的输出l.
fc2 输出只有一维时,你如何计算这样的准确度?

No point using "Accuracy" layer for regression task: this layer measures the accuracy of classification output.
For instance, if you are trying to predict one of L labels, num_output of fc2 layer will be L - that is, predicting a probability per class. Then "Accuracy" layer checks that the probability of the l-th entry, corresponding to the expected output l is maximal.
How can you compute such accuracy when fc2 output is only 1 dimensional?

在您的情况下,您只能检查欧几里得损失并看到它在测试和训练中都在减少.

In your case, you can only check the Euclidean loss and see it decreasing for both test and train.

这篇关于准确度始终为 1 Caffe 回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆