forked from sveitser/kaggle_diabetic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train_nn.py
41 lines (30 loc) · 1.03 KB
/
train_nn.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
"""Conv Nets training script."""
import click
import numpy as np
import data
import util
from nn import create_net
@click.command()
@click.option('--cnf', default='configs/c_512_4x4_32.py', show_default=True,
help='Path or name of configuration module.')
@click.option('--weights_from', default=None, show_default=True,
help='Path to initial weights file.')
def main(cnf, weights_from):
config = util.load_module(cnf).config
if weights_from is None:
weights_from = config.weights_file
else:
weights_from = str(weights_from)
files = data.get_image_files(config.get('train_dir'))
names = data.get_names(files)
labels = data.get_labels(names).astype(np.float32)
net = create_net(config)
try:
net.load_params_from(weights_from)
print("loaded weights from {}".format(weights_from))
except IOError:
print("couldn't load weights starting from scratch")
print("fitting ...")
net.fit(files, labels)
if __name__ == '__main__':
main()