-
Notifications
You must be signed in to change notification settings - Fork 4
/
display.py
90 lines (88 loc) · 3.42 KB
/
display.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import matplotlib.pyplot as plt
import cv2
import predict_func
import tensorflow as tf
from data import *
import numpy as np
def show_history(history, validation : bool = False):
if validation:
# Loss
fig, axes = plt.subplots(figsize= (20,5))
# Train
axes.plot(history.epoch, history.history['loss'], color= 'r', label = 'Train')
axes.plot(history.epoch, history.history['val_loss'], color = 'b', label = 'Val')
axes.set_xlabel('Epoch')
axes.set_ylabel('Loss')
axes.legend()
plt.savefig('loss.jpg')
plt.show()
# Acc
fig, axes = plt.subplots(figsize= (20,5))
# Train
axes.plot(history.epoch, history.history['acc'], color= 'r', label = 'Train')
axes.plot(history.epoch, history.history['val_acc'], color = 'b', label = 'Val')
axes.set_xlabel('Epoch')
axes.set_ylabel('Acc')
axes.legend()
plt.savefig('acc.jpg')
plt.show()
# Mean Iou
fig, axes = plt.subplots(figsize= (20,5))
# Train
axes.plot(history.epoch, history.history['mean_iou'], color= 'r', label = 'Train')
axes.plot(history.epoch, history.history['val_mean_iou'], color = 'b', label = 'Val')
axes.set_xlabel('Epoch')
axes.set_ylabel('MeanIoU')
axes.legend()
plt.savefig('mean_iou.jpg')
plt.show()
else:
fig, axes = plt.subplots(1,3, figsize= (20,5))
# loss
axes[0].plot(history.epoch, history.history['loss'])
axes[0].set_title('Train')
axes[0].set_xlabel('Epoch')
axes[0].set_ylabel('Loss')
# Acc
axes[1].plot(history.epoch, history.history['acc'])
axes[1].set_title('Train')
axes[1].set_xlabel('Epoch')
axes[1].set_ylabel('Acc')
# Mean Iou
axes[2].plot(history.epoch, history.history['mean_iou'])
axes[2].set_title('Train')
axes[2].set_xlabel('Epoch')
axes[2].set_ylabel('MeanIoU')
plt.savefig('.jpg')
plt.show()
def show_example(image, mask, model, label, inp_size, color_mode, metrics, train_data, function = None, kmean = None):
img = cv2.cvtColor(cv2.imread(image),cv2.COLOR_BGR2RGB)
img = tf.image.resize(img, inp_size, method ='nearest')
pred, _pred = predict_func.predict(model, image, label, color_mode, inp_size)
if mask != None:
msk= cv2.cvtColor(cv2.imread(mask), cv2.COLOR_BGR2RGB)
msk= tf.image.resize(msk, inp_size, method = 'nearest')
if function:
msk = tf.convert_to_tensor(function(msk.numpy()))
if kmean:
y_true = kmean.predict(msk.numpy().reshape(-1,3)).reshape(*inp_size, 1)
else:
y_true = train_data.processing(msk.numpy())
metrics.miou_class(y_true, _pred)
y_true = decode_label(y_true, label)
ground_truth = np.floor(img.numpy() * 0.7 + y_true * 0.3).astype('int')
fig, axes = plt.subplots(1,3, figsize = (12,3))
axes[0].imshow(img)
axes[0].set_title('Original Image')
axes[1].set_title('Ground truth')
axes[1].imshow(ground_truth)
axes[2].set_title('Prediction')
axes[2].imshow(pred)
else:
fig, axes = plt.subplots(1,2, figsize = (12,3))
axes[0].imshow(img)
axes[0].set_title('Original Image')
axes[1].set_title('Prediction')
axes[1].imshow(pred)
plt.savefig('predict.jpg')
plt.show()