-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.py
95 lines (86 loc) · 3.44 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
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
import datetime
import os
import posixpath as path
import subprocess
import sys
inputs = [
"Hanspeter-Pfister_large.jpg",
"lena.jpg",
"lisa.jpg",
"Mondrian.jpg",
"monet-parliament.jpg",
"moonman.jpg",
"picasso_three_musicians_moma.jpg",
"slisa.jpg",
]
if __name__ == "__main__":
# Build executable
msvc_tools_dir = os.getenv("VS120COMNTOOLS")
if msvc_tools_dir is None:
raise RuntimeError("Visual Studio 12.0 not detected!")
devenv_path = msvc_tools_dir + "..\\IDE\\devenv.com"
rebuildCmd = [devenv_path, "src/mona.sln", "/project", "minimona", "/projectconfig", "Release", "/rebuild"]
returnCode = subprocess.call(rebuildCmd)
if returnCode != 0:
raise RuntimeError("build failed!")
try: git_branch_hash = subprocess.check_output(["git","log","-n","1","--format=%H"]).decode().strip()
except: git_branch_hash = ""
out_dir = "test-" + datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "-" + git_branch_hash[0:8]
os.mkdir(out_dir)
gnuplot_fitness_file = path.join(out_dir, "fitness.p")
fitness_p = open(gnuplot_fitness_file, "w")
fitness_p.write("""\
unset log # remove any log-scaling
unset label # remove any previous labels
set xtic auto # set xtics automatically
set ytic auto # set ytics automatically
set key outside right top
set xlabel "Generation"
set ylabel "PSNR (dB)"
set xr [1:10000]
set yr [0:40]
set logscale x
set terminal jpeg size 800,600 font "Arial,12"
set output "graph-fitness.jpg"
plot """)
gnuplot_time_file = path.join(out_dir, "time.p")
time_p = open(gnuplot_time_file, "w")
time_p.write("""\
unset log # remove any log-scaling
unset label # remove any previous labels
set xtic auto # set xtics automatically
set ytic auto # set ytics automatically
set key outside right top
set xlabel "Generation"
set ylabel "Time (seconds)"
set xr [1:10000]
set yr [0:*]
set logscale x
set terminal jpeg size 800,600 font "Arial,12"
set output "graph-time.jpg"
plot """)
for img in inputs:
root,suffix = os.path.splitext(img)
out_file = path.join(out_dir, root+"-out.png")
stats_file = path.join(out_dir, root+"-out.dat")
temp_dir = path.join(out_dir, root)
os.mkdir(temp_dir)
subprocess.call(["minimona",
"-out", out_file,
"-stats", stats_file,
"-temp", temp_dir,
"-scale", "2",
"-gens", "2000",
"-tris", "800",
"-psoiter", "1000",
"-checklimit", "150",
"-particles", "16",
img
])
fitness_p.write("'%s' using 1:3 title '%s' with lines,\\\n" % (os.path.split(stats_file)[1], root))
time_p.write("'%s' using 1:2 title '%s' with lines,\\\n" % (os.path.split(stats_file)[1], root))
fitness_p.close()
time_p.close()
os.chdir(out_dir)
subprocess.call([ "gnuplot", "-e", "load '%s'" % os.path.split(gnuplot_fitness_file)[1] ])
subprocess.call([ "gnuplot", "-e", "load '%s'" % os.path.split(gnuplot_time_file)[1] ])