/
test.py
70 lines (60 loc) · 2.22 KB
/
test.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
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
import random
from PIL import Image
NUM = 30
IMG_SIZE = 256
OUTPUT_SIZE = 256*256
CATEGORY = 1
def readImages(filename):
images = np.zeros((NUM*CATEGORY, IMG_SIZE*IMG_SIZE))
fileImg = open(filename)
for k in range(NUM*CATEGORY):
line = fileImg.readline()
if(not line):
break
val = line.split(',')
for i in range(IMG_SIZE*IMG_SIZE):
images[k, i] = float(val[i + 1])
return images
def readLabels(filename):
labels = np.zeros((NUM*CATEGORY, OUTPUT_SIZE*CATEGORY))
fileImg = open(filename)
for k in range(NUM*CATEGORY):
line = fileImg.readline()
if(not line):
break
val = line.split(',')
for i in range(OUTPUT_SIZE*CATEGORY):
labels[k, i] = float(val[i + 1])
return labels
if __name__=='__main__':
tst_image = readImages('./data/testImage256.txt')
tst_label = readLabels('./data/testLABEL256.txt')
label = tst_label.reshape([-1, IMG_SIZE, IMG_SIZE, CATEGORY])
for i in range(NUM*CATEGORY):
plt.figure(figsize=[15, 4])
plt.subplot(1, 4, 1)
fig = plt.imshow(tst_image[i, :].reshape([IMG_SIZE, IMG_SIZE]), vmin=0, vmax=255, cmap='gray', aspect='auto')
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)
plt.subplot(1, 4, 2)
fig = plt.imshow(label[i, :, :, 0], cmap='jet', aspect='auto')
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)
rslt = np.loadtxt('./result/' + str(i) + '_0.txt')
max_val = np.max(rslt)
min_val = np.min(rslt)
rslt = rslt - min_val
rslt = rslt / (max_val - min_val)
plt.subplot(1, 4, 3)
fig = plt.imshow(rslt, vmin=0.8, cmap='jet', aspect='auto')
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)
rslt = np.loadtxt('./result_keras/' + str(i) + '.txt')
plt.subplot(1, 4, 4)
fig = plt.imshow(rslt, cmap='jet', aspect='auto')
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)
plt.show()