birdfsd_yolov5.api package

Submodules

birdfsd_yolov5.api.api module

This module contains the API endpoints for the model.

get_model_info(version: str = 'latest') _PrettyJSONResponse[source]

Returns the info of a specific version of the model.

Parameters

version – The model version.

Returns

A string containing the model of the server.

predict_endpoint(file: UploadFile, download: bool = False, download_cropped: bool = False) Union[Response, StreamingResponse, str][source]

Uses the backend model to predict the class of a given input image.

Parameters
  • file (UploadFile) – The UploadFile object of the image to be classified.

  • download (bool) – If True, the response is the labeled image bytes data.

  • download_cropped (bool) – If True, the response is a ZIP file with subdirectories of predicted class(es) containing cropped image(s) of the prediction(s).

Returns

A JSON string response with predictions (class, bbox, confidence), a URL to the labeled image, and information about the predicted species.

If download is set to True, the response is the labeled image bytes data.

If download_cropped is set to True, the response is a ZIP file with subdirectories of predicted class(es) containing cropped image(s) of the prediction(s) and a JSON file with the information about each prediction.

birdfsd_yolov5.api.api_utils module

This module contains utility functions for the model API.

create_cropped_images_object(pred: object) BytesIO[source]

Create a zip file object with cropped predictions.

Creates a zip file object containing cropped images and a json file with the labels and confidences.

Parameters

pred (object) – YOLOv5 Detections object.

Returns

A zip file object containing cropped images and a json file with the labels and confidences.

Return type

obj (io.BytesIO)

create_s3_client(api_s3: bool = False) Minio[source]

Creates a Minio client object.

Parameters

api_s3 – If True, use the API S3 credentials.

Returns

A Minio client object.

results_dict(name: str, object_hash: str, labeled_image_url: Optional[str], predictions: Dict[Union[int, str], Any], model_name: str, model_version: str, page: str) dict[source]

Creates a dictionary with the prediction result(s) for the API call.

Parameters
  • name (str) – The name of the image.

  • object_hash (str) – The hash of the image.

  • labeled_image_url (str) – The url of the labeled image.

  • predictions (list) – A list of dictionaries with the predictions.

  • model_name (str) – The name of the model.

  • model_version (str) – The version of the model.

  • page (str) – The GitHub page of the model.

Returns

A dictionary with the results of the image classification.

Return type

dict

species_info(species_name: str) Union[dict, str][source]

Retrieves a dictionary of information about the species.

This function takes a species name as input and returns a dictionary of information about the species.

Parameters

species_name (str) – The name of the species to be searched.

Returns

A dictionary of information about the species.

Return type

dict

Raises

ValueError – If the species name is not a string.

birdfsd_yolov5.api.model_utils module

This module is used to get the latest model weights and information.

get_latest_model_weights(s3_client: Minio, skip_download: bool = False) Tuple[str, str, str][source]

Get the latest model weights from the model collection in mongodb.

Parameters
  • s3_client (Minio) – Minio S3 client object

  • skip_download (bool) – If True, skip downloading the model weights from S3.

Returns

The version of the model weights model_name: The name of the model model_object_name: The name of the model weights file

Return type

model_version

init_model(s3: Minio, use_weights: Optional[str] = None) Tuple[str, str, str, Module][source]

This function initializes the model.

Parameters
  • s3 (Minio) – Minio S3 client object.

  • use_weights (str) – Use this weights file instead of the latest model.

Returns

The model version. model_name: The model name. model_weights: The model weights file name. model: The model object.

Return type

model_version

model_info(version: str) dict[source]

Returns the model information for the specified version.

Parameters

version (str) – The version of the model to be returned.

Returns

A dictionary containing the model information.

Return type

dict

Module contents