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.

property rank: int

The rank of this prediction among results.

property distance: float

The cosine distance of this prediction.

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:
property duration: float

The duration of the inference in seconds.

property predictions: List[ReIdentificationPrediction]

The list of predictions.

property distance_matrix: ndarray | None

The cosine distance matrix for the re-identification.

property image: ndarray | None

The image the results were processed on.

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

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 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 gallery

  • drop_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 returned

  • flip_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 returned

  • gallery_images (List[ndarray]) – List of images

  • flip_horizontal (bool) – Flag to enable horizontal flip of image during feature extraction

  • normalize_distance (bool) – Flag to return normalized distance matrix

Return type:

ndarray

Extract the features for the given image and add against the given ID to the gallery

Parameters:
  • image (ndarray) – Image to store in gallery

  • id (int) – ID for the given image

  • flip_horizontal (bool) – Flag to enable horizontal flip of image during feature extraction

Remove all the features corresponding to given ID from the gallery

Parameters:

id (int) – ID for which data needs to be removed

property accelerator: Accelerator | None

The accelerator being used.

property colors: ndarray | None

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.

property engine: Engine | None

The engine being used.

property labels: List[str] | None

The labels for the loaded model.

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

load(engine=Engine.DNN, accelerator=Accelerator.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: ModelConfig

The configuration of the model that was loaded

property model_id: str

The ID of the loaded model.

property model_purpose: SupportedPurposes

The purpose of the model being used.

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-identify

  • top_k (int) – Number of top predictions to return

  • normalize_distance (bool) – Flag to use normalized distance matrix

  • flip_horizontal (bool) – Flag to enable horizontal flip of image during feature extraction

Return type:

ReIdentificationResults