-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_semi.py
218 lines (204 loc) · 5.18 KB
/
main_semi.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import argparse
from train_net_semi import train_semi,test
def parse_args():
parser = argparse.ArgumentParser(
description="Training and testing pipeline."
)
# setting
parser.add_argument(
'--training',
action='store_true',
help='Training enable.'
)
parser.add_argument(
'--local_rank',
type=int,
help='Local rank for ddp.'
)
parser.add_argument(
'--backend',
default='nccl',
type=str,
help='Backend for ddp.'
)
parser.add_argument(
'--seed',
default=3407,
type=int,
help='Random Seed.'
)
parser.add_argument(
'--num_gpus',
default=4,
type=int,
help='Number of GPUs to use (applies to both training and testing).'
)
# model
parser.add_argument(
'--detectron2_ckpt',
default='./pretrained_models/fpn/model_final_cafdb1.pkl',
type=str,
help='ckpt path of fpn from detectron2.'
)
parser.add_argument(
'--detectron2_cfg',
default='./configs/COCO-PanopticSegmentation/panoptic_fpn_R_101_3x_train.yaml',
type=str,
help='cfg path of fpn from detectron2.'
)
parser.add_argument(
'--max_sequence_length',
default=230,
type=int,
help='Max length of the input language sequence.'
)
parser.add_argument(
'--max_seg_num',
default=64,
type=int,
help='Max num of the noun phrase to be segmented.'
)
parser.add_argument(
'--max_phrase_num',
default=30,
type=int,
help='Max num of the noun phrase to be segmented.'
)
parser.add_argument(
'--pretrained_bert',
default='./pretrained_models/bert/bert-base-uncased',
type=str,
help='Pretrained bert model.'
)
parser.add_argument(
'--bert_tokenize',
default='./pretrained_models/bert/bert-base-uncased.txt',
type=str,
help='Tokenize word list.'
)
parser.add_argument(
'--bert_freeze',
default = False,
action='store_true',
help='If true freeze BERT model.'
)
parser.add_argument(
'--fpn_freeze',
default = True,
action='store_true',
help='If true freeze FPN model.'
)
parser.add_argument(
'--ckpt_path',
default='',
type=str,
help='Path to the checkpoint to load the initial weight.'
)
parser.add_argument(
'--num_stages',
default=3,
type=int,
help='Iter num.'
)
parser.add_argument(
'--num_points',
default=200,
type=int,
help='Saliency Points num.'
)
# data
parser.add_argument(
'--data_path',
default='./datasets/coco',
type=str,
help='The path to the data directory.'
)
parser.add_argument(
'--data_dir',
default='./datasets',
type=str,
help='The path to the data directory.'
)
parser.add_argument(
'--batch_size',
default=12,
type=int,
help='Total mini-batch size.'
)
parser.add_argument(
'--num_workers',
default=0,
type=int,
help='Number of data loader workers per training process.'
)
parser.add_argument(
'--pin_memory',
default=True,
type=bool,
help='Load data to pinned host memory.'
)
# training pipeline
parser.add_argument(
'--epoch',
default=14,
type=int,
help='Training epoch.'
)
parser.add_argument(
'--base_lr',
default=1e-4,
type=float,
help='Learning rate.'
)
parser.add_argument(
'--weight_decay',
default=0,
type=float,
help='Weight decay.'
)
parser.add_argument(
'--scheduler',
default='step',
choices=['step', 'reduce'],
type=str,
help='Weight decay.'
)
# output
parser.add_argument(
'--save_fig',
action='store_true',
help='Saving evaluation figures of metrics.'
)
parser.add_argument(
'--save_ckpt',
default=9,
type=int,
help='Epoch for starting saving checkpoints.'
)
parser.add_argument(
'--log_period',
default=100,
type=int,
help='Logging period.'
)
parser.add_argument(
'--output_dir',
default="./output",
type=str,
help='Saving dir.'
)
# semi-supervised learning settings
parser.add_argument(
'--semi_cfg',
type=str,
help='config for semi supervised learning'
)
return parser.parse_args()
def main():
args = parse_args()
if args.training: # args.training = True
train_semi(args)
else: # args.training = False
test(args)
if __name__ == "__main__":
main()