-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot-ssim.py
59 lines (48 loc) · 2.25 KB
/
plot-ssim.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
import os
import sys
import re
import directory_traversal_helper
import plotting_helper
def get_inverse_complement( vals ):
ret = []
for val in vals:
assert(1.- val >= 0)
if (1.- val) == 0:
ret.append(100000000)
else:
ret.append(1. / (1. - val ) )
return ret
def main():
if len( sys.argv ) is not 2:
raise ValueError("Usage: python plot-ssim-stats.py frame_stats_directory")
frame_stats_directory = sys.argv[1]
_, dataset_title = os.path.split(os.path.abspath(frame_stats_directory))
per_trial_min_ssim_scores = []
all_ssim_scores = []
for f, _ in directory_traversal_helper.get_files_matching_regex(frame_stats_directory, "frame-stats.dat"):
print("parsing " + f)
with open(f) as frame_stats_file:
trial_ssim_scores = []
for line in frame_stats_file:
if re.search("first chunk request logged on server at ", line):
continue #ignore first line
string_match = re.search("ssim score ([0-9\.]+)", line)
if string_match is None:
print("Failed to parse ssim from line: " + line)
ssim_of_frame = float(string_match.group(1))
trial_ssim_scores.append(ssim_of_frame)
per_trial_min_ssim_scores.append(min(trial_ssim_scores))
all_ssim_scores += trial_ssim_scores
if not all_ssim_scores:
raise Exception("Couldn't parse any ssim values from " + frame_stats_directory)
filename = dataset_title + "-ssim-cdf.dat"
(xvals, yvals) = plotting_helper.downsample_cumulative_y(plotting_helper.get_cdf(all_ssim_scores))
plotting_helper.write_points_to_file(xvals, yvals, dataset_title, filename)
(xvals, yvals) = plotting_helper.downsample_cumulative_y(plotting_helper.get_cdf(get_inverse_complement(all_ssim_scores)))
filename = dataset_title + "-inverse-complement-ssim-cdf.dat"
plotting_helper.write_points_to_file(xvals, yvals, dataset_title, filename)
(xvals, yvals) = plotting_helper.get_cdf( per_trial_min_ssim_scores )
filename = dataset_title + "-min-ssim-cdf.dat"
plotting_helper.write_points_to_file(xvals, yvals, dataset_title, filename)
if __name__ == '__main__':
main()