-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
198 lines (175 loc) · 6.99 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
'''
AI Fashion Coordinator
(Baseline For Fashion-How Challenge)
MIT License
Copyright (C) 2023, Integrated Intelligence Research Section, ETRI
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Update: 2023.02.15.
'''
import argparse
import torch
from gaia import *
import os
import random
cores = os.cpu_count()
torch.set_num_threads(cores)
def seed_torch(seed=42):
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
torch.backends.cudnn.enabled = False
def get_udevice():
"""
function: get usable devices(CPU and GPU)
"""
if torch.cuda.is_available():
device = torch.device('cuda')
num_gpu = torch.cuda.device_count()
else:
device = torch.device('cpu')
print('Using device: {}'.format(device))
if torch.cuda.is_available():
print('# of GPU: {}'.format(num_gpu))
return device
def str2bool(v):
"""
function: convert into bool type(True or False)
"""
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')
# input options
parser = argparse.ArgumentParser(description='AI Fashion Coordinator.')
parser.add_argument('--mode', type=str,
default='test',
help='training or eval or test mode')
parser.add_argument('--in_file_trn_dialog', type=str,
default='./data/task1.ddata.wst.txt',
help='training dialog DB')
parser.add_argument('--in_file_tst_dialog', type=str,
default='./data/cl_eval_task1.wst.dev',
help='test dialog DB')
parser.add_argument('--in_file_fashion', type=str,
default='./data/mdata.wst.txt.2023.08.23',
help='fashion item metadata')
parser.add_argument('--in_file_img_feats', type=str,
default='./data/extracted_feat.json',
help='fashion item image features')
parser.add_argument('--model_path', type=str,
default='./model',
help='path to save/read model')
parser.add_argument('--model_file', type=str,
default=None,
help='model file name')
parser.add_argument('--eval_node', type=str,
default='[6000,6000,200][2000]',
help='nodes of evaluation network')
parser.add_argument('--subWordEmb_path', type=str,
default='./sstm_v0p5_deploy/sstm_v4p49_np_n36134_d128.dat',
help='path of subword embedding')
parser.add_argument('--learning_rate', type=float,
default=0.0001,
help='learning rate')
parser.add_argument('--max_grad_norm', type=float,
default=40.0,
help='clip gradients to this norm')
parser.add_argument('--zero_prob', type=float,
default=0.0,
help='dropout prob.')
parser.add_argument('--corr_thres', type=float,
default=0.7,
help='correlation threshold')
parser.add_argument('--batch_size', type=int,
default=100,
help='batch size for training')
parser.add_argument('--epochs', type=int,
default=10,
help='epochs to training')
parser.add_argument('--save_freq', type=int,
default=2,
help='evaluate and save results per # epochs')
parser.add_argument('--hops', type=int,
default=3,
help='number of hops in the MemN2N')
parser.add_argument('--mem_size', type=int,
default=16,
help='memory size for the MemN2N')
parser.add_argument('--key_size', type=int,
default=300,
help='memory size for the MemN2N')
parser.add_argument('--permutation_iteration', type=int,
default=3,
help='# of permutation iteration')
parser.add_argument('--evaluation_iteration', type=int,
default=10,
help='# of test iteration')
parser.add_argument('--num_augmentation', type=int,
default=3,
help='# of data augmentation')
parser.add_argument('--use_batch_norm', type=str2bool,
default=True,
help='use batch normalization')
parser.add_argument('--use_dropout', type=str2bool,
default=False,
help='use dropout')
parser.add_argument('--use_multimodal', type=str2bool,
default=False,
help='use multimodal input')
parser.add_argument('--use_cl', type=str2bool,
default=True,
help='enable continual learning')
parser.add_argument('--ntask', type=int,
default='1',
help='memory network or transformer')
parser.add_argument('--inference', type=str2bool,
default=False,
help='memory network or transformer')
args, _ = parser.parse_known_args()
if __name__ == '__main__':
seed_torch()
print('\n')
print('-'*60)
print('\t\tAI Fashion Coordinator')
print('-'*60)
print('\n')
mode = args.mode
if mode not in ['train', 'test', 'pred'] :
raise ValueError('Unknown mode {}'.format(mode))
print('<Parsed arguments>')
for k, v in vars(args).items():
print('{}: {}'.format(k, v))
print('')
gaia = gAIa(args, get_udevice())
if mode == 'train':
# training
gaia.train()
elif mode == 'test':
# test
gaia.test()
elif mode == 'pred':
# pred
gaia.pred()