首页 文章

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

提问于
浏览
1
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))

I want to get gradients in this way, but print(np.sum(grads)) is always 0, I change the layer conv5 or other layers, it did not work!

1 回答

  • 0

    I have solved the issue, added the following code to 'deploy.prototxt'

    force_backward:true
    

相关问题