-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_sign_imgs.py
43 lines (34 loc) · 1.55 KB
/
output_sign_imgs.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
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['font.family'] = 'Liberation Sans'
rcParams['font.size'] = 6
def output_grid_imgs(filename, nrows, ncols, images, labels,
sign_names, cmap=None):
fig, axes = plt.subplots(nrows, ncols, figsize=(12, 12))
for row in range(nrows):
for col in range(ncols):
index = np.random.randint(len(images))
image = images[index]
label = labels[index]
name = sign_names.query('ClassId=={}'.format(label))['SignName'].values[0]
axes[row, col].imshow(image, cmap=cmap)
axes[row, col].axis('off')
axes[row, col].set_title(name)
fig.savefig(fname=filename, dpi=300, transparent=True, bbox_inches='tight', pad_inches=0)
def output_compared_imgs(filename, nrows, befores, afters,
labels, sign_names, cmap=None):
fig, axes = plt.subplots(nrows, 2, figsize=(4, 2*nrows))
for row in range(nrows):
index = np.random.randint(len(befores))
before = befores[index]
after = afters[index]
label = labels[index]
name = sign_names.query('ClassId=={}'.format(label))['SignName'].values[0]
axes[row, 0].imshow(before, cmap=cmap)
axes[row, 0].axis('off')
axes[row, 0].set_title(name)
axes[row, 1].imshow(after, cmap=cmap)
axes[row, 1].axis('off')
axes[row, 1].set_title(name)
fig.savefig(fname=filename, dpi=300, transparent=True, bbox_inches='tight', pad_inches=0)