File size: 1,274 Bytes
c18b721
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from abcli import string
import matplotlib.pyplot as plt
import numpy as np
import abcli.logging
import logging

logger = logging.getLogger(__name__)


def plot_image(i, predictions_array, true_label, image, class_names):
    plt.grid(False)
    plt.xticks([])
    plt.yticks([])

    plt.imshow(image[i], cmap=plt.cm.binary)

    predicted_label = np.argmax(predictions_array)

    if true_label is None:
        color = "black"
    elif predicted_label == true_label[i]:
        color = "blue"
    else:
        color = "red"

    plt.xlabel(
        "{} {:2.0f}%{}".format(
            string.shorten(class_names[predicted_label]),
            100 * np.max(predictions_array),
            ""
            if true_label is None
            else " ({})".format(string.shorten(class_names[true_label[i]])),
        ),
        color=color,
    )


def plot_value_array(i, predictions_array, true_label):
    plt.grid(False)
    plt.xticks(range(len(predictions_array)))
    plt.yticks([])
    handle = plt.bar(range(len(predictions_array)), predictions_array, color="#777777")
    plt.ylim([0, 1])
    predicted_label = np.argmax(predictions_array)

    handle[predicted_label].set_color("green")
    if true_label is not None:
        handle[true_label[i]].set_color("blue")