Python 绘制模型多标签分类的所有预测

Python 绘制模型多标签分类的所有预测,python,matplotlib,neural-network,conv-neural-network,multilabel-classification,Python,Matplotlib,Neural Network,Conv Neural Network,Multilabel Classification,我想绘制我正在尝试培训的模型的输入和输出: 输入数据形状: processed_data.shape (100, 64, 256, 2) output.shape (100, 6) 它看起来是什么样子: processed_data array([[[[ 1.93965047e+04, 8.49532852e-01], [ 1.93965047e+04, 8.49463479e-01], 输出数据形状: processed_data.shape (100, 64, 2

我想绘制我正在尝试培训的模型的输入和输出:

输入数据形状:

processed_data.shape
(100, 64, 256, 2)
output.shape
(100, 6)
它看起来是什么样子:

processed_data
array([[[[ 1.93965047e+04,  8.49532852e-01],
         [ 1.93965047e+04,  8.49463479e-01],
输出数据形状:

processed_data.shape
(100, 64, 256, 2)
output.shape
(100, 6)
输出基本上是每个标签的概率

output = model.predict(processed_data)

output
array([[0.53827614, 0.64929205, 0.48180097, 0.50065327, 0.43016508,
        0.50453395]
我想以某种方式为处理后的数据中的每个实例绘制类的预测概率(因为这是多标签分类问题),但我很难做到这一点。 因此,我如何绘制处理后的数据,但不确定如何绘制每个输入实例的概率。我希望能够在每个输出上标记所有6个可能的类。我有点迷路了。。。 有什么建议吗

到目前为止,我只打印输入: 形状=输出。形状[0]

for i in range(it):
    fig,axs = plt.subplots(5,2,figsize=(10,10))

    if isinstance(data,list): 
        inp = data[i]
        outp = output[i]
    else: 
        inp = data
        outp = output

    for j in range(5):
        r = randint(0,shape)
        axs[j,0].imshow(inp[r,...,0]); 
        axs[j,0].title.set_text('Input {}'.format(r))

我编辑了我的回答,因为我更好地理解了这个问题。此代码将打印图像和输出

import matplotlib.image as mpimg
import numpy as np
import matplotlib.pyplot as plt

img_paths = ['../python/imgs/Image001.png',
             '../python/imgs/Image002.png',
             '../python/imgs/Image003.png',
             '../python/imgs/Image004.png',
             '../python/imgs/Image005.png']

input  = np.array([mpimg.imread(path) for path in img_paths])
output = np.random.rand(5, 6)

print(input.shape, output.shape)

fig, axs = plt.subplots(2, 5, figsize=(8, 4), sharey = 'row')

for i, sample in enumerate(range(5)):
    o = output[sample]

    axs[0,i].set_title(f'Sample {sample + 1}')
    axs[0,i].imshow(input[i,:])
    axs[0,i].axis('off')

    axs[1,i].bar(range(6), o)
    axs[1,i].set_xticks(range(6))
    axs[1,i].set_xticklabels([f'{i+1}' for i in range(6)])

plt.show()
输出:

(5, 1510, 2560, 4) (5, 6)


重要的部分是调用,在调用中,您可以根据自己的喜好创建一个绘图网格(如果您想要实际绘制所有100幅图像,您可能会更喜欢垂直布局)。

现在我编辑了我的回答,因为我更好地理解了这个问题。此代码将打印图像和输出

import matplotlib.image as mpimg
import numpy as np
import matplotlib.pyplot as plt

img_paths = ['../python/imgs/Image001.png',
             '../python/imgs/Image002.png',
             '../python/imgs/Image003.png',
             '../python/imgs/Image004.png',
             '../python/imgs/Image005.png']

input  = np.array([mpimg.imread(path) for path in img_paths])
output = np.random.rand(5, 6)

print(input.shape, output.shape)

fig, axs = plt.subplots(2, 5, figsize=(8, 4), sharey = 'row')

for i, sample in enumerate(range(5)):
    o = output[sample]

    axs[0,i].set_title(f'Sample {sample + 1}')
    axs[0,i].imshow(input[i,:])
    axs[0,i].axis('off')

    axs[1,i].bar(range(6), o)
    axs[1,i].set_xticks(range(6))
    axs[1,i].set_xticklabels([f'{i+1}' for i in range(6)])

plt.show()
输出:

(5, 1510, 2560, 4) (5, 6)


重要的部分是调用,在调用中,您可以根据自己的喜好创建打印网格(如果您想要实际打印所有100幅图像,您可能更喜欢垂直布局)。

嘿,非常感谢您的帮助。对不起,如果我的问题不是很清楚。实际上,我想在输入的同时绘制这些预测(这样我可以立即检查)它们是否正确。你对怎么做有什么建议吗?或者可能只是在已经存在的输入图形(我上面有)上绘制结果?非常感谢你的帮助@lúlúlúlúlú_l@saraherceg谢谢,我想我能更好地理解这个问题。看看我的编辑。非常感谢你的帮助和详细的例子!我真的很感激!这帮了大忙!嘿,非常感谢你的帮助。对不起,如果我的问题不是很清楚。实际上,我想在输入的同时绘制这些预测(这样我可以立即检查)它们是否正确。你对怎么做有什么建议吗?或者可能只是在已经存在的输入图形(我上面有)上绘制结果?非常感谢你的帮助@lúlúlúlúlú_l@saraherceg谢谢,我想我能更好地理解这个问题。看看我的编辑。非常感谢你的帮助和详细的例子!我真的很感激!这帮了大忙!