使用训练好的模型进行预测的时候,为分析效果,通常需要对特征提取过程中的特征映射做可视化操作
本文以keras为例,对特征可视化操作进行详解。
一、首先,对模型的最后输出层进行特征可视化
from keras import models
#使用matlpotlib模块进行绘图的操作
import matplotlib.pylot as plt
#images是一个batch的输入图像,batch_input[batch图像数量,尺寸高,尺寸宽,3(rgb通道数量)]
#model是训练好的模型
#model = load_model('path')
nb_images = len(images)
batch_input = np.zeros((nb_images, net_h, net_w, 3))
# preprocess the input
for i in range(nb_images):
batch_input[i] = preprocess_input(images[i], net_h, net_w)
# run the prediction
#batch_output为一个样本的所有通道输出特征映射,本文应用特征金字塔结构,有三