Skip to content

Commit

Permalink
Merge branch 'rvankoert:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rvankoert authored Mar 20, 2024
2 parents 71848d0 + a58fa53 commit 96aefa9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/convert_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def convert_model(directory: str, output_directory: str = None) \
logging.info("Converting model to .keras format...")
output_folder = os.path.join(output_directory, model.name)

# Check if there is already a model.keras file in the output folder
if os.path.exists(os.path.join(output_folder, 'model.keras')):
logging.warning("A model.keras file already exists in the output "
"folder. Attempting to load the model from disk.")
try:
return tf.keras.models.load_model(
os.path.join(output_folder, 'model.keras'),
custom_objects=custom_objects)
except Exception:
raise ValueError(
"Failed to load the model from disk. Please clean the "
f"output folder '{output_folder}' and try again.")

try:
# Copy the model directory to the output folder
shutil.copytree(directory, output_folder)
Expand Down

0 comments on commit 96aefa9

Please sign in to comment.