The SampleMLP class implements the MNIST API sample. More...
Public Member Functions | |
SampleMLP (const SampleMLPParams ¶ms) | |
bool | build () |
Function builds the network engine. More... | |
bool | infer () |
Runs the TensorRT inference engine for this sample. More... | |
bool | teardown () |
Cleans up any state created in the sample class. More... | |
Private Types | |
template<typename T > | |
using | SampleUniquePtr = std::unique_ptr< T, samplesCommon::InferDeleter > |
Private Member Functions | |
bool | constructNetwork (SampleUniquePtr< nvinfer1::IBuilder > &builder, SampleUniquePtr< nvinfer1::INetworkDefinition > &network, SampleUniquePtr< nvinfer1::IBuilderConfig > &config) |
Uses the API to create the MLP Network. More... | |
bool | processInput (const samplesCommon::BufferManager &buffers) |
Reads the input and stores the result in a managed buffer. More... | |
bool | verifyOutput (const samplesCommon::BufferManager &buffers) |
Classifies digits and verify result. More... | |
std::map< std::string, std::pair< nvinfer1::Dims, nvinfer1::Weights > > | loadWeights (const std::string &file) |
Loads weights from weights file. More... | |
nvinfer1::Dims | loadShape (std::ifstream &input) |
Loads shape from weights file. More... | |
void | transposeWeights (nvinfer1::Weights &wts, int hiddenSize) |
Transpose weights. More... | |
nvinfer1::ILayer * | addMLPLayer (nvinfer1::INetworkDefinition *network, nvinfer1::ITensor &inputTensor, int32_t hiddenSize, nvinfer1::Weights wts, nvinfer1::Weights bias, nvinfer1::ActivationType actType, int idx) |
Add an MLP layer. More... | |
Private Attributes | |
SampleMLPParams | mParams |
The parameters for the sample. More... | |
int | mNumber {0} |
The number to classify. More... | |
std::map< std::string, std::pair< nvinfer1::Dims, nvinfer1::Weights > > | mWeightMap |
The weight name to weight value map. More... | |
std::shared_ptr< nvinfer1::ICudaEngine > | mEngine |
The TensorRT engine used to run the network. More... | |
std::vector< SampleUniquePtr< nvinfer1::IHostMemory > > | weightsMemory |
Host weights memory holder. More... | |
The SampleMLP class implements the MNIST API sample.
It creates the network for MNIST classification using the API
|
private |
|
inline |
bool SampleMLP::build | ( | ) |
Function builds the network engine.
Creates the network, configures the builder and creates the network engine.
This function creates the MLP network by using the API to create a model and builds the engine that will be used to run MNIST (mEngine)
bool SampleMLP::infer | ( | ) |
Runs the TensorRT inference engine for this sample.
This function is the main execution function of the sample. It allocates the buffer, sets inputs and executes the engine.
bool SampleMLP::teardown | ( | ) |
Cleans up any state created in the sample class.
|
private |
Uses the API to create the MLP Network.
network | Pointer to the network that will be populated with the MLP network |
builder | Pointer to the engine builder |
|
private |
Reads the input and stores the result in a managed buffer.
|
private |
Classifies digits and verify result.
|
private |
Loads weights from weights file.
Our weight files are in a very simple space delimited format. type is the integer value of the DataType enum in NvInfer.h. <number of buffers> for each buffer: [name] [type] [size] <data x size in hex>
|
private |
Loads shape from weights file.
|
private |
Transpose weights.
|
private |
Add an MLP layer.
The addMLPLayer function is a simple helper function that creates the combination required for an MLP layer. By replacing the implementation of this sequence with various implementations, then then it can be shown how TensorRT optimizations those layer sequences.
|
private |
The parameters for the sample.
|
private |
The number to classify.
|
private |
The weight name to weight value map.
|
private |
The TensorRT engine used to run the network.
|
private |
Host weights memory holder.