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

Function main

samples/python/network_api_pytorch_mnist/sample.py:129–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127
128
129def main():
130 common.add_help(description="Runs an MNIST network using a PyTorch model")
131 # Train the PyTorch model
132 mnist_model = model.MnistModel()
133 mnist_model.learn()
134 weights = mnist_model.get_weights()
135 # Do inference with TensorRT.
136 engine = build_engine(weights)
137
138 # Build an engine, allocate buffers and create a stream.
139 # For more information on buffer allocation, refer to the introductory samples.
140 inputs, outputs, bindings, stream = common.allocate_buffers(engine)
141 context = engine.create_execution_context()
142
143 case_num = load_random_test_case(mnist_model, pagelocked_buffer=inputs[0].host)
144 # For more information on performing inference, refer to the introductory samples.
145 # The common.do_inference function will return a list of outputs - we only have one in this case.
146 [output] = common.do_inference_v2(context, bindings=bindings, inputs=inputs, outputs=outputs, stream=stream)
147 pred = np.argmax(output)
148 common.free_buffers(inputs, outputs, stream)
149 print("Test Case: " + str(case_num))
150 print("Prediction: " + str(pred))
151
152
153if __name__ == "__main__":

Callers 1

sample.pyFile · 0.70

Calls 6

learnMethod · 0.95
get_weightsMethod · 0.95
load_random_test_caseFunction · 0.85
printFunction · 0.85
build_engineFunction · 0.70
allocate_buffersMethod · 0.45

Tested by

no test coverage detected