Spaces:
Build error
Build error
Update modelutil.py
Browse files- modelutil.py +27 -13
modelutil.py
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import tensorflow as tf
|
| 2 |
|
| 3 |
def create_model():
|
| 4 |
-
|
| 5 |
LAYERS = [tf.keras.layers.Flatten(input_shape=[28,28], name="inputlayer"),
|
| 6 |
tf.keras.layers.Dense(300, activation='relu', name="hiddenlayer1"),
|
| 7 |
tf.keras.layers.Dense(100, activation='relu', name="hiddenlayer2"),
|
| 8 |
tf.keras.layers.Dense(10, activation='softmax', name="outputlayer")]
|
| 9 |
|
| 10 |
model = tf.keras.models.Sequential(LAYERS)
|
| 11 |
-
|
| 12 |
-
model.load_weights('./checkpoint')
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
# LOSS_FUNCTION = tf.keras.losses.SparseCategoricalCrossentropy() # HERE
|
| 16 |
-
# OPTIMIZER = tf.keras.optimizers.legacy.Adam()
|
| 17 |
-
# METRICS = ["accuracy"]
|
| 18 |
-
# model.compile(loss=LOSS_FUNCTION,
|
| 19 |
-
# optimizer=OPTIMIZER,
|
| 20 |
-
# metrics=METRICS)
|
| 21 |
-
|
| 22 |
return model
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
| 1 |
+
# import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
# def create_model():
|
| 4 |
+
|
| 5 |
+
# LAYERS = [tf.keras.layers.Flatten(input_shape=[28,28], name="inputlayer"),
|
| 6 |
+
# tf.keras.layers.Dense(300, activation='relu', name="hiddenlayer1"),
|
| 7 |
+
# tf.keras.layers.Dense(100, activation='relu', name="hiddenlayer2"),
|
| 8 |
+
# tf.keras.layers.Dense(10, activation='softmax', name="outputlayer")]
|
| 9 |
+
|
| 10 |
+
# model = tf.keras.models.Sequential(LAYERS)
|
| 11 |
+
|
| 12 |
+
# model.load_weights('./checkpoint')
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# # LOSS_FUNCTION = tf.keras.losses.SparseCategoricalCrossentropy() # HERE
|
| 16 |
+
# # OPTIMIZER = tf.keras.optimizers.legacy.Adam()
|
| 17 |
+
# # METRICS = ["accuracy"]
|
| 18 |
+
# # model.compile(loss=LOSS_FUNCTION,
|
| 19 |
+
# # optimizer=OPTIMIZER,
|
| 20 |
+
# # metrics=METRICS)
|
| 21 |
+
|
| 22 |
+
# return model
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
import tensorflow as tf
|
| 27 |
|
| 28 |
def create_model():
|
|
|
|
| 29 |
LAYERS = [tf.keras.layers.Flatten(input_shape=[28,28], name="inputlayer"),
|
| 30 |
tf.keras.layers.Dense(300, activation='relu', name="hiddenlayer1"),
|
| 31 |
tf.keras.layers.Dense(100, activation='relu', name="hiddenlayer2"),
|
| 32 |
tf.keras.layers.Dense(10, activation='softmax', name="outputlayer")]
|
| 33 |
|
| 34 |
model = tf.keras.models.Sequential(LAYERS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
return model
|
| 36 |
|
| 37 |
+
def load_model_weights(model, checkpoint_path):
|
| 38 |
+
model.load_weights(checkpoint_path)
|