Image Classification

Image classification will take an image or part of an image and classify it into one of its categories. For example, a model trained on the Imagenet dataset would be able to correctly classify images in several different categories, including plants and animals. You should use a classifier if you have an image with a prominent object and want to know more about it. However, a classifier won’t locate an object in an image. For locating objects within an image, head to the Object Detection section.


Classification can be performed on an image using the Classification class. The first step is to instantiate a Classification object with the ID of the model to use. For example:

classification = edgeiq.Classification("alwaysai/googlenet")

If the model is not a classification model, the instantiation will fail with an error message indicating that the model can’t be used. Next, call the object’s load() function to initialize the inference engine and accelerator.


Unless directly specified, the accelerator chosen will be the default for the provided Engine. Now the image classifier is ready. Use the classify_image() function to classify an image. A confidence level can also be provided to filter out results that don’t meet the required confidence level.

results = classification.classify_image(image, confidence_level=0.5)

The results object is of type ClassificationResults and contains the duration of the inference, in seconds, and a list of predictions. Each prediction is of type ClassificationPrediction and contains the label and the confidence of that prediction.

Often, an image might contain several prominent objects. Since classification only classifies the most prominent object in the image, it can be useful to first perform object detection on the image, then cut out the important part of the image using the cutout_image() function:

new_image = edgeiq.cutout_image(image, bounding_box_prediction)

The function takes as input an image and an ObjectDetectionPrediction (the individual result type of ObjectDetection) and returns a cutout of the input image that is boxed in by the bounding box. Head to the Understanding the Results Objects section to learn more about how the results objects can be used.