【问题标题】:Caffe accuracy.layer accuracy error when I revise the accuracyCaffe accuracy.layer 修改精度时的精度错误
【发布时间】:2017-02-17 18:04:24
【问题描述】:

当我为我的回归项目修改精度时,Caffe accuracy.layer 精度错误: 修改精度的accuracy.layer代码:

for (int i = 0; i < outer_num_; ++i) 
  for (int j = 0; j < inner_num_; ++j) {
    Distance = sqrt((bottom_data[i * dim + j] - bottom_label[i * inner_num_ + j])*(bottom_data[i * dim + j] - bottom_label[i * inner_num_ + j]));   
    if (Distance <= 10) {           
         ++accuracy;        
    }
  }
}

但结果是:

I1008 22:14:37.701171 102764 caffe.cpp:286] Loss: 70993.9
I1008 22:14:37.701171 102764 caffe.cpp:298] accuracy = -1.#IND

这是我的net.prototxt

    layer {
        name: "framert"
        type: "HDF5Data"
        top: "data"
        top: "label"
        include {
            phase: TRAIN
        }
        hdf5_data_param {
            source: "G:/lab-zhang/caffe-windows/data/csv/train_data_list.txt"
            batch_size: 10
        }
    }
    layer {
        name: "inner1"
        type: "InnerProduct"
        bottom: "data"
        top: "inner1"
        param {
            lr_mult: 1
            decay_mult: 1.5
        }
        param {
            lr_mult: 2
            decay_mult: 0
        }
        inner_product_param {
            num_output: 50
            weight_filler {
                type: "xavier"
            }
            bias_filler {
                type: "constant"
                value: 0.1
            }
        }
    }
    layer {
        name: "inner2"
        type: "InnerProduct"
        bottom: "inner1"
        top: "inner2"
        param {
            lr_mult: 1
            decay_mult: 1.0
        }
        param {
            lr_mult: 2
            decay_mult: 0
        }
        inner_product_param {
            num_output: 1   
            weight_filler {
                type: "xavier"
            }
            bias_filler {
                type: "constant"
                value: 0.1
            }
        }
    }
    layer {
        name: "relu1"
        type: "ReLU"
        bottom: "inner2"
        top: "inner2"
        relu_param {
            engine: CAFFE
        }
    }
    layer {
        name: "accuracy"
        type: "Accuracy"
        bottom: "inner2"
        bottom: "label"
        top: "accuracy"
        include {
            phase: TEST
        }
    }
    layer {
        name: "loss"
        type: "EuclideanLoss"
        bottom: "inner2"
        bottom: "label"
        top: "loss"
    }

错误结果的原因是什么:accuracy:-1.#IND? 这是我的net.prototxt

layer {
    name: "framert"
    type: "HDF5Data"
    top: "data"
    top: "label"
    include {
        phase: TRAIN
    }
    hdf5_data_param {
        source: "G:/lab-zhang/caffe-windows/data/csv/train_data_list.txt"
        batch_size: 10
    }
}
layer {
    name: "inner1"
    type: "InnerProduct"
    bottom: "data"
    top: "inner1"
    param {
        lr_mult: 1
        decay_mult: 1.5
    }
    param {
        lr_mult: 2
        decay_mult: 0
    }
    inner_product_param {
        num_output: 50
        weight_filler {
            type: "xavier"
        }
        bias_filler {
            type: "constant"
            value: 0.1
        }
    }
}
layer {
    name: "inner2"
    type: "InnerProduct"
    bottom: "inner1"
    top: "inner2"
    param {
        lr_mult: 1
        decay_mult: 1.0
    }
    param {
        lr_mult: 2
        decay_mult: 0
    }
    inner_product_param {
        num_output: 1   
        weight_filler {
            type: "xavier"
        }
        bias_filler {
            type: "constant"
            value: 0.1
        }
    }
}
layer {
    name: "relu1"
    type: "ReLU"
    bottom: "inner2"
    top: "inner2"
    relu_param {
        engine: CAFFE
    }
}
layer {
    name: "accuracy"
    type: "Accuracy"
    bottom: "inner2"
    bottom: "label"
    top: "accuracy"
    include {
        phase: TEST
    }
}
layer {
    name: "loss"
    type: "EuclideanLoss"
    bottom: "inner2"
    bottom: "label"
    top: "loss"
}

【问题讨论】:

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


【解决方案1】:

您得到的准确度:-1.#IND 表示您的代码计算的值是 not a number (NaN)
从您发布的代码中不清楚为什么您会收到 NaN。我怀疑您更改了太多准确层代码并引入了导致Nan 的错误。
确保不要忘记更新 count 并确保 update top[0]-&gt;mutable_cpu_data()[0] 具有计算的准确度。


一般来说,最好不要覆盖现有层,而是编写具有所需功能的新层。
编写新层时,请遵循caffe wikiin this git issue 中的指南。具体来说,为您的图层编写一个测试!

【讨论】:

  • 感谢您的帮助!我更新了'top[0]->mutable_cpu_data()[0] = accuracy / count;'。我会尝试创建自己的 accuracy.layer
猜你喜欢
  • 2015-11-21
  • 1970-01-01
  • 2020-04-27
  • 2015-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多