Created
January 10, 2020 04:26
-
-
Save thetonus/41b4b00c9559dd00092a4cd0a90dd85e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Convert Keras .h5 model to .tflite """ | |
from tensorflow.contrib import lite | |
def main(model_path: str) -> None: | |
try: | |
converter = lite.TFLiteConverter.from_keras_model_file(model_path) | |
model = converter.convert() | |
except Exception as e: | |
print(e) | |
return None | |
output_path = f"{model_path.split('.')[0]}.tflite" | |
with open(output_path, 'wb') as file: | |
file.write( model ) | |
if __name__ == "__main__": | |
from argparse import ArgumentParser | |
parser = ArgumentParser() | |
parser.add_argument("-m", "--model", type=str, required=True, help="Path of .h5 model") | |
args = parser.parse_args() | |
main(args.model) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment