-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_random_multiframe_fit_KF-ITW_different_Expression.py
executable file
·93 lines (57 loc) · 2.67 KB
/
run_random_multiframe_fit_KF-ITW_different_Expression.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
#!/usr/bin/env python3.5
import glob, os, sys
import eos_starter_lib as esl
from concurrent.futures import ThreadPoolExecutor
import random
EXE = "/user/HS204/m09113/eos/eos_build14/examples/fit-model-multi-alpha-exp"
LOGNAME = "fitting.log"
OUTPUTBASE = "/vol/vssp/facer2vm/people/Philipp/KF-ITW-prerelease_alpha_experiments/"
message = ""
OVERWRITE = True
id_folders = glob.glob("/user/HS204/m09113/facer2vm_project_area/data/KF-ITW-prerelease/*")
#id_folders = os.walk("/user/HS204/m09113/facer2vm_project_area/data/KF-ITW-prerelease/").next()[1]
#list of experiments to do: for example [20, 1] means 20 fittings with 1 randomly selected image each
experiments = [ [20, 10], [20, 20], [15, 30], [10, 50], [10, 70], [10, 90], [10, 110], [10, 130], [10, 150] ]
with ThreadPoolExecutor(max_workers=20) as executor:
for n in range(0,len(id_folders)):
id_folder = id_folders[n]
# make absolute
id_folder = os.path.abspath(id_folder)
# check if it's a folder
if (not os.path.isdir(id_folder)):
continue;
expressions = next(os.walk(id_folder))[1]
lms=[]
for exp in expressions:
expression = "/"+exp+"/"
id_and_expr_folder = id_folder + expression
# gather lm and img files
lms.extend(glob.glob(id_and_expr_folder+"/*.pts"))
#imgs = esl.find_imgs_to_lms (lms, "*.png")
for experiment in experiments: # each specific number of image
#check if we have enough images with lms for this experiment
if experiment[1]>len(lms):
continue
random.seed(experiment[1]*223)
for set_iter in range(experiment[0]): #each time same number of images but different images
lms_exp = random.sample(lms, experiment[1])
#print (lms_exp)
imgs_exp = esl.find_imgs_to_lms (lms_exp, "*.png")
# create outputfolder
outputfolder = OUTPUTBASE + os.path.basename(id_folder)
if (not os.path.exists(outputfolder)):
os.mkdir(outputfolder)
outputfolder += "/expression_mix/"
if (not os.path.exists(outputfolder)):
os.mkdir(outputfolder)
outputfolder += format(experiment[1], '03d') +"_images_"+format(set_iter, '02d')+"/"
if (not os.path.exists(outputfolder)):
os.mkdir(outputfolder)
message = "id "+os.path.basename(id_folder) + " with " + str(experiment[1])+" images, set "+str(set_iter)
if (os.path.exists(outputfolder+'merged.obj') and not OVERWRITE):
print ("already done", message)
continue
# prepare multi image fit command
cmd = esl.assemble_command(EXE, lms_exp, imgs_exp, outputfolder, regularisation=30.0, iterations=75)
# print id and start cmd
executor.submit(esl.start_and_log,"multiframe fitting on "+message, cmd, None, log=outputfolder+LOGNAME) #21600