-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.py
43 lines (34 loc) · 1.05 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
# -*- coding: utf-8 -*-
"""
@Author : zhwzhong
@License : (C) Copyright 2013-2018, hit
@Contact : [email protected]
@Software: PyCharm
@File : main.py
@Time : 2021/6/26 09:34
@Desc :
"""
import warnings
warnings.filterwarnings("ignore")
import loss
import torch
import utility
from option import args
from trainer import Trainer
from importlib import import_module
from torch.utils.tensorboard import SummaryWriter
utility.init_state()
utility.set_checkpoint_dir(args)
writer = SummaryWriter('./logs/{}'.format(args.file_name))
loss = loss.Loss(args=args)
device = torch.device('cpu' if args.cpu else 'cuda')
module = import_module('models.' + args.model_name.lower())
model = module.make_model(args).to(device)
if not args.cpu:
model = torch.nn.parallel.DataParallel(model, device_ids=list(range(args.num_gpus)))
print('===> Parameter Number:', utility.get_parameter_number(model))
train_process = Trainer(args=args, my_model=model, my_loss=loss, writer=writer)
if args.test_only:
train_process.test()
else:
train_process.train()