一文带你用可视化理解卷积神经网络(17)

现在 , 我们将进行下面三个步骤:

  • 预处理原图像

  • 计算有不同遮挡部分的图片的概率

  • 生成热图

from keras.preprocessing.image import img_to_array
from keras.applications.vgg16 import preprocess_input
# convert the image pixels to a numpy array
image = img_to_array(image)
# reshape data for the model
image = image.reshape((1 image.shape[0
image.shape[1
image.shape[2
))
# prepare the image for the VGG model
image = preprocess_input(image)
# predict the probability across all output classes
yhat = model.predict(image)
temp = image[0

print(temp.shape)
heatmap = np.zeros((224224))
correct_class = np.argmax(yhat)
for n(xyimage) in enumerate(iter_occlusion(temp14)):
heatmap[x:x+14y:y+14
= model.predict(image.reshape((1 image.shape[0

推荐阅读