Skip to content

Commit a60d01a

Browse files
author
Jamaludin Mohd Yusof
committed
Added documentation for keras_utils
1 parent a5cf50d commit a60d01a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

common/keras_utils.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import os
2222
def set_parallelism_threads():
23+
""" Set the number of parallel threads according to the number available on the hardware
24+
"""
25+
2326
if K.backend() == 'tensorflow' and 'NUM_INTRA_THREADS' in os.environ and 'NUM_INTER_THREADS' in os.environ:
2427
import tensorflow as tf
2528
# print('Using Thread Parallelism: {} NUM_INTRA_THREADS, {} NUM_INTER_THREADS'.format(os.environ['NUM_INTRA_THREADS'], os.environ['NUM_INTER_THREADS']))
@@ -31,6 +34,9 @@ def set_parallelism_threads():
3134

3235

3336
def set_seed(seed):
37+
""" Set the random number seed to the desired value
38+
"""
39+
3440
set_seed_defaultUtils(seed)
3541

3642
if K.backend() == 'tensorflow':
@@ -50,6 +56,21 @@ def get_function(name):
5056

5157

5258
def build_optimizer(type, lr, kerasDefaults):
59+
""" Set the optimizer to the appropriate Keras optimizer function
60+
based on the input string and learning rate. Other required values
61+
are set to the Keras default values
62+
63+
Parameters
64+
----------
65+
type : string
66+
String to choose the optimizer
67+
Options recognized: 'sgd', 'rmsprop', 'adagrad', adadelta', 'adam'
68+
See the Keras documentation for a full description of the options
69+
70+
Return
71+
----------
72+
Returns the appropriate Keras optimizer function
73+
"""
5374

5475
if type == 'sgd':
5576
return optimizers.SGD(lr=lr, decay=kerasDefaults['decay_lr'],
@@ -103,6 +124,22 @@ def build_optimizer(type, lr, kerasDefaults):
103124

104125

105126
def build_initializer(type, kerasDefaults, seed=None, constant=0.):
127+
""" Set the initializer to the appropriate Keras initializer function
128+
based on the input string and learning rate. Other required values
129+
are set to the Keras default values
130+
131+
Parameters
132+
----------
133+
type : string
134+
String to choose the initializer
135+
Options recognized: 'constant', 'uniform', 'normal',
136+
'glorot_uniform', 'lecun_uniform', 'he_normal'
137+
See the Keras documentation for a full description of the options
138+
139+
Return
140+
----------
141+
Returns the appropriate Keras initializer function
142+
"""
106143

107144
if type == 'constant':
108145
return initializers.Constant(value=constant)

0 commit comments

Comments
 (0)