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

The id corresponding to this prediction.

Return type

int

property rank

The rank of this prediction among results.

Return type

int

property distance

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

The duration of the inference in seconds.

Return type

float

property predictions

The list of predictions.

Return type

List[ReIdentificationPrediction]

property distance_matrix

The cosine distance matrix for the re-identification.

Return type

Optional[ndarray]

property image

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

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

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

Optional[ndarray]

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

Optional[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

publish_analytics(results, tag=None, **kwargs)

Publish ReIdentification results to the alwaysAI Analytics Service

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

  • tag – Additional information to assist in querying and visualizations.