简体   繁体   English

如何在Keras中显示由Resnet50模型提取的图像的特征

[英]How can I display a features of a image that was extracted by a Resnet50 model in keras

So what I am trying to do is display the features that were extracted from a Resnet50 model and saved as a .npy. 因此,我想做的是显示从Resnet50模型提取并另存为.npy的功能。

I can read it in all and fine and the array looks fine. 我完全可以阅读它,数组看起来也很好。 But I cannot figure out a way to display the results well. 但是我无法找到一种很好地显示结果的方法。 How can I show this in matplotlib of opencv ? 如何在opencv matplotlib中显示此内容?

Here is what I have so far: 这是我到目前为止的内容:

import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from matplotlib import cm
import os

path = "ResnetFeatures/"

def load_resnet_features(file, path):
    file_path = os.path.join(path, file)
    return np.load(file_path)

test_file = '1500test.npy'




test_feature = load_resnet_features(test_file, path)
print(test_feature.shape)
test_feature = np.squeeze(test_feature, axis=0)
print(test_feature.shape)
test_feature = test_feature.reshape((49, 2048))
plt.imshow(test_feature)
plt.show()

Which gives this 这给这个

(1, 7, 7, 2048)
(7, 7, 2048)

This gives this, but it is not what I want. 这样就可以了,但这不是我想要的。 I would like something that is more square in shape are the original image is (224,224,3) 我想要形状更方形的东西是原始图像(224,224,3) 在此处输入图片说明

Ok I figured it out thanks to Jake P help. 好的,我感谢Jake P的帮助。 在此处输入图片说明

So I know the image can be reshaped like (49, 2048) So I brock apart 2048 to get this (7,7) (64, 32) Then just cross multipled (7*32) (7 * 64) 所以我知道图像可以像(49,2048)那样重塑,所以我将2048分开以得到(7,7)(64,32),然后交叉乘以(7 * 32)(7 * 64)

test_feature = test_feature.reshape((448, 224))
print_shape(test_feature)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:“ NoneType”对象在keras resnet50中没有属性“ image_data_format” - AttributeError: 'NoneType' object has no attribute 'image_data_format' in keras resnet50 用于Keras中特征提取的ResNet50输入问题 - ResNet50 input issue for feature extraction in Keras Image_classification 使用 resnet50 模型和 imagenet db 和我的自定义标签 - Image_classification using resnet50 model with imagenet db with my custom labels 将 Keras 生成器转换为 Tensorflow 数据集以训练 Resnet50 - Convert Keras generator to Tensorflow Dataset to train Resnet50 在以下用于分类的 ResNet50 模型中的 0 验证准确率背后的推理 - Reasoning behind 0 validation accuracy in the following ResNet50 model for classification TensorFlow2:ResNet50 - ValueError - TensorFlow2: ResNet50 - ValueError Pytorch:加载ResNet50模型时转储了非法指令核心 - Pytorch: Illegal instruction core dumped when loading ResNet50 model 在Nvidia RTX2080 Ti上使用Tensorflow2.0的“简单” ResNet50进行OOM - OOM with a “simple” ResNet50 using Tensorflow2.0 on an Nvidia RTX2080 Ti 我可以使用 pytorch resnet18 模型预测一个图像但不能预测一组图像,如何使用 pytorch 模型预测列表中的一组图像? - I can predict one image but not a set of images with a pytorch resnet18 model, how can i predict a set of images in a list using pytorch models? 如何在 Keras 回归模型中包含特征的归一化? - How to include normalization of features in Keras regression model?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM