This example demonstrates how to classify a single image using one of the TensorFlow pretrained models converted to TensorRT.
If you haven't already, follow the installation instructions here.
Assuming you have a trained and frozen image classification model, convert it to a plan using the following convert_plan script.
python scripts/convert_plan.py data/frozen_graphs/inception_v1.pb data/plans/inception_v1.plan input 224 224 InceptionV1/Logits/SpatialSqueeze 1 1048576 float
For reference, the inputs to the convert_plan.py script are
- frozen graph path
- output plan path
- input node name
- input height
- input width
- output node name
- max batch size
- max workspace size
- data type (float or half)
Once the plan file is generated, run the example Cpp/CUDA program to classify the image.
./build/examples/classify_image/classify_image data/images/gordon_setter.jpg data/plans/inception_v1.plan data/imagenet_labels_1001.txt input InceptionV1/Logits/SpatialSqueeze inception
You should see that the most probable index is 215, which using our label file corresponds to a "Gordon setter". For reference, the inputs to the classify_image example are
- input image path
- plan file path
- labels file (one label per line, line number corresponds to index in output)
- input node name
- output node name
- preprocessing function (either vgg or inception. see: this)
To use other networks, supply the classify_image executable with arguments corresponding to the default networks table (link). You will need to generate the corresponding PLAN file as well.