20
20
21
21
import os
22
22
def set_parallelism_threads ():
23
+ """ Set the number of parallel threads according to the number available on the hardware
24
+ """
25
+
23
26
if K .backend () == 'tensorflow' and 'NUM_INTRA_THREADS' in os .environ and 'NUM_INTER_THREADS' in os .environ :
24
27
import tensorflow as tf
25
28
# 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():
31
34
32
35
33
36
def set_seed (seed ):
37
+ """ Set the random number seed to the desired value
38
+ """
39
+
34
40
set_seed_defaultUtils (seed )
35
41
36
42
if K .backend () == 'tensorflow' :
@@ -50,6 +56,21 @@ def get_function(name):
50
56
51
57
52
58
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
+ """
53
74
54
75
if type == 'sgd' :
55
76
return optimizers .SGD (lr = lr , decay = kerasDefaults ['decay_lr' ],
@@ -103,6 +124,22 @@ def build_optimizer(type, lr, kerasDefaults):
103
124
104
125
105
126
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
+ """
106
143
107
144
if type == 'constant' :
108
145
return initializers .Constant (value = constant )
0 commit comments