-
Notifications
You must be signed in to change notification settings - Fork 3
/
convert_pb_to_tflite.py
45 lines (32 loc) · 1.19 KB
/
convert_pb_to_tflite.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
"""
It's Just Work With Tensorflow v1.14.0
"""
import tensorflow as tf
import argparse
import re
import os
def parse_args():
desc = "ARGANv1"
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('--pb_file', type=str, default='output_graph.pb', help='pb File Path')
"""checking arguments"""
return parser.parse_args()
def main( arguments ):
graph_def_file = 'converted_models/pb/' + arguments.pb_file
base_file = os.path.basename( graph_def_file ).replace('.pb', '')
input_arrays = ["generator/G_MODEL/A/MirrorPad"]
output_arrays = ["generator/G_MODEL/out_layer/Tanh"]
converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph(
graph_def_file=graph_def_file,
input_arrays=input_arrays,
input_shapes={'generator/G_MODEL/A/MirrorPad' : [5, 262, 262,3]},
output_arrays=output_arrays
)
tflite_model = converter.convert()
# # Save the model.
with open( f'converted_models/tflite/{base_file}.tflite', 'wb') as f:
f.write(tflite_model)
print("Model Is Converted to Tf-Lite Version")
if __name__ == '__main__':
arg = parse_args()
main( arg )