【问题标题】:Caffe: How to check accuracies of multiple Data sets with already trained model at a time?Caffe:如何使用已经训练好的模型一次检查多个数据集的准确性?
【发布时间】:2016-11-04 13:41:12
【问题描述】:

在 Caffe 框架中使用 2 个类别的 10k 图像训练 LeNet 模型后,我得到了包含权重和偏差的模型 lenet_iter_4000.caffemodel。我想一次检查 5k 新测试图像(在训练时不属于测试图像的一部分)的准确性。我为所有这些 5k 图像创建了 lmdb 文件。我知道如何使用以下方法测试图像。

./build/tools/caffe test --model=examples/mnist/lenet_train_test.prototxt --weights=examples/mnist/lenet_iter_4000.caffemodel

但是我无法一次获得准确度,例如在训练时如果我们输入 test_interval 3000 将获得准确度,我们将在 3000 迭代后获得所有测试图像的准确度。如果我想在训练后的某个时间测试准确性,我必须在 prototxt 中进行更改。 我的问题是:如何在使用经过训练的模型进行训练后获得多个数据集的准确性?

【问题讨论】:

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


    【解决方案1】:

    一种快速的解决方案是在训练时获得多个数据集的准确度。您可以通过修改您的solver.prototxt和net.prototxt来实现这一点,如下所示,更具体地说是在solver.prototxt中使用多个“test_state”和多个具有不同“include:{stage:”xxx“}”的数据层net.prototxt 用于测试多个数据集:

    solver.prototxt:

    net: "lenet_train_test.prototxt"
    #testing stage for your orininal test images
    test_state: { stage: "original test" }
    #testing stage for your new test images
    test_state: { stage: "new 5k test" }
    #iterations for original testing
    test_iter: xxx
    #iterations for your new 5k testing
    test_iter: xxx
    #Those 2 testings use the same test_interval
    test_interval: 500
    

    对应的net.prototxt:

    name: "LeNet"
    layer {
      name: "mnist"
      type: "Data"
      top: "data"
      top: "label"
      include {
        phase: TRAIN
      }
      transform_param {
        scale: 0.00390625
      }
      data_param {
        source: "examples/mnist/mnist_train_lmdb"
        batch_size: 32
        backend: LMDB
        shuffle: true
      }
    }
    layer {
      name: "mnist"
      type: "Data"
      top: "data"
      top: "label"
      include {
        phase: TEST
        stage: "original test"
      }
      transform_param {
        scale: 0.00390625
      }
      data_param {
        source: "examples/mnist/mnist_test_lmdb"
        batch_size: 100
        backend: LMDB
      }
    }
    layer {
      name: "mnist"
      type: "Data"
      top: "data"
      top: "label"
      include {
        phase: TEST
        stage: "new 5k test"
      }
      transform_param {
        scale: 0.00390625
      }
      data_param {
        source: "path/to/your/5k_images_test_lmdb"
        batch_size: 100
        backend: LMDB
      }
    }
    .
    .
    .
    layer {
      name: "accuracy"
      type: "Accuracy"
      bottom: "ip2"
      bottom: "label"
      top: "accuracy"
      include {
        phase: TEST
      }
    }
    layer {
      name: "loss"
      type: "SoftmaxWithLoss"
      bottom: "ip2"
      bottom: "label"
      top: "loss"
    }
    

    并像微调一样使用它们:

    ./build/tools/caffe train --solver=examples/mnist/solver.prototxt --weights=examples/mnist/lenet_iter_4000.caffemodel
    

    在第 0 次迭代时,求解器将测试多个数据集,您将获得它们的多个精度,然后可以停止求解器。

    【讨论】:

    • 我想在使用经过训练的模型进行训练后获得多个数据集的准确度。
    • 您的问题的快速解决方案可以是这样的:/build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt --weights=examples/mnist/lenet_iter_4000.caffemodel。 lenet_solver.prototxt 和相应的 net.prototxt 应该像我的回答一样修改。
    • 我明白,但我已经训练了几个小时的模型。我想使用该模型进行测试,以节省时间。我已经为 LeNet 提供了示例。但我已经为 1 训练了 AlexNet 模型day.我想使用经过训练的 Alexnet 模型进行测试。
    • 在第 0 次迭代中,求解器将测试您的 2 个数据集,包括您的 5k 图像,您将获得它们的准确度。然后你可以阻止它。这是我能想到的最快的方法。否则,您应该修改 caffe.cpp 中的 test() 函数,就像 Solver::Init() 所做的那样,以维护多个网络进行测试,这有点微不足道。 @BHAV247
    • Alexnet模型用于测试的解决方案与lenet相同,只是修改sovler.prototxt添加“test_state”和alexnet.prototxt为你的5k测试图像添加一个数据层。测试时间一点也不长。 @BHAV247
    【解决方案2】:

    只要用caffe的测试工具,检查the interface examples

    我来晚了,但是想知道如何将训练模型仅用于测试目的的人可以使用 caffe 的测试工具。如果您训练了模型,并计划在之后使用它,那么您应该在每次迭代时保存权重。我们将最终保存的权重命名为 model_iter_xxxx.caffemodel。

    1. 将模型复制到 model_test.prototxt(例如)

    2. 添加要在测试阶段考虑的层,即用于测试数据的输入层和准确性层。

    3. 运行:caffe test -model path/to/model_test.prototxt -weights path/to/model_iter_xxxx.caffemodel -iterations 100

    【讨论】:

      猜你喜欢
      • 2021-09-27
      • 2018-01-14
      • 1970-01-01
      • 2019-01-30
      • 2023-04-09
      • 2015-11-28
      • 2023-02-17
      • 1970-01-01
      • 2018-02-08
      相关资源
      最近更新 更多