ReIdentification¶
- class ReIdentificationPrediction(id, rank, distance)¶
A single prediction from
ReIdentification
.- Parameters
id (
int
) – The id corresponding to this prediction.rank (
int
) – The rank of this prediction among results.distance (
float
) – The cosine distance of this prediction.
- property id: int¶
The id corresponding to this prediction.
- Return type
int
- property rank: int¶
The rank of this prediction among results.
- Return type
int
- property distance: float¶
The cosine distance of this prediction.
- Return type
float
- class ReIdentificationResults(predictions, distance_matrix, duration, image)¶
All the results of re-identification from
ReIdentification
.Predictions are stored in sorted order, with descending order of rank.
- Parameters
predictions (
List
[ReIdentificationPrediction
]) – The list of predictions ordered by rank.distance_matrix (
Optional
[ndarray
]) – The cosine distance matrix for the re-identification.duration (
float
) – The duration of the inference.image (
Optional
[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[ReIdentificationPrediction]¶
The list of predictions.
- Return type
- property distance_matrix: Optional[ndarray]¶
The cosine distance matrix for the re-identification.
- Return type
Optional
[ndarray
]
- property image: Optional[ndarray]¶
The image the results were processed on.
Image is not available when results are obtained from EyeCloud Cameras.
- Return type
Optional
[ndarray
]
- class ReIdentification(model_id, model_config=None)¶
Re-identify the object(image) against a set of known/tracked items.
- Parameters
model_id (
str
) – The ID of the model you want to use for image classification.
- set_per_id_gallery_limit(count, drop_method)¶
Set the limit of instances per ID to be maintained in the gallery
- Parameters
count (
int
) – Number of instances per ID to be maintained in the gallerydrop_method (
str
) – instances to drop if needed when add_to_gallery() is called Supported values [“drop_oldest”, “drop_random”, “drop_latest”]
- extract_features(image, flip_horizontal=True)¶
Compute feature matrix for the given image
- Parameters
image (
ndarray
) – Image for which features are to be extracted and returnedflip_horizontal (
bool
) – Flag to enable horizontal flip of image during feature extraction
- Return type
ndarray
- get_distances(image, gallery_images, flip_horizontal=True, normalize_distance=True)¶
Calculate the distance matrix between given image and gallery images
- Parameters
image (
ndarray
) – Image for which distances to gallery images will be returnedgallery_images (
List
[ndarray
]) – List of imagesflip_horizontal (
bool
) – Flag to enable horizontal flip of image during feature extractionnormalize_distance (
bool
) – Flag to return normalized distance matrix
- Return type
ndarray
- add_to_gallery(image, id, flip_horizontal=True)¶
Extract the features for the given image and add against the given ID to the gallery
- Parameters
image (
ndarray
) – Image to store in galleryid (
int
) – ID for the given imageflip_horizontal (
bool
) – Flag to enable horizontal flip of image during feature extraction
- remove_from_gallery(id)¶
Remove all the features corresponding to given ID from the gallery
- Parameters
id (
int
) – ID for which data needs to be removed
- 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.
- re_id_image(image, top_k=1, normalize_distance=True, flip_horizontal=True)¶
Re-identify the given object(image) against a set of known/tracked items (gallery).
- Parameters
image (
ndarray
) – The image to re-identifytop_k (
int
) – Number of top predictions to returnnormalize_distance (
bool
) – Flag to use normalized distance matrixflip_horizontal (
bool
) – Flag to enable horizontal flip of image during feature extraction
- Return type