MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / create_network

Method create_network

samples/python/detectron2/build_engine.py:139–167  ·  view source on GitHub ↗

Parse the ONNX graph and create the corresponding TensorRT network definition. :param onnx_path: The path to the ONNX graph to load.

(self, onnx_path)

Source from the content-addressed store, hash-verified

137 self.parser = None
138
139 def create_network(self, onnx_path):
140 """
141 Parse the ONNX graph and create the corresponding TensorRT network definition.
142 :param onnx_path: The path to the ONNX graph to load.
143 """
144 network_flags = (1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH))
145
146 self.network = self.builder.create_network(network_flags)
147 self.parser = trt.OnnxParser(self.network, self.trt_logger)
148
149 onnx_path = os.path.realpath(onnx_path)
150 with open(onnx_path, "rb") as f:
151 if not self.parser.parse(f.read()):
152 log.error("Failed to load ONNX file: {}".format(onnx_path))
153 for error in range(self.parser.num_errors):
154 log.error(self.parser.get_error(error))
155 sys.exit(1)
156
157 inputs = [self.network.get_input(i) for i in range(self.network.num_inputs)]
158 outputs = [self.network.get_output(i) for i in range(self.network.num_outputs)]
159
160 log.info("Network Description")
161 for input in inputs:
162 self.batch_size = input.shape[0]
163 log.info("Input '{}' with shape {} and dtype {}".format(input.name, input.shape, input.dtype))
164 for output in outputs:
165 log.info("Output '{}' with shape {} and dtype {}".format(output.name, output.shape, output.dtype))
166 assert self.batch_size > 0
167 self.builder.max_batch_size = self.batch_size
168
169 def create_engine(self, engine_path, precision, config_file, calib_input=None, calib_cache=None, calib_num_images=5000,
170 calib_batch_size=8):

Callers 15

mainFunction · 0.95
supports_modelFunction · 0.45
call_implMethod · 0.45
__call__Method · 0.45
call_implMethod · 0.45
build_engineFunction · 0.45
build_engineFunction · 0.45
build_engine_onnxFunction · 0.45
build_engineFunction · 0.45
build_engineFunction · 0.45
build_engineFunction · 0.45

Calls 5

readMethod · 0.80
get_inputMethod · 0.80
parseMethod · 0.45
errorMethod · 0.45
infoMethod · 0.45

Tested by 1