Utils: pyvar.ml.utils

Label Reader Class

pyvar.ml.utils.label

platform:

Unix/Yocto

synopsis:

Class to handle labels file from Machine Learning models.

class pyvar.ml.utils.label.Label(labels_file_path=None)[source]
Variables:
  • labels_file – path to the labels file.

  • list – list with the labels from the label file.

read_labels(category=None)[source]

Reads Machine Learning labels file and save the result as a list.

Parameters:

category (str) – model category (classification or detection).

Returns:

True if the labels file was read successfully.

Overlay Class

pyvar.ml.utils.overlay

platform:

Unix/Yocto

synopsis:

Class to handle overlay on single images and frames.

class pyvar.ml.utils.overlay.Overlay[source]
Variables:
  • inference_time_info – shows the inference time on image/frame;

  • scores_info – shows the scores on image/frame;

  • extra_info – shows extra info on image/frame;

  • framerate_info – shows framerate on image/frame.

static generate_colors(labels)[source]
info(category=None, image=None, top_result=None, labels=None, inference_time=None, model_name=None, source_file=None, fps=None)[source]

Draw information on single images and frames such as inference time, scores, model name, and source file.

Parameters:
  • category (str) – model category (classification or detection);

  • image (numpy array) – original image to overlay the information.

  • top_result (list) – top results from the inference.

  • labels (list) – list of the read labels.

  • inference_time (str) – inference time from TFLiteInterpreter class.

  • model_name (str) – the model name.

  • source_file (str) – the source file name.

  • fps (float) – fpsit from Framerate class.

Returns:

The numpy.array image format with the overlaid information.

Frames Per Second Calculator Class

pyvar.ml.utils.framerate

platform:

Unix/Yocto

synopsis:

Class to calculate framerate from videos and real time cameras devices.

class pyvar.ml.utils.framerate.Framerate[source]
fpsit()[source]

Calculates the frames per second and save it in the fps attribute.

File Transfer Protocol Class

pyvar.ml.utils.retriever

Resizer Class

pyvar.ml.utils.resizer

platform:

Unix/Yocto

synopsis:

Class to resize image/frame.

class pyvar.ml.utils.resizer.Resizer[source]
Variables:
  • frame – original frame;

  • frame_resized – resized frame;

  • image – original image;

  • image_path – image path;

  • image_resized – image resized;

  • model_height – model height;

  • model_width – model width.

resize_frame(frame=None, width=None, height=None, expand_dims=True)[source]

Resize the frame.

Parameters:
  • frame (numpy array) – original frame to be resized;

  • width (int) – new width to resize;

  • height (int) – new height to resize;

  • expand_dims (bool) – if expand dimensions or not

Returns:

The numpy.array resized frame is stored at the frame_resized attribute.

resize_image(image_path=None, width=None, height=None, expand_dims=True)[source]

Resize the image.

Parameters:
  • image_path (numpy array) – original image to be resized;

  • width (int) – new width to resize;

  • height (int) – new height to resize;

  • expand_dims (bool) – if expand dimensions or not

Returns:

The numpy.array resized image is stored at image_resized attribute.

set_sizes(engine_input_details=None)[source]

Set the height and width model size.

Timer Calculator Class

pyvar.ml.utils.timer

platform:

Unix/Yocto

synopsis:

Python Class to calculate time.

class pyvar.ml.utils.timer.Timer[source]
timeit()[source]

Calculates the time and save it in the time attribute.