kitten and resize it to 224x224 pixels net.blobs['data'].data[...] = transformer.preprocess('data', caffe.io.load_image(image)) # make a prediction from the kitten pixels out = net.forward() # extract the most likely prediction print("Predicted class is #{}.".format(out['prob'][0].argmax()))
into the network and make the prediction predict(image) # Get an empty set of probabilities probs = np.zeros_like(net.blobs['prob'].data) # Set the probability for our intended outcome to 1 probs[0][intended_outcome] = 1 # Do backpropagation to calculate the gradient for that outcome # and the image we put in gradient = net.backward(prob=probs) return gradient['data'].copy()