-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainability_imagination_benchmark.py
74 lines (58 loc) · 2.44 KB
/
containability_imagination_benchmark.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
# Containability Imagination Benchmark experiment
# The result of the containability imagination for each object in the <data_root_dir> will
# be saved in the <result_dir> in a format of:
# "container sphere-in-percentaget 0 1 2 3"
# After the result is generated, run benchmark_map.py to see the result
# python containability_imagination_benchmark.py <root_dir> <data_root_dir> <result_dir>
# Author: Hongtao Wu
# Institution: Johns Hopkins University
# Date: Mar 10, 2020
from __future__ import print_function
import os
import time
import argparse
import numpy as np
from containability import Containability
parser = argparse.ArgumentParser(
description="Containability imagination benchmark")
parser.add_argument("root_dir",
type=str,
help="root directory of the container imagination")
parser.add_argument("data_root_dir",
type=str,
help="root directory of the data")
parser.add_argument("result_dir",
type=str,
help="directory of for saving the result")
args = parser.parse_args()
root_dir = args.root_dir
obj_dir = args.data_root_dir
result_dir = args.result_dir
content_urdf = os.path.join(root_dir, "object/m&m.urdf")
obj_list = os.listdir(obj_dir)
print("Object number: ", len(obj_list))
for obj_name in obj_list:
start_time = time.time()
obj_urdf = os.path.join(obj_dir, obj_name, obj_name + "_mesh_0.urdf")
obj_vhacd_mesh = os.path.join(obj_dir, obj_name,
obj_name + "_mesh_0_vhacd.obj")
C = Containability(obj_urdf,
obj_vhacd_mesh,
rotate=True,
translate=True,
friction=True,
restitution=True,
obj_zero_pos=[0, 0, 1],
obj_zero_orn=[0, 0, 0],
check_process=False,
mp4_dir=None,
object_name=obj_name,
content_urdf=content_urdf)
containability_affordance, sphere_in_percentage = C.get_containability()
C.disconnect_p()
imagination_time = time.time() - start_time
result_txt_name = os.path.join(result_dir, obj_name + ".txt")
with open(result_txt_name, "w") as file1:
writerow = 'container ' + str(sphere_in_percentage) + ' 0 1 2 3'
file1.write(writerow)
print("Finish containability imagination benchmark!")