-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlvcit_main.py
203 lines (194 loc) · 6.02 KB
/
lvcit_main.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import traceback
import warnings
import time
import argparse
import os
from util import str2bool
from lvcit_runner import runner
from dataloaders import *
warnings.filterwarnings('ignore')
# data info
ROOT = os.path.join("data", "lvcit")
VERSION = "_v6_random_255_255_255_255_s1a0"
checkpoints_dir = "checkpoints"
checkpoints_save_dir = os.path.join("checkpoints", "save")
data_info = [
{
"data_name": "voc",
"data": os.path.join(ROOT, "3composite_img", f"VOC_20{VERSION}"),
"covering_array_type": [
f"adaptive random_20_{k}_{tau}" for k in [4] for tau in [2]
],
"num_classes": 20,
"phase": "predict",
"res_path": os.path.join(ROOT, "4results", f"VOC_20{VERSION}"),
"inp_name": "data/voc/voc_glove_word2vec.pkl",
"graph_file": "data/voc/voc_adj.pkl",
},
{
"data_name": "coco",
"data": os.path.join(ROOT, "3composite_img", f"COCO_80{VERSION}"),
"covering_array_type": [
f"adaptive random_80_{k}_{tau}" for k in [4] for tau in [2]
],
"num_classes": 80,
"phase": "predict",
"res_path": os.path.join(ROOT, "4results", f"COCO_80{VERSION}"),
"inp_name": "data/coco/coco_glove_word2vec.pkl",
"graph_file": "data/coco/coco_adj.pkl",
},
]
# model info
model_info = [
# 0 msrn
{
"model_name": "msrn",
"image_size": 448,
"batch_size": 64,
"threshold": 0.5,
"workers": 1,
"epochs": 20,
"epoch_step": [30],
"start_epoch": 0,
"lr": 0.1,
"momentum": 0.9,
"weight_decay": 1e-4,
"print_freq": 0,
"resume": os.path.join(checkpoints_dir, "msrn", "voc_checkpoint.pth.tar"),
"evaluate": True,
"pretrained": 1,
"pretrain_model": os.path.join(checkpoints_dir, "msrn", "resnet101_for_msrn.pth.tar"),
"pool_ratio": 0.2,
"backbone": "resnet101",
"save_model_path": os.path.join(checkpoints_save_dir, "msrn"),
},
# 1 ml gcn
{
"model_name": "mlgcn",
"image_size": 448,
"batch_size": 64,
"threshold": 0.5,
"workers": 2,
"epochs": 20,
"epoch_step": [30],
"start_epoch": 0,
"lr": 0.1,
"lrp": 0.1,
"momentum": 0.9,
"weight_decay": 1e-4,
"print_freq": 0,
"resume": os.path.join(checkpoints_dir, "mlgcn", "voc_checkpoint.pth.tar"),
"evaluate": True,
"save_model_path": os.path.join(checkpoints_save_dir, "mlgcn"),
},
# 2 asl
{
"model_name": "asl",
"model_type": "tresnet_xl",
"model_path": os.path.join(checkpoints_dir, "asl", "voc_checkpoint.pth"),
"workers": 1,
"image_size": 448,
"threshold": 0.8,
"batch_size": 64,
"print_freq": 64,
# TODO save path
},
]
TASKS = [
# voc msrn
{
"task_name": "voc_msrn",
"args": {**data_info[0], **model_info[0]},
"dataloader": LvcitVoc,
},
# voc mlgcn
{
"task_name": "voc_mlgcn",
"args": {**data_info[0], **model_info[1]},
"dataloader": LvcitVoc,
},
# voc asl
{
"task_name": "voc_asl",
"args": {**data_info[0], **model_info[2]},
"dataloader": LvcitVoc2,
},
# coco msrn
{
"task_name": "coco_msrn",
"args": {
**data_info[1], **model_info[0],
"pool_ratio": 0.05,
"resume": os.path.join(checkpoints_dir, "msrn", "coco_checkpoint.pth.tar"),
"batch_size": 10,
},
"dataloader": LvcitCoco,
},
# coco mlgcn
{
"task_name": "coco_mlgcn",
"args": {
**data_info[1], **model_info[1],
"resume": os.path.join(checkpoints_dir, "mlgcn", "coco_checkpoint.pth.tar"),
"batch_size": 80,
},
"dataloader": LvcitCoco,
},
# coco asl
{
"task_name": "coco_asl",
"args": {
**data_info[1], **model_info[2],
"model_type": "tresnet_l",
"model_path": os.path.join(checkpoints_dir, "asl", "coco_checkpoint.pth"),
"print_freq": 640,
"batch_size": 64,
},
"dataloader": LvcitCoco2,
},
]
if __name__ == "__main__":
with open("errors.txt", 'w') as f:
f.write("")
parser = argparse.ArgumentParser(description="test execution")
parser.add_argument(
"--demo", "-d",
type=str2bool,
default=False,
)
args = parser.parse_args()
if args.demo:
task = TASKS[0]
task["args"]["covering_array_type"] = ["adaptive random_6_3_2"]
print("task: {} started".format(task["task_name"]))
start = time.time()
args = argparse.Namespace(**task["args"])
args.dataloader = task["dataloader"]
args.data = os.path.join(args.data, args.model_name)
args.res_path = os.path.join(args.res_path, args.model_name)
try:
runner(args, 1)
except Exception:
with open("errors.txt", 'a') as f:
f.write(task["task_name"])
traceback.print_exc()
f.write(traceback.format_exc())
f.write("\n")
print("task: {} finished, time:{}".format(task["task_name"], time.time() - start))
else:
for task in TASKS:
print("task: {} started".format(task["task_name"]))
start = time.time()
args = argparse.Namespace(**task["args"])
args.dataloader = task["dataloader"]
args.data = os.path.join(args.data, args.model_name)
args.res_path = os.path.join(args.res_path, args.model_name)
try:
runner(args)
except Exception:
with open("errors.txt", 'a') as f:
f.write(task["task_name"])
traceback.print_exc()
f.write(traceback.format_exc())
f.write("\n")
print("task: {} finished, time:{}".format(task["task_name"], time.time() - start))