Skip to content

Commit 105df11

Browse files
authored
Black formatted
1 parent ffbcf81 commit 105df11

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

Notebooks/utils/DL_utils.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,35 @@
1111

1212

1313
class myCallback(tf.keras.callbacks.Callback):
14-
"""
14+
"""
1515
User can pass on the desired accuracy threshold while creating an instance of the class
1616
"""
1717

18-
def __init__(self, acc_threshold=0.9, print_msg=True):
18+
def __init__(self, acc_threshold=0.9, print_msg=True):
1919
self.acc_threshold = acc_threshold
2020
self.print_msg = print_msg
2121

22-
def on_epoch_end(self, epoch, logs={}):
22+
def on_epoch_end(self, epoch, logs={}):
2323
if logs.get("acc") > self.acc_threshold:
2424
if self.print_msg:
25-
print("\nReached {}% accuracy so cancelling the training!".format(self.acc_threshold))
25+
print(
26+
"\nReached {}% accuracy so cancelling the training!".format(
27+
self.acc_threshold
28+
)
29+
)
2630
self.model.stop_training = True
2731
else:
2832
if self.print_msg:
2933
print("\nAccuracy not high enough. Starting another epoch...\n")
3034

31-
32-
def build_classification_model(
33-
num_layers=1,
34-
architecture=[32],
35-
act_func="relu",
36-
input_shape=(28, 28),
37-
output_class=10,
38-
):
39-
"""
35+
def build_classification_model(
36+
num_layers=1,
37+
architecture=[32],
38+
act_func="relu",
39+
input_shape=(28, 28),
40+
output_class=10,
41+
):
42+
"""
4043
Builds a densely connected neural network model from user input
4144
4245
Arguments
@@ -48,20 +51,20 @@ def build_classification_model(
4851
Returns
4952
A neural net (Keras) model for classification
5053
"""
51-
layers = [tf.keras.layers.Flatten(input_shape=input_shape)]
52-
if act_func == "relu":
53-
activation = tf.nn.relu
54-
elif act_func == "sigmoid":
55-
activation = tf.nn.sigmoid
56-
elif act_func == "tanh":
57-
activation = tf.nn.tanh
58-
59-
for i in range(num_layers):
60-
layers.append(tf.keras.layers.Dense(architecture[i], activation=tf.nn.relu))
61-
layers.append(tf.keras.layers.Dense(output_class, activation=tf.nn.softmax))
62-
63-
model = tf.keras.models.Sequential(layers)
64-
return model
54+
layers = [tf.keras.layers.Flatten(input_shape=input_shape)]
55+
if act_func == "relu":
56+
activation = tf.nn.relu
57+
elif act_func == "sigmoid":
58+
activation = tf.nn.sigmoid
59+
elif act_func == "tanh":
60+
activation = tf.nn.tanh
61+
62+
for i in range(num_layers):
63+
layers.append(tf.keras.layers.Dense(architecture[i], activation=tf.nn.relu))
64+
layers.append(tf.keras.layers.Dense(output_class, activation=tf.nn.softmax))
65+
66+
model = tf.keras.models.Sequential(layers)
67+
return model
6568

6669

6770
def build_regression_model(

0 commit comments

Comments
 (0)