python - 提取cnn的输出
问题描述
我已经训练了一个 cnn 模型来对狗和猫的图像进行分类,它给出了 98% 的准确率但是我想可视化 cnn 层的输出,即我的 cnn 预测它是狗还是猫的特征如果有的话可视化 cnn 的输出?
解决方案
您可以将模型分为两个模型:
以前的型号:
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 后期培训:
cnn_output = feature_extraction_model.predict(x)
推荐阅读
- python - 将两个数据帧添加在一起,但 ID 继续。替换重复项?
- fusioncharts - 当我们将鼠标悬停在FusionCharts多系列面积图中的特定区域上时,如何在工具提示上显示特定区域的图例?
- optimization - 解决 NLP 时目标值不一致
- swift - Swift - UIScrollView 内的 UICollectionView - 自动布局
- javascript - Javascript d3 没有 1 个 CSV 的标题
- angular - 使用 *ngFor 循环角 10 在表中显示嵌套对象
- python - 用于债券的 Xbbg Python 包装器
- drupal - 如何通过 URL 或菜单路径查询 Drupal 快捷方式 (8.x/9.x)?
- javascript - How come YouTube can autoplay videos without user interaction but no other site can?
- c++ - 在 MacOS 上构建项目时,Cmake '无法在生成多个输出文件时指定 -o'