-
Notifications
You must be signed in to change notification settings - Fork 7
/
generate_examples.py
158 lines (139 loc) · 4.21 KB
/
generate_examples.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import argparse
import os
import copy
import pickle
import logging
import numpy as np
from PIL import Image
from data_generation.tasks import TASKS
from data_generation.generalization_tasks import TASKS as TASKS_GEN
from data_generation.utils import save_image
TASKS_IDX={
### elementary
0: "task_shape",
1: "task_pos",
2: "task_size",
3: "task_color",
4: "task_rot",
5: "task_flip",
6: "task_count",
7: "task_inside",
8: "task_contact",
### compositions
9: "task_sym_rot",
10: "task_sym_mir",
11: "task_pos_pos_1",
12: "task_pos_pos_2",
13: "task_pos_count_2",
14: "task_pos_count_1",
15: "task_pos_pos_4",
16: "task_pos_count_3",
17: "task_inside_count_1",
18: "task_count_count",
19: "task_shape_shape",
20: "task_shape_contact_2",
21: "task_contact_contact_1",
22: "task_inside_inside_1",
23: "task_inside_inside_2",
24: "task_pos_inside_3",
25: "task_pos_inside_1",
26: "task_pos_inside_2",
27: "task_pos_inside_4",
28: "task_rot_rot_1",
29: "task_flip_flip_1",
30: "task_rot_rot_3",
31: "task_pos_pos_3",
32: "task_pos_count_4",
33: "task_size_size_1",
34: "task_size_size_2",
35: "task_size_size_3",
36: "task_size_size_4",
37: "task_size_size_5",
38: "task_size_sym_1",
39: "task_size_sym_2",
40: "task_color_color_1",
41: "task_color_color_2",
42: "task_sym_sym_1",
43: "task_sym_sym_2",
44: "task_shape_contact_3",
45: "task_shape_contact_4",
46: "task_contact_contact_2",
47: "task_pos_size_1",
48: "task_pos_size_2",
49: "task_pos_shape_1",
50: "task_pos_shape_2",
51: "task_pos_rot_1",
52: "task_pos_rot_2",
53: "task_pos_col_1",
54: "task_pos_col_2",
55: "task_pos_contact",
56: "task_size_shape_1",
57: "task_size_shape_2",
58: "task_size_rot",
59: "task_size_inside_1",
60: "task_size_contact",
61: "task_size_count_1",
62: "task_size_count_2",
63: "task_shape_color",
64: "task_shape_color_2",
65: "task_shape_color_3",
66: "task_shape_inside",
67: "task_shape_inside_1",
68: "task_shape_count_1",
69: "task_shape_count_2",
70: "task_rot_color",
71: "task_rot_inside_1",
72: "task_rot_inside_2",
73: "task_rot_count_1",
74: "task_color_inside_1",
75: "task_color_inside_2",
76: "task_color_contact",
77: "task_color_count_1",
78: "task_color_count_2",
79: "task_inside_contact",
80: "task_contact_count_1",
81: "task_contact_count_2",
82: "task_size_color_1",
83: "task_size_color_2",
84: "task_color_sym_1",
85: "task_color_sym_2",
86: "task_shape_rot_1",
87: "task_shape_contact_5",
88: "task_rot_contact_1",
89: "task_rot_contact_2",
90: "task_inside_sym_mir",
91: "task_flip_count_1",
92: "task_flip_inside_1",
93: "task_flip_inside_2",
94: "task_flip_color_1",
95: "task_shape_flip_1",
96: "task_rot_flip_1",
97: "task_size_flip_1",
98: "task_pos_rot_3",
99: "task_pos_flip_1",
100: "task_pos_flip_2",
101: "task_flip_contact_1",
102: "task_flip_contact_2",
}
if __name__ == '__main__':
parser = argparse.ArgumentParser()
# parser.add_argument('--seed', type=int, default=0, help='seed for dataset generation')
parser.add_argument('--data_dir', type=str, default='examples/', help='directory to output dataset')
parser.add_argument('--task_idx', type=int, default=0, help='index of the dataset')
parser.add_argument('--split', default='', help='choose "gen" to generate generalization set examples')
parser.add_argument('--n_samples', type=int, default=0, help='number of examples to generate')
args = parser.parse_args()
pid = os.getpid()
logging.info('JOB PID {}'.format(pid))
# seed = args.seed
# np.random.seed(seed)
base_path = args.data_dir
task_idx = args.task_idx
os.makedirs(base_path, exist_ok=True)
n_samples = args.n_samples
if args.split == 'gen':
tn, tfn, desc = TASKS_GEN[task_idx]
else:
tn, tfn, desc = TASKS[task_idx]
images = np.concatenate([tfn() for i in range(n_samples)], 0)
save_image(images, base_path, tn)