Esempio n. 1
0
def plot_more_than_three_canals(input_, prediction, groundtruth, labels):
    plt.figure(figsize=(40, 16))
    line_number = input_.shape[0]
    col_number = groundtruth.shape[-1] + 3
    for i, (input_thumb, pred_thumb,
            truth_thumb) in enumerate(zip(input_, prediction, groundtruth)):
        plt.subplot(line_number, col_number, i * col_number + 1)
        imshow(input_thumb, cmap='gray')
        if not i and labels is not None:
            plt.title(labels[0])

        plt.subplot(line_number, col_number, i * col_number + 2)
        imshow(pred_thumb)
        if not i and labels is not None:
            plt.title(labels[1])

        plt.subplot(line_number, col_number, i * col_number + 3)
        imshow(truth_thumb)
        if not i and labels is not None:
            plt.title(labels[2])

        for canal in range(pred_thumb.shape[2]):
            plt.subplot(line_number, col_number, i * col_number + canal + 4)
            imshow(pred_thumb[:, :, canal], cmap=COLORMAPS[canal])
            plt.colorbar()
            if not i and labels is not None and len(labels) > 3 + canal:
                plt.title(f"Prediction: {labels[3 + canal]}")
Esempio n. 2
0
def plot_regressor_distribution(examples, truths, predictions, attributes,
                                means, stds):
    plt.figure(figsize=(6 * (len(attributes) + 1), 4 * 4))

    for i, example in zip(range(3), examples):
        if i < len(example):
            plt.subplot(3, len(attributes) + 1, 1 + i * (len(attributes) + 1))
            imshow(example, vmax=1)

            prediction = np.round(predictions[i] * stds + means, 2)
            truth = np.round(truths[i] * stds + means, 2)
            plt.title(f'Prediction: {prediction}\nTruth: {truth}',
                      fontdict={'horizontalalignment': 'right'})

    for i, attribute in enumerate(attributes):
        mean = means[i]
        std = stds[i]

        plt.subplot(3, len(attributes) + 1, i + 2)

        plt.hist(predictions[:, i] * std + mean,
                 bins=20,
                 range=(-std + mean, std + mean),
                 density=True)
        plt.title(attribute)
        if not i:
            plt.ylabel('Predictions')

        plt.subplot(3, len(attributes) + 1, i + 2 + len(attributes) + 1)
        plt.hist(truths[:, i] * std + mean,
                 bins=20,
                 range=(-std + mean, std + mean),
                 density=True)
        if not i:
            plt.ylabel('Truth')

        plt.subplot(3, len(attributes) + 1, i + 2 + 2 * (len(attributes) + 1))
        plt.hist(abs(truths[:, i] - predictions[:, i]),
                 bins=20,
                 range=(0, 2),
                 density=True)
        if not i:
            plt.ylabel('Normalized Absolute Error')
Esempio n. 3
0
def plot_example(example, prediction, labels, limit=LIMIT):
    input_, truth = example
    input_ = input_[:limit]
    n = input_.shape[0]
    plt.figure(figsize=(27, 12))
    plt.tight_layout()
    for i, (im, classes) in enumerate(zip(input_, prediction)):
        if i != 0:
            tick_label = [' ' for _ in labels]
        else:
            tick_label = labels
        plt.subplot(2, n, i + 1)
        imshow(im, vmax=1)

        plt.subplot(2, n, i + 1 + n)
        plt.barh(labels, truth[i], tick_label=tick_label, color='C1')
        plt.barh(labels, classes, tick_label=tick_label, color='C0')
        plt.xlim(0, 1)
        plt.yticks()
    plt.tight_layout()
Esempio n. 4
0
def plot_less_than_three_canals(input_, prediction, groundtruth, labels):
    plt.figure(figsize=(max(256, input_.shape[2]) / 100 * 9,
                        max(256, input_.shape[1]) / 100 * 3.5))
    if groundtruth is None:
        line_number = 2
    else:
        line_number = 3
    col_number = input_.shape[0]

    for i, im in enumerate(input_):
        plt.subplot(line_number, col_number, 1 + i)
        imshow(input_[i], vmin=0, vmax=255)
        if not i and labels is not None:
            plt.title(labels[0])

        plt.subplot(line_number, col_number, i + 1 + col_number)
        imshow(prediction[i], vmin=0, vmax=255, cmap='hot')
        if not i and labels is not None:
            plt.title(labels[1])

        if line_number == 3:
            plt.subplot(line_number, col_number, i + 1 + col_number * 2)
            imshow(groundtruth[i], vmin=0, vmax=255)
            if not i and labels is not None:
                plt.title(labels[2])
Esempio n. 5
0
def plot_regressor_on_color(examples, truths, predictions, means, stds):
    plt.figure(figsize=(4 * 4, 3 * 4))

    for i, (example, truth,
            prediction) in enumerate(zip(examples[:12], truths, predictions)):
        plt.subplot(3, 4, i + 1)
        imshow(example, vmax=1)

        prediction = prediction * stds + means
        truth = truth * stds + means
        if means[0] > 1:
            prediction = prediction / 255
            truth = truth / 255

        plt.text(example.shape[0] / 2 * 1.05,
                 -example.shape[1] / 12,
                 '████',
                 color=np.clip(prediction, 0, 1))
        plt.text(example.shape[0] / 2 * 1.05,
                 -example.shape[1] / 35,
                 '████',
                 color=np.clip(truth, 0, 1))
        plt.title(f'\nPrediction:\nTruth:',
                  fontdict={'horizontalalignment': 'right'})