-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.py
executable file
·48 lines (31 loc) · 1.44 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
from __future__ import print_function, absolute_import
import argparse
import torch
from scripts.utils.misc import save_checkpoint, adjust_learning_rate
import scripts.utils.pytorch_ssim as pytorch_ssim
import scripts.datasets as datasets
import scripts.machines as machines
from options import Options
def main(args):
DataLoader = datasets.COCO
if 'mmu' in args.arch:
DataLoader = datasets.COCOv2
if args.task == 'inpainting':
DataLoader = datasets.Inpainting
train_loader = torch.utils.data.DataLoader(DataLoader('train',args),batch_size=args.train_batch, shuffle=True,
num_workers=args.workers, pin_memory=False)
val_loader = torch.utils.data.DataLoader(DataLoader('val',args),batch_size=args.test_batch, shuffle=False,
num_workers=args.workers, pin_memory=False)
lr = args.lr
data_loaders = (train_loader,val_loader)
Machine = machines.__dict__[args.machine](datasets=data_loaders, args=args)
for epoch in range(Machine.args.start_epoch, Machine.args.epochs):
print('\nEpoch: %d | LR: %.8f' % (epoch + 1, lr))
lr = adjust_learning_rate(data_loaders, Machine.optimizer, epoch, lr, args)
Machine.record('lr',lr, epoch)
Machine.train(epoch)
Machine.validate(epoch)
save_checkpoint(Machine)
if __name__ == '__main__':
parser=Options().init(argparse.ArgumentParser(description='PyTorch Training'))
main(parser.parse_args())