我已经训练了一个cnn模型来对狗和猫的图像进行分类,它提供了98%的准确率,但我想可视化cnn层的输出,即我的cnn预测它是狗还是猫的特征,如果有什么方法可以可视化cnn的输出?
发布于 2019-05-14 21:05:10
您可以将模型分为两个模型:
以前的型号:
input = Input(...)
# Your Layers
output = Dense(1)
old_model = Model(inputs=[input], output)
新模型:
input = Input(...)
#Add the first layers and the CNN here
cnn_layer = Conv2D(...)
feature_extraction_model = Model(inputs=[input], outputs=cnn_layer)
input_cnn = Input(...) # The shape of your CNN output
# Add the classification layer here
output = Dense(1)
classifier_model = Model(inputs=[input_cnn], outputs=output)
现在,您将新模型定义为:feature_extraction_model和classifier_model的组合
new_model = Model(inputs=[input], outputs=classifier_model(input_cnn))
# Train the model
new_model.fit(x, y)
现在,您可以访问CNNlayer post培训:
cnn_output = feature_extraction_model.predict(x)
https://stackoverflow.com/questions/56130678
复制相似问题