dogBreedVision / helper.py
yussaaa's picture
lfs untrack non-binary files
0b96c2d
raw
history blame contribute delete
831 Bytes
import os
import datetime
import tensorflow as tf
import tensorflow_hub as hub
def save_model(model, suffix=None):
"""
Saves a given model in a models directory and appends a suffix (str)
for clarity and reuse.
"""
# Create model directory with current time
modeldir = os.path.join(
"../models", datetime.datetime.now().strftime("%Y%m%d-%H%M%s")
)
model_path = modeldir + "-" + suffix + ".h5" # save format of model
print(f"Saving model to: {model_path}...")
model.save(model_path)
return model_path
def load_model(model_path):
"""
Loads a saved model from a specified path.
"""
print(f"Loading saved model from: {model_path}")
model = tf.keras.models.load_model(
model_path, custom_objects={"KerasLayer": hub.KerasLayer}
)
return model