Classification

class ClassificationPrediction(confidence, label)

A single prediction from Classification.

Parameters
  • confidence (float) – The confidence of this prediction.

  • label (str) – The label describing this prediction result.

property label

The label describing this prediction result.

Type

string

property confidence

The confidence of this prediction.

Type

float

class ClassificationResults(predictions, duration, image)

All the results of classification from Classification.

Predictions are stored in sorted order, with descending order of confidence.

Parameters
  • predictions (list of class:ClassificationPrediction) – The list of predictions ordered by confidence descending.

  • duration (float) – The duration of the inference.

  • image (numpy array of image) – The image that the inference was performed on.

property duration

The duration of the inference in seconds.

Type

float

property predictions

The list of predictions.

Type

list of ClassificationPrediction

property image

The image the results were processed on.

Image is not available when results are obtained from EyeCloud Cameras.

Type

numpy array – The image in BGR format

class Classification(model_id)

Identify the most prominent object in an image.

Typical usage:

classifier = edgeiq.Classification('alwaysai/googlenet')
classifier.load(engine=edgeiq.Engine.DNN)

<get image>
results = classifier.classify_image(image)
for prediction in results.predictions:
    print('Label: {}, confidence: {}'.format(
        prediction.label, prediction.confidence))
Parameters

model_id (string) – The ID of the model you want to use for image classification.

classify_image(image, confidence_level=0.3)

Identify the most prominent object in the specified image.

Parameters
  • image (numpy array of image) – The image to analyze.

  • confidence_level (float in range [0.0, 1.0]) – The minimum confidence level required to successfully accept a classification.

Returns

ClassificationResults

publish_analytics(results, tag=None)

Publish Classification results to the alwaysAI Analytics Service

Parameters
  • results (ClassificationResults) – The results to publish.

  • tag (JSON-serializable object) – Additional information to assist in querying and visualizations.

property accelerator

The accelerator being used.

Return type

Optional[Accelerator]

property colors

The auto-generated colors for the loaded model.

Note: Initialized to None when the model doesn’t have any labels. Note: To update, the new colors list must be same length as the label list.

Return type

List[Tuple[int, int, int]]

property engine

The engine being used.

Return type

Optional[Engine]

property labels

The labels for the loaded model.

Note: Initialized to None when the model doesn’t have any labels.

Return type

List[str]

load(engine=<Engine.DNN: 'DNN'>, accelerator=<Accelerator.DEFAULT: 'DEFAULT'>)

Load the model to an engine and accelerator.

Parameters
  • engine (Engine) – The engine to load the model to

  • accelerator (Accelerator) – The accelerator to load the model to

property model_config

The configuration of the model that was loaded

Return type

ModelConfig

property model_id

The ID of the loaded model.

Return type

str

property model_purpose

The purpose of the model being used.

Return type

str