-
Notifications
You must be signed in to change notification settings - Fork 56
/
main.py
63 lines (52 loc) · 2.26 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
import os
import torch
import argparse
from torch.backends import cudnn
from models.MIMOUNet import build_net
from train import _train
from eval import _eval
def main(args):
# CUDNN
cudnn.benchmark = True
if not os.path.exists('results/'):
os.makedirs(args.model_save_dir)
if not os.path.exists('results/' + args.model_name + '/'):
os.makedirs('results/' + args.model_name + '/')
if not os.path.exists(args.model_save_dir):
os.makedirs(args.model_save_dir)
if not os.path.exists(args.result_dir):
os.makedirs(args.result_dir)
model = build_net(args.model_name)
# print(model)
if torch.cuda.is_available():
model.cuda()
if args.mode == 'train':
_train(model, args)
elif args.mode == 'test':
_eval(model, args)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
# Directories
parser.add_argument('--model_name', default='MIMO-UNet', choices=['MIMO-UNet', 'MIMO-UNetPlus'], type=str)
parser.add_argument('--data_dir', type=str, default='dataset/GOPRO')
parser.add_argument('--mode', default='test', choices=['train', 'test'], type=str)
# Train
parser.add_argument('--batch_size', type=int, default=4)
parser.add_argument('--learning_rate', type=float, default=1e-4)
parser.add_argument('--weight_decay', type=float, default=0)
parser.add_argument('--num_epoch', type=int, default=3000)
parser.add_argument('--print_freq', type=int, default=100)
parser.add_argument('--num_worker', type=int, default=8)
parser.add_argument('--save_freq', type=int, default=100)
parser.add_argument('--valid_freq', type=int, default=100)
parser.add_argument('--resume', type=str, default='')
parser.add_argument('--gamma', type=float, default=0.5)
parser.add_argument('--lr_steps', type=list, default=[(x+1) * 500 for x in range(3000//500)])
# Test
parser.add_argument('--test_model', type=str, default='weights/MIMO-UNet.pkl')
parser.add_argument('--save_image', type=bool, default=False, choices=[True, False])
args = parser.parse_args()
args.model_save_dir = os.path.join('results/', args.model_name, 'weights/')
args.result_dir = os.path.join('results/', args.model_name, 'result_image/')
print(args)
main(args)