forked from eugenelet/CRFP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (58 loc) · 2.97 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
#### take reference from
from option import args
from utils import mkExpDir
from dataset import dataloader
from model import CRFP
from loss.loss import get_loss_dict
from trainer import Trainer
import math
import os
import time
import torch
import torch.nn as nn
import warnings
from tqdm import tqdm
warnings.filterwarnings('ignore')
if __name__ == '__main__':
### make save_dir
_logger = mkExpDir(args)
### device and model
if args.num_gpu == 1:
device = torch.device('cpu') if args.cpu else torch.device('cuda:{}'.format(args.gpu_id))
else:
device = torch.device('cpu') if args.cpu else torch.device('cuda')
# _model = CRFP.BasicFVSR(mid_channels=32, y_only=args.y_only, hr_dcn=args.hr_dcn, offset_prop=args.offset_prop, spynet_pretrained='pretrained_models/fnet.pth', device=device).to(device)
# _model = CRFP.CRFP_simple_noDCN(mid_channels=32, y_only=args.y_only, hr_dcn=args.hr_dcn, offset_prop=args.offset_prop, spynet_pretrained='pretrained_models/fnet.pth', device=device).to(device)
# _model = CRFP.CRFP_simple(mid_channels=32, y_only=args.y_only, hr_dcn=args.hr_dcn, offset_prop=args.offset_prop, spynet_pretrained='pretrained_models/fnet.pth', device=device).to(device)
# _model = CRFP.CRFP(mid_channels=32, y_only=args.y_only, hr_dcn=args.hr_dcn, offset_prop=args.offset_prop, spynet_pretrained='pretrained_models/fnet.pth', device=device).to(device)
_model = CRFP.CRFP_DSV(mid_channels=32, y_only=args.y_only, hr_dcn=args.hr_dcn, offset_prop=args.offset_prop, spynet_pretrained='pretrained_models/fnet.pth', device=device).to(device)
# _model = CRFP.CRFP_DSV_CRA(mid_channels=32, y_only=args.y_only, hr_dcn=args.hr_dcn, offset_prop=args.offset_prop, spynet_pretrained='pretrained_models/fnet.pth', device=device).to(device)
if ((not args.cpu) and (args.num_gpu > 1)):
_model = nn.DataParallel(_model, list(range(args.num_gpu)))
### dataloader of training set and testing set
_dataloader = dataloader.get_dataloader(args)
### loss
_loss_all = get_loss_dict(args, _logger)
### trainer
t = Trainer(args, _logger, _dataloader, _model, _loss_all)
t.before_run()
### test / eval / train
if (args.test):
t.load(model_path=args.model_path)
t.test_basicvsr()
elif (args.eval):
model_list = sorted(os.listdir(args.model_path))
# model_list = model_list[::-1]
for idx, m in enumerate(model_list):
t.load(model_path=os.path.join(args.model_path, m))
t.eval_basicvsr(idx)
t.vis_plot_metric('eval')
else:
# t.load(model_path=args.model_path)
for epoch in range(1, args.num_epochs+1):
t.train_basicvsr(current_epoch=epoch)
t.vis_plot_metric('train')
# if (epoch % args.val_every == 0):
# t.eval_basicvsr(current_epoch=epoch)
# t.vis_plot_metric('eval')
torch.cuda.empty_cache()