可视化InceptionResnetV2学习的功能

时间:2019-02-23 09:53:56

标签: tensorflow machine-learning keras deep-learning computer-vision

我已经训练了一个InceptionResnetV2模型来对我在keras中的图像执行4分类问题。现在,我需要通过训练好的模型传递测试图像,以查看我的模型实际学习了哪些功能。我的意图是可视化到最后一层,但是当我遵循this教程时,我从前12层开始。

当我调用模型的激活层进行可视化时,出现参数错误

  

tensorflow.python.framework.errors_impl.InvalidArgumentError:没有这样的可调用句柄:6490197728   tensorflow.python.framework.errors_impl.InvalidArgumentError:输入_1:0都被输入和获取。

我想念什么

这是我的密码

from keras.preprocessing import image
from tensorflow.keras.models import Model
import numpy as np
import tensorflow as tf



img_path='../../../data/fourclasses/class_label/205.jpg'

img = image.load_img(img_path, target_size=(299, 299))
img = image.img_to_array(img)
img = np.expand_dims(img, axis=0)
img /= 255.

new_model=tf.keras.models.load_model('test_model.model')
predictions=new_model.predict(img)
print(predictions)
label = np.argmax(predictions, axis=1)
print(label)

# Extracts the outputs of the top 12 layers
layer_outputs = [layer.output for layer in new_model.layers[:12]]


# Creates a model that will return these outputs, given the model input
# activation_model = models.Model(inputs=new_model.input, 
outputs=layer_outputs)

activation_model = Model(inputs=new_model.input, outputs=layer_outputs)


print(img.shape)

# Returns a list of five Numpy arrays: one array per layer activation
activations = activation_model.predict(img)

# first layer activation
first_layer_activation = activations[0]
print(first_layer_activation.shape)

我希望看到一个输出,上面有投影的功能,如本示例enter image description here

0 个答案:

没有答案