forked from thtrieu/darkflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pb_to_tflite.py
32 lines (22 loc) · 964 Bytes
/
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
import os
import tensorflow as tf
from config_options import options, base_data_dir
from darkflow.net.build import TFNet
options = options(base_data_dir, train=False)
# load network
tfnet = TFNet(options)
tfnet.savepb(base_data=base_data_dir)
graph_file = base_data_dir + "/built_graph/custom-yolov2.pb"
in_n = ["input"]
out_n = ["output"]
tflite_path = base_data_dir + "/tflite_model/"
if not os.path.exists(tflite_path):
os.mkdir(tflite_path)
converter1 = tf.lite.TocoConverter.from_frozen_graph(graph_file, in_n, out_n)
converter1.post_training_quantize = False
tflite_non_quantized_model = converter1.convert()
open(tflite_path + "non_quantized_model.tflite", "wb").write(tflite_non_quantized_model)
converter2 = tf.lite.TocoConverter.from_frozen_graph(graph_file, in_n, out_n)
converter2.post_training_quantize = True
tflite_quantized_model = converter2.convert()
open(tflite_path + "quantized_model.tflite", "wb").write(tflite_quantized_model)