-
Notifications
You must be signed in to change notification settings - Fork 10
/
dist_reconstruct.py
84 lines (71 loc) · 2.92 KB
/
dist_reconstruct.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
import os
import argparse
import concurrent.futures
import subprocess
import json
def reconstruct_mano_mesh(model_dir, task, start_point, end_point, use_eval_mode, optim):
if use_eval_mode:
if optim:
cmd = f'python reconstruct.py -e {model_dir} --task {task} --start_point {start_point} --end_point {end_point} --eval_mode --label'
else:
cmd = f'python reconstruct.py -e {model_dir} --task {task} --start_point {start_point} --end_point {end_point} --eval_mode'
else:
if optim:
cmd = f'python reconstruct.py -e {model_dir} --task {task} --start_point {start_point} --end_point {end_point} --label'
else:
cmd = f'python reconstruct.py -e {model_dir} --task {task} --start_point {start_point} --end_point {end_point}'
subprocess_env = os.environ.copy()
subprocess_env['CUDA_VISIBLE_DEVICES'] = gpus_list[idx]
subproc = subprocess.Popen(cmd, shell=True, env=subprocess_env, stdout=subprocess.PIPE)
subproc.communicate()
if __name__ == "__main__":
arg_parser = argparse.ArgumentParser(description="Generate meshes in parallel")
arg_parser.add_argument(
"--experiment",
"-e",
dest="experiment_directory",
required=True,
help="The experiment directory. This directory should include experiment specifications in "
+ '"specs.json", and logging will be done in this directory as well.',
)
arg_parser.add_argument(
"--task",
"-t",
dest="task",
default="obman",
choices=["obman", "dexycb"],
help="task to perform"
)
arg_parser.add_argument(
"--optim",
dest="optim",
action='store_true',
help="whether to fit sdf to mano"
)
args = arg_parser.parse_args()
gpus_list = os.environ["CUDA_VISIBLE_DEVICES"].split(',')
num_gpus = len(gpus_list)
if args.task == 'obman':
image_source = 'input/obman.json'
use_eval_mode = True
elif args.task == 'dexycb':
image_source = 'input/dexycb.json'
use_eval_mode = True
all_filenames = json.load(open(image_source))['filenames']
division = len(all_filenames) // num_gpus
start_points = []
end_points = []
for i in range(num_gpus):
start_point = i * division
if i != num_gpus - 1:
end_point = start_point + division
else:
end_point = len(all_filenames)
start_points.append(start_point)
end_points.append(end_point)
model_dir = args.experiment_directory
with concurrent.futures.ThreadPoolExecutor(max_workers=num_gpus) as executor:
for idx, (start, end) in enumerate(zip(start_points, end_points)):
print(f'Subprocess for {model_dir} using GPU {gpus_list[idx]} from {start} to {end - 1}')
executor.submit(reconstruct_mano_mesh, model_dir, args.task, start, end, use_eval_mode, args.optim)
executor.shutdown()