The SampleDynamicReshape class implementes the dynamic reshape sample. More...
Public Member Functions | |
SampleDynamicReshape (const samplesCommon::OnnxSampleParams ¶ms) | |
bool | build () |
Builds both engines. More... | |
bool | prepare () |
Prepares the model for inference by creating execution contexts and allocating buffers. More... | |
bool | infer () |
Runs inference using TensorRT on a random image. More... | |
Private Types | |
template<typename T > | |
using | SampleUniquePtr = std::unique_ptr< T, samplesCommon::InferDeleter > |
Private Member Functions | |
bool | buildPreprocessorEngine (const SampleUniquePtr< nvinfer1::IBuilder > &builder) |
Builds an engine for preprocessing (mPreprocessorEngine). More... | |
bool | buildPredictionEngine (const SampleUniquePtr< nvinfer1::IBuilder > &builder) |
Builds an engine for prediction (mPredictionEngine). More... | |
Dims | loadPGMFile (const std::string &fileName) |
Loads a PGM file into mInput and returns the dimensions of the loaded image. More... | |
bool | validateOutput (int digit) |
Checks whether the model prediction (in mOutput) is correct. More... | |
template<typename T > | |
SampleUniquePtr< T > | makeUnique (T *t) |
Private Attributes | |
samplesCommon::OnnxSampleParams | mParams |
The parameters for the sample. More... | |
nvinfer1::Dims | mPredictionInputDims |
The dimensions of the input of the MNIST model. More... | |
nvinfer1::Dims | mPredictionOutputDims |
The dimensions of the output of the MNIST model. More... | |
SampleUniquePtr< nvinfer1::ICudaEngine > | mPreprocessorEngine {nullptr} |
SampleUniquePtr< nvinfer1::ICudaEngine > | mPredictionEngine {nullptr} |
SampleUniquePtr< nvinfer1::IExecutionContext > | mPreprocessorContext {nullptr} |
SampleUniquePtr< nvinfer1::IExecutionContext > | mPredictionContext {nullptr} |
samplesCommon::ManagedBuffer | mInput {} |
Host and device buffers for the input. More... | |
samplesCommon::DeviceBuffer | mPredictionInput {} |
Device buffer for the output of the preprocessor, i.e. More... | |
samplesCommon::ManagedBuffer | mOutput {} |
Host buffer for the ouptut. More... | |
The SampleDynamicReshape class implementes the dynamic reshape sample.
This class builds one engine that resizes a given input to the correct size, and a second engine based on an ONNX MNIST model that generates a prediction.
|
private |
|
inline |
bool SampleDynamicReshape::build | ( | ) |
Builds both engines.
Builds the two engines required for inference.
This function creates one TensorRT engine for resizing inputs to the correct sizes, then creates a TensorRT network by parsing the ONNX model and builds an engine that will be used to run inference (mPredictionEngine).
bool SampleDynamicReshape::prepare | ( | ) |
Prepares the model for inference by creating execution contexts and allocating buffers.
Prepares the model for inference by creating an execution context and allocating buffers.
This function sets up the sample for inference. This involves allocating buffers for the inputs and outputs, as well as creating TensorRT execution contexts for both engines. This only needs to be called a single time.
bool SampleDynamicReshape::infer | ( | ) |
Runs inference using TensorRT on a random image.
Runs inference for this sample.
This function is the main execution function of the sample. It runs inference for using a random image from the MNIST dataset as an input.
|
private |
Builds an engine for preprocessing (mPreprocessorEngine).
|
private |
Builds an engine for prediction (mPredictionEngine).
This function builds an engine for the MNIST model, and updates mPredictionInputDims and mPredictionOutputDims according to the dimensions specified by the model. The preprocessor reshapes inputs to mPredictionInputDims.
|
private |
Loads a PGM file into mInput and returns the dimensions of the loaded image.
This function loads the specified PGM file into the input host buffer.
|
private |
Checks whether the model prediction (in mOutput) is correct.
|
inlineprivate |
|
private |
The parameters for the sample.
|
private |
The dimensions of the input of the MNIST model.
|
private |
The dimensions of the output of the MNIST model.
|
private |
|
private |
|
private |
|
private |
|
private |
Host and device buffers for the input.
|
private |
Device buffer for the output of the preprocessor, i.e.
the input to the prediction model.
|
private |
Host buffer for the ouptut.