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: str¶
The label describing this prediction result.
- Return type
str
- property confidence: float¶
The confidence of this prediction.
- Return 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
[ClassificationPrediction
]) – The list of predictions ordered by confidence descending.duration (
float
) – The duration of the inference.image (
ndarray
) – The image that the inference was performed on.
- property duration: float¶
The duration of the inference in seconds.
- Return type
float
- property predictions: List[ClassificationPrediction]¶
The list of predictions.
- Return type
List
[ClassificationPrediction
]
- property image: ndarray¶
The image the results were processed on.
- Return type
ndarray
- class Classification(model_id, model_config=None)¶
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 (
str
) – 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 (
ndarray
) – The image to analyze.confidence_level (
float
) – The minimum confidence level required to successfully accept a classification. Expected range: [0.0, 1.0].
- Return type
- property accelerator: Optional[Accelerator]¶
The accelerator being used.
- Return type
Optional
[Accelerator
]
- property colors: Optional[ndarray]¶
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
Optional
[ndarray
]
- property labels: Optional[List[str]]¶
The labels for the loaded model.
Note: Initialized to None when the model doesn’t have any labels.
- Return type
Optional
[List
[str
]]
- load(engine=Engine.DNN, accelerator=Accelerator.DEFAULT)¶
Load the model to an engine and accelerator.
- Parameters
engine (
Engine
) – The engine to load the model toaccelerator (
Accelerator
) – The accelerator to load the model to
- property model_config: ModelConfig¶
The configuration of the model that was loaded
- Return type
- property model_id: str¶
The ID of the loaded model.
- Return type
str
- property model_purpose: SupportedPurposes¶
The purpose of the model being used.
- Return type
SupportedPurposes
- publish_analytics(results, tag=None, **kwargs)¶
Publish results to the alwaysAI Analytics Service
Example usage:
try: inference.publish_analytics(results, tag='custom_tag') except edgeiq.PublishError as e: # Retry publish except edgeiq.ConnectionError as e: # Save state and exit app to reconnect
- Parameters
results (
TypeVar
(ResultsT
)) – The results to publish.tag (
Optional
[Any
]) – Additional information to assist in querying and visualizations.
- Raises
ConnectionBlockedError
when using connection to the alwaysAI Device Agent and resources are at capacity,- Raises
PacketRateError
when publish rate exceeds current limit,- Raises
PacketSizeError
when packet size exceeds current limit. Packet publish size and rate limits will be provided in the error message.