Classifying Images with ImageNet
There are multiple types of deep learning networks available, including recognition, detection/localization, and semantic segmentation. The first deep learning capability we're highlighting in this tutorial is image recognition using classifcation networks that have been trained to identify scenes and objects.
imageNet object accepts an input image and outputs the probability for each class. Having been trained on the ImageNet ILSVRC dataset of 1000 objects, the GoogleNet and ResNet-18 models were automatically downloaded during the build step. See below for other classification models that can be downloaded and used as well.
As examples of using
imageNet we provide versions of a command-line interface for C++ and Python:
Later in the tutorial, we'll also cover versions of a live camera recognition program for C++ and Python:
Using the Console Program on Jetson
First, let's try using the
imagenet-console program to test imageNet recognition on some example images. It loads an image, uses TensorRT and the
imageNet class to perform the inference, then overlays the classification result and saves the output image. The repo comes with some sample images for you to use.
After building the repo, make sure your terminal is located in the
$ cd jetson-inference/build/aarch64/bin
imagenet-console accepts 3 command-line arguments:
- the path to an input image (
jpg, png, tga, bmp)
- optional path to output image (
jpg, png, tga, bmp)
--networkflag which changes the classification model being used (the default network is GoogleNet).
Note that there are additional command line parameters available for loading customized models. Launch the application with the
--help flag to recieve more info about using them, or see the
Code Examples readme.
Here are a couple examples of running the program in C++ or Python:
$ ./imagenet-console --network=googlenet orange_0.jpg output_0.jpg # --network flag is optional
$ ./imagenet-console.py --network=googlenet orange_0.jpg output_0.jpg # --network flag is optional
note: the first time you run the program, TensorRT may take up to a few minutes to optimize the network.
this optimized network file is cached to disk after the first run, so future runs will load faster.
$ ./imagenet-console granny_smith_1.jpg output_1.jpg
$ ./imagenet-console.py granny_smith_1.jpg output_1.jpg
Downloading Other Classification Models
By default, the repo is set to download the GoogleNet and ResNet-18 networks during the build step.
There are other pre-trained models that you can use as well, should you choose to download them:
|Network||CLI argument||NetworkType enum|
note: to download additional networks, run the Model Downloader tool
$ cd jetson-inference/tools
Generally the more complex networks can have greater classification accuracy, with increased runtime.
Using Different Classification Models
You can specify which model to load by setting the
--network flag on the command line to one of the corresponding CLI arguments from the table above. By default, GoogleNet is loaded if the optional
--network flag isn't specified.
Below are some examples of using the ResNet-18 model:
# C++ $ ./imagenet-console --network=resnet-18 jellyfish.jpg output_jellyfish.jpg # Python $ ./imagenet-console.py --network=resnet-18 jellyfish.jpg output_jellyfish.jpg
# C++ $ ./imagenet-console --network=resnet-18 stingray.jpg output_stingray.jpg # Python $ ./imagenet-console.py --network=resnet-18 stingray.jpg output_stingray.jpg
# C++ $ ./imagenet-console.py --network=resnet-18 coral.jpg output_coral.jpg # Python $ ./imagenet-console.py --network=resnet-18 coral.jpg output_coral.jpg
Feel free to experiment with using the different models and see how their accuracies and performance differ.
Next, we'll go through the steps to code your own image recognition program from scratch, first in Python and then C++.
© 2016-2019 NVIDIA | Table of Contents