-1

我想在测试时为 MNIST 数据集的每个输入调用一个函数。例如,如果 MNIST 中的测试数据是 x1, ... , xn 对于每个输入 xi 在测试时我想调用该函数。我修改了“ http://nbviewer.ipython.org/github/BVLC/caffe/blob/tutorial/examples/01-learning-lenet.ipynb ”中的代码,这样我就注释了“#solver.step(1) # SGD by Caffe”,因为我不想对网络进行任何训练。但我认为这不是正确的方法,因为与原始代码相比,准确性会降低。请为如何实施它提供任何帮助。

我认为曾经可以更改的代码。

%%time
niter = 200
test_interval = 25
# losses will also be stored in the log
train_loss = zeros(niter)
test_acc = zeros(int(np.ceil(niter / test_interval)))
output = zeros((niter, 8, 10))
# the main solver loop
for it in range(niter):
    solver.step(1)  # SGD by Caffe

# store the train loss
#train_loss[it] = solver.net.blobs['loss'].data

# store the output on the first test batch
# (start the forward pass at conv1 to avoid loading new data)
#solver.test_nets[0].forward(start='conv1')
output[it] = solver.test_nets[0].blobs['ip2'].data[:8]

# run a full test every so often
# (Caffe can also do this for us and write to a log, but we show here
#  how to do it directly in Python, where more complicated things are easier.)
if it % test_interval == 0:
    print 'Iteration', it, 'testing...'
    correct = 0
    for test_it in range(100):
        solver.test_nets[0].forward()
        correct += sum(solver.test_nets[0].blobs['ip2'].data.argmax(1)
                       == solver.test_nets[0].blobs['label'].data)
    test_acc[it // test_interval] = correct / 1e4
4

1 回答 1

1

您可以添加一个 python 层,include { phase: TEST }仅用于转换您的测试输入。

于 2016-01-10T06:36:14.277 回答