如何将1D numpy数组从keras层输出更改为image(3D numy array)

2024-04-19 01:16:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个keras层的输出或特性图,但是如何将其转换为可以显示的图像(3D numpy数组)。在

model = VGG16(weights='imagenet', include_top=True)
layer_outputs = [layer.output for layer in model.layers[1:]]
print layer_outputs
viz_model = Model(input=model.input,
                  output=layer_outputs)
features = viz_model.predict(x)

output = features[0] #has shape (1,224,224,64)

如有任何意见或建议,我们将不胜感激。谢谢您。在


Tags: 图像numpylayerinputoutputmodel数组特性
1条回答
网友
1楼 · 发布于 2024-04-19 01:16:43

在迭代每个要素图时,可以将每个要素图添加为一个子图:

import numpy as np
import matplotlib.pyplot as plt
from pylab import cm

m = np.random.rand(1,224,224,64)

fig = plt.figure()
fig.suptitle("Feature Maps")

for j in range(m.shape[3]):
    ax = fig.add_subplot(8, 8, j+1)
    ax.matshow(m[0,:,:,j], cmap=cm.gray)
    plt.xticks(np.array([]))
    plt.yticks(np.array([]))

plt.show()

这会给你一些像这样的东西(在我的情况下只是噪音):

enter image description here

相关问题 更多 >