为什么pycaffe向后的结果总是为0?

时间:2018-12-09 02:40:33

标签: caffe pycaffe

net.blobs['data'].data[...] = transformed_image
output = net.forward()

output_prob = output['prob'][0]  # the output probability vector for the 
first image in the batch

print 'predicted class is:', output_prob.argmax()

label_index = output_prob.argmax()
caffeLabel = np.zeros((1,1000))
caffeLabel[0,label_index] = 1;

vis_layer = 'pool5' # visualization layer

grads=net.backward(diffs=[vis_layer],**{'prob':caffeLabel})
print(np.sum(grads))

我想以这种方式获得渐变,但是print(np.sum(grads))始终为0,我更改了conv5层或其他层,它不起作用!

1 个答案:

答案 0 :(得分:0)

我已经解决了该问题,将以下代码添加到了“ deploy.prototxt”

force_backward:true