在测试或预测的每个输入处调用特定函数?

Calling particular function at each input on testing or on prediction?

我想在 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

您可以为 include { phase: TEST } 添加一个 python 层,这只会转换您的测试输入。