-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
142 lines (135 loc) · 5.24 KB
/
plot.py
File metadata and controls
142 lines (135 loc) · 5.24 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import json
import glob
import cv2
import os
def comp_psnr_plot(model_str, snr_train):
colors = list(mcolors.TABLEAU_COLORS)
markers = ['o', 's']
ls = ['--', '-']
i = 0
for model in model_str:
j = 0
for snr in snr_train:
path = './result_txt/plot1/{0}_SNR{1}.txt'.format(model, snr)
with open(path, 'r') as f:
text = f.read()
compression_ratios = text.split('\n')[0]
compression_ratios = json.loads(compression_ratios)
psnr = text.split('\n')[1]
psnr = json.loads(psnr)
label = '{0} (SNR={1}dB)'.format(model, snr)
plt.plot(compression_ratios, psnr, ls=ls[i], c=colors[j], marker=markers[i], label=label)
#plt.plot(compression_ratios, psnr, ls='-', c=colors[i], marker='o', label=label)
j += 1
i += 1
plt.title('AWGN Channel')
plt.xlabel('k/n')
plt.ylabel('PSNR (dB)')
plt.ylim(0, 35)
plt.grid(True)
plt.legend(loc='lower right')
os.makedirs('./plot/plot1_psnr', exist_ok=True)
plt.savefig('./plot/plot1_psnr/{0}_CompRatio{1}_SNR{2}.png'.format(model_str, compression_ratios, snr_train))
plt.show()
def all_model_psnr(model_str, snr_train):
colors = list(mcolors.TABLEAU_COLORS)
i = 0
for snr in snr_train:
j = 0
for model in model_str:
path = './result_txt/plot1/{0}_SNR{1}.txt'.format(model, snr)
with open(path, 'r') as f:
text = f.read()
compression_ratios = text.split('\n')[0]
compression_ratios = json.loads(compression_ratios)
psnr = text.split('\n')[1]
psnr = json.loads(psnr)
label = '{0} (SNR={1}dB)'.format(model, snr)
plt.plot(compression_ratios, psnr, ls='-', c=colors[j], marker='o', label=label)
j += 1
i += 1
plt.title('AWGN Channel')
plt.xlabel('k/n')
plt.ylabel('PSNR (dB)')
plt.ylim(0, 35)
plt.grid(True)
plt.legend(loc='lower right')
os.makedirs('./plot/plot1_psnr', exist_ok=True)
plt.savefig('./plot/plot1_psnr/{0}_CompRatio{1}_SNR{2}.png'.format(model_str, compression_ratios, snr_train))
plt.show()
def comp_ssim_plot(model_str, snr_train):
colors = list(mcolors.TABLEAU_COLORS)
markers = ['o', 's']
ls = ['--', '-']
i = 0
for model in model_str:
j = 0
for snr in snr_train:
path = './result_txt/plot1/{0}_SNR{1}.txt'.format(model, snr)
with open(path, 'r') as f:
text = f.read()
compression_ratios = text.split('\n')[0]
compression_ratios = json.loads(compression_ratios)
ssim = text.split('\n')[2]
ssim = json.loads(ssim)
label = '{0} (SNR={1}dB)'.format(model, snr)
plt.plot(compression_ratios, ssim, ls=ls[i], c=colors[j], marker=markers[i], label=label)
#plt.plot(compression_ratios, ssim, ls='-', c=colors[i], marker='X', label=label)
j += 1
i += 1
plt.title('AWGN Channel')
plt.xlabel('k/n')
plt.ylabel('SSIM')
plt.ylim(0.4,1)
plt.grid(True)
plt.legend(loc='lower right')
os.makedirs('./plot/plot1_ssim', exist_ok=True)
plt.savefig('./plot/plot1_ssim/{0}_CompRatio{1}_SNR{2}.png'.format(model_str, compression_ratios, snr_train))
plt.show()
def test_plot(model_str, compression_ratios, snr_train):
for comp_ratio in compression_ratios:
colors = list(mcolors.TABLEAU_COLORS)
markers = ['o', 's']
i = 0
ls = ['--', '-']
for model in model_str:
j = 0
for snr in snr_train:
path = './result_txt/plot2/{0}_CompRatio{1}_SNR{2}.txt'.format(model, comp_ratio, snr)
with open(path, 'r') as f:
text = f.read()
snr_test = text.split('\n')[0]
snr_test = json.loads(snr_test)
psnr = text.split('\n')[1]
psnr = json.loads(psnr)
label = '{0} (SNR={1}dB)'.format(model, snr)
plt.plot(snr_test, psnr, ls=ls[i], c=colors[j], marker=markers[i], label=label)
j += 1
i += 1
plt.title('AWGN Channel (k/n={0})'.format(comp_ratio))
plt.xlabel('SNR_test (dB)')
plt.ylabel('PSNR (dB)')
plt.ylim(0,35)
plt.grid(True)
plt.legend(loc='lower right')
plt.savefig('./plot/plot2/{0}_CompRatio{1}_SNR{2}.png'.format(model_str, comp_ratio, snr_train))
plt.show()
def all_img(model):
fig = plt.figure()
i=1
for filename in sorted(glob.glob('./img/{0}/*.jpg'.format(model))):
print(filename)
img = cv2.imread(filename)
ax = fig.add_subplot(3,3,i)
ax.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
ax = plt.gca()
ax.axes.xaxis.set_ticks([])
ax.axes.yaxis.set_ticks([])
label = filename.replace('./img/{0}/pred_'.format(model), '')
label = label.replace('.jpg', '')
ax.set_xlabel(label)
i += 1
plt.savefig('./img/{0}/all.jpg'.format(model))
plt.show()