forked from javawizard/arts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
53 lines (45 loc) · 1.46 KB
/
runner.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
from glob import glob
from time import sleep
from os import path, rename
from re import sub
from sys import stdout
from subprocess import call
PYTORCH_STYLE_TRANSFER_CWD = path.join(
path.dirname(__file__),
'PyTorch-Style-Transfer',
'experiments'
)
def newstate(filepath, state):
return sub(r'\.[^\.]+$', '.' + state, filepath)
def process(filepath):
processing = newstate(filepath, "processing")
rename(filepath, processing)
style_path = path.abspath(path.join(processing, "style.jpg"))
subject_path = path.abspath(path.join(processing, "subject.jpg"))
output_path = path.abspath(path.join(processing, "output.jpg"))
stdout_path = path.join(processing, "stdout.txt")
with open(stdout_path, "a") as f:
f.write("Status: starting\n")
cmd = "python -u main.py optim " \
"--style-image {0} --content-image {1} --output-image {2} " \
"--iters 200 --log-interval 1 --style-weight 10" \
"".format(style_path, subject_path, output_path)
with open(stdout_path, 'a') as f:
call(cmd.split(), stdout=f, bufsize=1, cwd=PYTORCH_STYLE_TRANSFER_CWD)
f.write("Status: done\n")
count = 0
while(True):
print "Checking for requests... ", count
count += 1
stdout.flush()
files = list(reversed(sorted(glob("images/*.request"))))
for file in files:
print "request: ", path.basename(file)
stdout.flush()
if len(files) > 0:
print "* Processing: ", files[0]
stdout.flush()
process(files[0])
sleep(1)
print
stdout.flush()