-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
128 lines (116 loc) · 2.83 KB
/
train.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
import torch
from torch.utils.data import DataLoader
import argparse
from ei.ei import EI
from physics.ct import CT
from dataset.ctdb import CTData
from transforms.rotate import Rotate
parser = argparse.ArgumentParser(description="EI experiment parameters.")
parser.add_argument(
"--schedule",
default=[2000, 3000, 4000],
nargs="+",
type=int,
help="learning rate schedule (when to drop lr by 10x),"
"(default: [2000, 3000, 4000])",
)
parser.add_argument(
"--cos", default=False, action="store_true", help="use cosine lr schedule"
)
parser.add_argument(
"--epochs",
default=5000,
type=int,
metavar="N",
help="number of total epochs to run " "(default: 5000)",
)
parser.add_argument(
"--lr",
"--learning-rate",
default=5e-4,
type=float,
metavar="LR",
help="initial learning rate " "(default: 5e-4)",
dest="lr",
)
parser.add_argument(
"--wd",
"--weight-decay",
default=1e-8,
type=float,
metavar="W",
help="weight decay (default: 1e-8)",
dest="weight_decay",
)
parser.add_argument(
"-b",
"--batch-size",
default=2,
type=int,
metavar="N",
help="mini-batch size (default: 2)",
)
parser.add_argument(
"--ckp-interval",
default=500,
type=int,
help="save checkpoints interval epochs (default: 1000)",
)
parser.add_argument(
"--dataset",
default="./dataset/CT100_128x128.mat",
type=str,
metavar="PATH",
help="path to the dataset MATLAB file (default: ./dataset/CT100_128x128.mat)",
)
# EI specific configs:
parser.add_argument(
"--ei-trans",
default=5,
type=int,
help="number of transformations for EI (default: 5)",
)
parser.add_argument(
"--ei-alpha",
default=100,
type=float,
help="equivariance strength (default: 100)",
)
# Inverse problem task configs:
parser.add_argument(
"--views",
default=50,
type=int,
help="number of radon views (default: 50)",
)
def main():
args = parser.parse_args()
lr = {"G": args.lr, "WD": args.weight_decay}
dataset = CTData(mode="train", root_dir=args.dataset)
dataloader = DataLoader(dataset=dataset, batch_size=args.batch_size, shuffle=True)
# forward model A
physics = CT(img_width=128, radon_view=args.ct_views, circle=False)
# transformations group G (used in Equivariant Imaging)
transform = Rotate(n_trans=args.ei_trans)
# define Equivariant Imaging model
ei = EI(
in_channels=1,
out_channels=1,
img_width=128,
img_height=128,
dtype=torch.float,
)
ei.train_ei(
dataloader,
physics,
transform,
args.epochs,
lr,
args.ei_alpha,
args.ckp_interval,
schedule="cos" if args.cos else args.schedule,
loss_type="l2",
report_psnr=True,
)
if __name__ == "__main__":
main()