首页 > 解决方案 > 如何在 keras 中显示由 Resnet50 模型提取的图像的特征

问题描述

所以我要做的是显示从 Resnet50 模型中提取并保存为 .npy 的特征。

我可以全部阅读,而且数组看起来很好。但我想不出一种方法来很好地显示结果。我怎样才能显示matplotlib这个opencv

这是我到目前为止所拥有的:

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()

这给了这个

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

这给出了这个,但这不是我想要的。我想要一些形状更方形的东西,原始图像是 (224,224,3) 在此处输入图像描述

标签: python-3.xmatplotlibpython-imaging-library

解决方案


好的,感谢 Jake P 的帮助,我想通了。 在此处输入图像描述

所以我知道图像可以像 (49, 2048) 一样重塑所以我将 2048 分开以获得 (7,7) (64, 32) 然后交叉乘法 (7*32) (7 * 64)

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

推荐阅读