-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.py
67 lines (58 loc) · 1.5 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'''Main script.'''
import os
from model_trainer import train_model
def transfer_learning(
train_dir,
valid_dir,
no_class=200,
epoch=10,
batch_size=128,
tensorboard_dir=None,
checkpoint_dir=None
):
'''For transfer learning.
Build the model and fix all VGG16 layers to untrainable.
Transfer the FC layer to the target classes.
'''
return train_model(
name_optimizer='adam',
learning_rate=0.001,
decay_learning_rate=1e-9,
train_dir=train_dir,
valid_dir=valid_dir,
no_class=no_class,
epoch=epoch,
batch_size=batch_size,
tensorboard_dir=tensorboard_dir,
checkpoint_dir=checkpoint_dir
)
def fine_tuning(
train_dir,
valid_dir,
model_weights_path,
all_trainable=True,
no_class=200,
epoch=20,
batch_size=128,
tensorboard_dir=None,
checkpoint_dir=None
):
'''For fine tuning.
Load a model and make all layers trainbale.
Fine tune the whole model.
'''
return train_model(
learning_rate=0.0001,
decay_learning_rate=1e-8,
train_dir=train_dir,
valid_dir=valid_dir,
all_trainable=all_trainable,
model_weights_path=model_weights_path,
no_class=no_class,
epoch=epoch,
batch_size=batch_size,
tensorboard_dir=tensorboard_dir,
checkpoint_dir=checkpoint_dir
)
if __name__ == "__main__":
pass