TestImageClassification¶
Copyright (c) organization
- Author
btran
Functions
-
int
main(int argc, char *argv[]) The following steps outlines verbosely what the code in this .cpp file does.
Checks if the number of commandline arguments is not exactly 3. If true, output verbose error and exit with failure.
Store the first commandline argument as the file path to the referenced onnx model and the second as the file path to input image.
Instantiate an ImageClassificationOrtSessionHandler class object and initialize it with the total number of pretrained ImageNet Classes for squeezenet1.1.onnx with the file path to referenced onnx model.
Initialize the classNames in the class object with IMAGENET_CLASSES as defined under Constants.hpp.
Read in input image using Opencv.
Check if input image is empty. If so, output error and exit with failure.
Resize input image down to 244 by 244, as defined in this .cpp file.
Convert input image to 1-dimensional float array.
Pass 1-dimensional float array to ImageClassificationOrtSessionHandler preprocess function to account for ImageNet images Mean and Standard Deviation. This helps normalize the input image based on how squeezenet1.1.onnx was trained on ImageNet.
Start debug timer.
Pass normalized 1-dimensional float array to ImageClassificationOrtSessionHandler inference step and store in inferenceOutput variable.
Pass inferenceOutput to ImageClassificationOrtSessionHandler mutator function to output the first 5 pairs of object class name strings with their corresponding output confidence score.
Stop debug timer. Calculate and output to terminal the time taken to run 1000 rounds of inference.