最近我创建了用于猫和狗分类的基本 CNN 模型(非常基本)。如何使用 keras 可视化这些层的输出?我使用 keras 的 Tensorflow 后端。
您可以定义一个模型,获取您想要查看的每一层的输出并进行预测:
假设您有完整的模型:
cnnModel = #a model you have defined with layers
假设您想要索引 1、5 和 8 层的输出。
使用这些层的输出从该模型创建一个新模型。
from keras.models import Model
desiredLayers = [1,5,8]
desiredOutputs = [cnnModel.layers[i].output for i in desiredLayers]
#alternatively, you can use cnnModel.get_layer('layername').output for that
newModel = Model(cnnModel.inputs, desiredOutputs)
使用该模型进行预测:
print(newModel.predict(inputData))
现在,“可视化”这些结果可能很棘手,因为它们可能比常规图像具有更多的通道。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)