-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_engine.py
More file actions
37 lines (30 loc) · 1.17 KB
/
build_engine.py
File metadata and controls
37 lines (30 loc) · 1.17 KB
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
import argparse
import sys
from trt_engine_builder import TRTEngineBuilder
from trt_config import efficientdet_model_dict
def parse_arguments():
"""
Parses command-line arguments.
Returns:
argparse.Namespace: Parsed arguments.
"""
parser = argparse.ArgumentParser(description='Build TensorRT engine from an ONNX model.')
parser.add_argument('--model_type', '-m',
choices=list(efficientdet_model_dict.keys()),
default='efficientdet_lite0',
help='Model type to use for building the engine.')
parser.add_argument('--fp16', '-f',
action='store_true',
help='Enable FP16 precision for the TensorRT engine.')
return parser.parse_args()
def main():
args = parse_arguments()
# Initialize the TensorRT Engine Builder with parsed arguments
builder = TRTEngineBuilder(MODEL_TYPE=args.model_type, fp16=args.fp16)
if not builder.initialized:
print("Failed to initialize the TensorRT Engine Builder. Exiting.")
sys.exit(1)
# Build the engine
builder.build_engine()
if __name__ == '__main__':
main()