-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrain.py
188 lines (163 loc) · 7.21 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import sys
import argparse
import os
from os import listdir
from os.path import isfile, isdir, join
import numpy as np
import pandas as pd
import multiprocessing
import sys
sys.path.insert(0, "./")
import pyErrorPred
def main():
parser = argparse.ArgumentParser(description="Error predictor network trainer",
epilog="v0.0.1")
parser.add_argument("folder",
action="store",
help="Location of folder to save checkpoints to.")
parser.add_argument("--epoch",
"-e", action="store",
type=int,
default=200,
help="# of epochs (path over all proteins) to train for (Default: 200)")
parser.add_argument("--no_cutoff",
"-ncut",
action="store_true",
default=False,
help="Not having the -6 cutoff for auxiliary distance matrix (Default: False)")
parser.add_argument("--esto_loss_only",
"-elo",
action="store_true",
default=False,
help="Estogram loss only (Default: False)")
parser.add_argument("--no_last_dilation",
"-nld",
action="store_true",
default=False,
help="not using dilation for very last part of resnet (Default: False)")
parser.add_argument("--scaled_loss",
"-scl",
action="store_true",
default=False,
help="using loss scaled with protein size. (Default: False)")
parser.add_argument("--label_smoothing",
"-lsm",
action="store_true",
default=False,
help="apply label smoothing at training time. (Default: False)")
parser.add_argument("--partial",
"-partial",
action="store_true",
default=False,
help="partial instance normalization (Default: False)")
parser.add_argument("--transpose_matrix",
"-transmtx",
action="store_true",
default=False,
help="Transpose last few blocks (Default: False)")
parser.add_argument("--self_attention",
"-selfattn",
action="store_true",
default=False,
help="Put self attention on last few blocks(Default: False)")
parser.add_argument("--decay",
"-d", action="store",
type=float,
default=0.99,
help="Decay rate for learning rate (Default: 0.99)")
parser.add_argument("--base",
"-b", action="store",
type=float,
default=0.0005,
help="Base learning rate (Default: 0.0005)")
parser.add_argument("--silent",
"-s",
action="store_true",
default=False,
help="Run in silent mode (Default: False)")
args = parser.parse_args()
restoreModel = False
if isdir(args.folder):
restoreModel = True
#########################
### Generating a mask ###
#########################
ignore_list = []
if not args.silent:
print("Loading samples")
##########################
### Loading data files ###
##########################
script_dir = os.path.dirname(__file__)
base = join(script_dir, "data/")
if args.no_cutoff:
X = pyErrorPred.dataloader(np.load(join(base,"train_proteins4.npy")),
lengthmax=280,
distribution=False,
distance_cutoff=0)
V = pyErrorPred.dataloader(np.load(join(base,"valid_proteins4.npy")),
lengthmax=280,
distribution=False,
distance_cutoff=0)
else:
X = pyErrorPred.dataloader(np.load(join(base,"train_proteins4.npy")),
lengthmax=280,
distribution=False)
V = pyErrorPred.dataloader(np.load(join(base,"valid_proteins4.npy")),
lengthmax=280,
distribution=False)
if not args.silent:
print("Building a network")
#########################
### Training a model ###
#########################
if not args.esto_loss_only:
model = pyErrorPred.Model(obt_size=70,
tbt_size=58,
prot_size=None,
num_chunks=5,
optimizer="adam",
mask_weight=0.33,
lddt_weight=10.0,
feature_mask = None,
ignore3dconv = False,
name=args.folder,
scaled_loss=args.scaled_loss,
label_smoothing=args.label_smoothing,
no_last_dilation = args.no_last_dilation,
partial_instance_norm = args.partial,
transpose_matrix = args.transpose_matrix,
self_attention = args.self_attention,
nretype = 20)
else:
model = pyErrorPred.Model(obt_size=70,
tbt_size=58,
prot_size=None,
num_chunks=5,
optimizer="adam",
mask_weight=0.01,
lddt_weight=0.01,
feature_mask = None,
ignore3dconv = False,
name=args.folder,
scaled_loss=args.scaled_loss,
label_smoothing=args.label_smoothing,
no_last_dilation = args.no_last_dilation,
partial_instance_norm = args.partial,
transpose_matrix = args.transpose_matrix,
self_attention = args.self_attention,
nretype = 20)
if restoreModel:
model.load()
if not args.silent:
print("Training the network")
model.train(X,
V,
args.epoch,
decay=args.decay,
base_learning_rate=args.base,
save_best=True,
save_freq=10)
return 0
if __name__== "__main__":
main()