-
Notifications
You must be signed in to change notification settings - Fork 2
/
h5_to_savedmodel.py
55 lines (35 loc) · 1.13 KB
/
h5_to_savedmodel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 13 02:51:07 2021
@author: Ibrah
"""
import argparse
import tensorflow as tf
def from_h5_to_export():
"""Converts an H5 model to a TFSavedModel"""
# Parse the command line arguments
args = parser.parse_args()
# Get the args as a dict(key,value)
variables = vars(args)
# Load the model
print("\nLoading the model...")
model = tf.keras.models.load_model(variables["source"])
print("\nDone!")
# Convert and save the output
model.save(variables["dest"])
print("\nDone!")
def create_parser():
"""Creates a parser for the command line runner"""
# Create the parser
parser = argparse.ArgumentParser(description="Converts an .h5 model to a TFSavedModel")
# Add arguments
# Model path
parser.add_argument("-source", help="Model path")
# Output path
parser.add_argument("-dest", help="Output path")
return parser
if __name__ == "__main__":
# Setup the parser
parser = create_parser()
# Conversion
from_h5_to_export()