-
Notifications
You must be signed in to change notification settings - Fork 29
/
main.py
176 lines (130 loc) · 7.35 KB
/
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
import os
import os.path as osp
import argparse
import torch
from torch import nn
from tensorboardX import SummaryWriter
from core import Train, Test
from datasets.DatasetLoader import get_dataset_loader
from datasets.TargetDatasetLoader import get_tgtdataset_loader
from misc.utils import init_model, init_random_seed, mkdirs
from misc.saver import Saver
import models
import random
from pdb import set_trace as st
def main(args):
if args.training_type is 'Train':
savefilename = osp.join(args.dataset1+args.dataset2+args.dataset3+'1')
elif args.training_type is 'Test':
savefilename = osp.join(args.tstfile, args.tstdataset+'to'+args.dataset_target+args.snapshotnum)
args.seed = init_random_seed(args.manual_seed)
if args.training_type in ['Train','Test']:
summary_writer = SummaryWriter(osp.join(args.results_path, 'log', savefilename))
saver = Saver(args,savefilename)
saver.print_config()
##################### load seed#####################
#####################load datasets#####################
if args.training_type is 'Train':
data_loader1_real = get_dataset_loader(name=args.dataset1, getreal=True, batch_size=args.batchsize)
data_loader1_fake = get_dataset_loader(name=args.dataset1, getreal=False, batch_size=args.batchsize)
data_loader2_real = get_dataset_loader(name=args.dataset2, getreal=True, batch_size=args.batchsize)
data_loader2_fake = get_dataset_loader(name=args.dataset2, getreal=False, batch_size=args.batchsize)
data_loader3_real = get_dataset_loader(name=args.dataset3, getreal=True, batch_size=args.batchsize)
data_loader3_fake = get_dataset_loader(name=args.dataset3, getreal=False, batch_size=args.batchsize)
data_loader_target = get_tgtdataset_loader(name=args.dataset_target, batch_size=args.batchsize)
elif args.training_type is 'Test':
data_loader_target = get_tgtdataset_loader(name=args.dataset_target, batch_size=args.batchsize)
##################### load models#####################
FeatExtmodel = models.create(args.arch_FeatExt)
DepthEstmodel = models.create(args.arch_DepthEst)
FeatEmbdmodel = models.create(args.arch_FeatEmbd,momentum=args.bn_momentum)
if args.training_type is 'Train':
FeatExt_restore = None
DepthEst_restore = None
FeatEmbd_restore = None
elif args.training_type is 'Test':
FeatExt_restore = osp.join('results', args.tstfile, 'snapshots', args.tstdataset, 'FeatExtor-'+args.snapshotnum+'.pt')
FeatEmbd_restore = osp.join('results', args.tstfile, 'snapshots', args.tstdataset, 'FeatEmbder-'+args.snapshotnum+'.pt')
DepthEst_restore = None
else:
raise NotImplementedError('method type [%s] is not implemented' % args.training_type)
FeatExtor = init_model(net=FeatExtmodel, init_type = args.init_type, restore=FeatExt_restore, parallel_reload=True)
DepthEstor= init_model(net=DepthEstmodel, init_type = args.init_type, restore=DepthEst_restore, parallel_reload=True)
FeatEmbder= init_model(net=FeatEmbdmodel, init_type = args.init_type, restore=FeatEmbd_restore, parallel_reload=False)
print(">>> FeatExtor <<<")
print(FeatExtor)
print(">>> DepthEstor <<<")
print(DepthEstor)
print(">>> FeatEmbder <<<")
print(FeatEmbder)
##################### tarining models#####################
if args.training_type=='Train':
Train(args, FeatExtor, DepthEstor, FeatEmbder,
data_loader1_real, data_loader1_fake,
data_loader2_real, data_loader2_fake,
data_loader3_real, data_loader3_fake,
data_loader_target,
summary_writer, saver, savefilename)
elif args.training_type in ['Test']:
Test(args, FeatExtor, FeatEmbder, data_loader_target, savefilename)
else:
raise NotImplementedError('method type [%s] is not implemented' % args.training_type)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Meta_FA")
# datasets
# OMI
parser.add_argument('--dataset1', type=str, default='OULU')
parser.add_argument('--dataset2', type=str, default='MSU')
parser.add_argument('--dataset3', type=str, default='idiap')
parser.add_argument('--dataset_target', type=str, default='CASIA')
# OIC
# parser.add_argument('--dataset1', type=str, default='OULU')
# parser.add_argument('--dataset2', type=str, default='idiap')
# parser.add_argument('--dataset3', type=str, default='CASIA')
# parser.add_argument('--dataset_target', type=str, default='MSU')
#ICM
# parser.add_argument('--dataset1', type=str, default='idiap')
# parser.add_argument('--dataset2', type=str, default='CASIA')
# parser.add_argument('--dataset3', type=str, default='MSU')
# parser.add_argument('--dataset_target', type=str, default='OULU')
#OCM
# parser.add_argument('--dataset1', type=str, default='OULU')
# parser.add_argument('--dataset2', type=str, default='CASIA')
# parser.add_argument('--dataset3', type=str, default='MSU')
# parser.add_argument('--dataset_target', type=str, default='idiap')
# model
parser.add_argument('--arch_FeatExt', type=str, default='FeatExtractor')
parser.add_argument('--arch_DepthEst', type=str, default='DepthEstmator')
parser.add_argument('--arch_FeatEmbd', type=str, default='FeatEmbedder')
parser.add_argument('--init_type', type=str, default='xavier')
parser.add_argument('--metatrainsize', type=int, default=2)
# optimizer
parser.add_argument('--lr_meta', type=float, default=1e-3)
parser.add_argument('--lr_dep', type=float, default=1e-3)
parser.add_argument('--meta_step_size', type=float, default=1e-3)
parser.add_argument('--momentum', type=float, default=0.9)
parser.add_argument('--bn_momentum', type=float, default=1)
parser.add_argument('--weight_decay', type=float, default=5e-5)
parser.add_argument('--beta1', type=float, default=0.9)
parser.add_argument('--beta2', type=float, default=0.999)
parser.add_argument('--optimizer_meta', type=str, default='adam')
# # # # training configs
parser.add_argument('--training_type', type=str, default='Train')
parser.add_argument('--results_path', type=str, default='./results/Train_20191125')
parser.add_argument('--batchsize', type=int, default=10)
# parser.add_argument('--training_type', type=str, default='Test')
# parser.add_argument('--results_path', type=str, default='./results/Test_20191125/')
# parser.add_argument('--batchsize', type=int, default=1)
# parser.add_argument('--tstfile', type=str, default='Train_20191125')
# parser.add_argument('--tstdataset', type=str, default='idiapCASIAMSU1')
# parser.add_argument('--snapshotnum', type=str, default='final')
parser.add_argument('--epochs', type=int, default=10)
parser.add_argument('--log_step', type=int, default=2)
parser.add_argument('--tst_step', type=int, default=100)
parser.add_argument('--model_save_step', type=int, default=500)
parser.add_argument('--model_save_epoch', type=int, default=1)
parser.add_argument('--manual_seed', type=int, default=None)
parser.add_argument('--W_depth', type=int, default=10)
parser.add_argument('--W_metatest', type=int, default=1)
print(parser.parse_args())
main(parser.parse_args())