forked from NVIDIA-AI-IOT/tf_to_trt_image_classification
-
Notifications
You must be signed in to change notification settings - Fork 3
/
convert_plan.py
72 lines (59 loc) · 1.9 KB
/
convert_plan.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
# Full license terms provided in LICENSE.md file.
import os
import subprocess
import uff
import pdb
import sys
UFF_TO_PLAN_EXE_PATH = 'build/src/uff_to_plan'
TMP_UFF_FILENAME = 'data/tmp.uff'
def frozenToPlan(frozen_graph_filename, plan_filename, input_name, input_height,
input_width, output_name, max_batch_size, max_workspace_size, data_type):
# generate uff from frozen graph
uff_model = uff.from_tensorflow_frozen_model(
frozen_file=frozen_graph_filename,
output_nodes=[output_name],
output_filename=TMP_UFF_FILENAME,
text=False,
)
# convert frozen graph to engine (plan)
args = [
TMP_UFF_FILENAME,
plan_filename,
input_name,
str(input_height),
str(input_width),
output_name,
str(max_batch_size),
str(max_workspace_size),
data_type # float / half
]
subprocess.call([UFF_TO_PLAN_EXE_PATH] + args)
# cleanup tmp file
os.remove(TMP_UFF_FILENAME)
if __name__ == '__main__':
if not os.path.exists('data/plans'):
os.makedirs('data/plans')
if len(sys.argv) is not 10:
print("usage: python convert_plan.py <frozen_graph_path> <output_plan_path> <input_name> <input_height>"
" <input_width> <output_name> <max_batch_size> <max_workspace_size> <data_type>")
exit()
frozen_graph_filename = sys.argv[1]
plan_filename = sys.argv[2]
input_name = sys.argv[3]
input_height = sys.argv[4]
input_width = sys.argv[5]
output_name = sys.argv[6]
max_batch_size = sys.argv[7]
max_workspace_size = sys.argv[8]
data_type = sys.argv[9]
frozenToPlan(frozen_graph_filename,
plan_filename,
input_name,
input_height,
input_width,
output_name,
max_batch_size,
max_workspace_size,
data_type
)