tinyms.app

This module is to support vision visualization with opencv, which can help developers use pre-trained models to predict and show the reasoning image fast. Current it only supports object detection model.

class tinyms.app.ObjectDetector(config=None)[source]

ObjectDetector is a high-level class defined for building model,preproceing the input image, predicting and postprocessing the prediction output data.

Parameters

config (dict) – model config parsed from the json file under the app/object_detection/configs dir.

convert2tensor(transform_input)[source]

Convert the numpy data to the tensor format.

Parameters

transform_input (numpy.ndarray) – the preprocessing image.

Returns

Tensor, the converted image.

data_postprocess(predictions_output, image_shape)[source]

Postprocessing the predictions output data.

Parameters
  • predictions_output (list) – predictions output data.

  • image_shape (list) – the shape of the input image.

Returns

dict, the postprocessing result.

data_preprocess(input)[source]

Preprocess the input image.

Parameters

input (numpy.ndarray) – the input image.

Returns

list, the preprocess image shape. numpy.ndarray, the preprocess image result.

model_build(is_training=False)[source]

Build the object detection model to predict the image.

Parameters

is_training (bool) – default: False.

Returns

model.Model, generated object detection model.

model_load_and_predict(serve_model, input_tensor)[source]

Load the object detection model to predict the image.

Parameters
  • serve_model (model.Model) – object detection model.

  • input_tensor (Tensor) – the converted input image.

Returns

model.Model, object detection model loaded the checkpoint file. list, predictions output result.

tinyms.app.object_detection_predict(input, object_detector, is_training=False)[source]

An easy object detection model predicting method for beginning developers to use.

Parameters
  • input (numpy.ndarray) – the input image.

  • object_detector (ObjectDetector) – the instance of the ObjectDetector class.

  • is_training (bool) – default: False.

Returns

dict, the postprocessing result.

tinyms.app.visualize_boxes_on_image(img, bbox_data, box_color=(0, 255, 0), box_thickness=3, text_font=1, font_scale=3, text_color=(0, 0, 255), font_size=3, show_scores=True)[source]

Visualize the prediction image.

Parameters
  • img (numpy.ndarray) – the input image.

  • bbox_data (dict) – the predictions box data.

  • box_color (list) – the box color. Default: (0, 255, 0).

  • box_thickness (int) – box thickness. Default: 3.

  • text_font (Enum) – text font. Default: cv2.FONT_HERSHEY_PLAIN.

  • font_scale (int) – font scale. Default: 3.

  • text_color (list) – text color. Default: (0, 0, 255).

  • font_size (int) – font size. Default: 3.

  • show_scores (bool) – whether to show scores. Default: True.

Returns

numpy.ndarray, the output image drawed the prediction box.

tinyms.app.draw_boxes_on_image(img, boxes, box_scores, box_classes, box_color=(0, 255, 0), box_thickness=3, text_font=1, font_scale=3, text_color=(0, 0, 255), font_size=3, show_scores=True)[source]

Draw the prediction box for the input image.

Parameters
  • img (numpy.ndarray) – the input image.

  • boxes (list) – the box coordinates.

  • box_color (list) – the box color. Default: (0, 255, 0).

  • box_thickness (int) – box thickness. Default: 3.

  • text_font (Enum) – text font. Default: cv2.FONT_HERSHEY_PLAIN.

  • font_scale (int) – font scale. Default: 3.

  • text_color (list) – text color. Default: (0, 0, 255).

  • font_size (int) – font size. Default: 3.

  • show_scores (bool) – whether to show scores. Default: True.

Returns

numpy.ndarray, the output image drawed the prediction box.

tinyms.app.save_image(img, save_dir='./', img_name='no_name', img_format='jpg')[source]

Save the prediction image.

Parameters
  • img (numpy.ndarray) – the input image.

  • save_dir (str) – the dir to save the prediction image.

  • img_name (str) – the name of the prediction image. Default: ‘no_name’.

  • img_format (str) – the format of the prediction image. Default: ‘jpg’.

tinyms.app.load_and_parse_config(config_path)[source]

Load and parse the json file the object detection model.

Parameters

config_path (numpy.ndarray) – the config json file path.

Returns

dict, the model configuration.

class tinyms.app.ObjectDetector(config=None)[source]

ObjectDetector is a high-level class defined for building model,preproceing the input image, predicting and postprocessing the prediction output data.

Parameters

config (dict) – model config parsed from the json file under the app/object_detection/configs dir.

convert2tensor(transform_input)[source]

Convert the numpy data to the tensor format.

Parameters

transform_input (numpy.ndarray) – the preprocessing image.

Returns

Tensor, the converted image.

data_postprocess(predictions_output, image_shape)[source]

Postprocessing the predictions output data.

Parameters
  • predictions_output (list) – predictions output data.

  • image_shape (list) – the shape of the input image.

Returns

dict, the postprocessing result.

data_preprocess(input)[source]

Preprocess the input image.

Parameters

input (numpy.ndarray) – the input image.

Returns

list, the preprocess image shape. numpy.ndarray, the preprocess image result.

model_build(is_training=False)[source]

Build the object detection model to predict the image.

Parameters

is_training (bool) – default: False.

Returns

model.Model, generated object detection model.

model_load_and_predict(serve_model, input_tensor)[source]

Load the object detection model to predict the image.

Parameters
  • serve_model (model.Model) – object detection model.

  • input_tensor (Tensor) – the converted input image.

Returns

model.Model, object detection model loaded the checkpoint file. list, predictions output result.

tinyms.app.object_detection_predict(input, object_detector, is_training=False)[source]

An easy object detection model predicting method for beginning developers to use.

Parameters
  • input (numpy.ndarray) – the input image.

  • object_detector (ObjectDetector) – the instance of the ObjectDetector class.

  • is_training (bool) – default: False.

Returns

dict, the postprocessing result.

class tinyms.app.ObjectDetector(config=None)[source]

ObjectDetector is a high-level class defined for building model,preproceing the input image, predicting and postprocessing the prediction output data.

Parameters

config (dict) – model config parsed from the json file under the app/object_detection/configs dir.

convert2tensor(transform_input)[source]

Convert the numpy data to the tensor format.

Parameters

transform_input (numpy.ndarray) – the preprocessing image.

Returns

Tensor, the converted image.

data_postprocess(predictions_output, image_shape)[source]

Postprocessing the predictions output data.

Parameters
  • predictions_output (list) – predictions output data.

  • image_shape (list) – the shape of the input image.

Returns

dict, the postprocessing result.

data_preprocess(input)[source]

Preprocess the input image.

Parameters

input (numpy.ndarray) – the input image.

Returns

list, the preprocess image shape. numpy.ndarray, the preprocess image result.

model_build(is_training=False)[source]

Build the object detection model to predict the image.

Parameters

is_training (bool) – default: False.

Returns

model.Model, generated object detection model.

model_load_and_predict(serve_model, input_tensor)[source]

Load the object detection model to predict the image.

Parameters
  • serve_model (model.Model) – object detection model.

  • input_tensor (Tensor) – the converted input image.

Returns

model.Model, object detection model loaded the checkpoint file. list, predictions output result.

tinyms.app.object_detection_predict(input, object_detector, is_training=False)[source]

An easy object detection model predicting method for beginning developers to use.

Parameters
  • input (numpy.ndarray) – the input image.

  • object_detector (ObjectDetector) – the instance of the ObjectDetector class.

  • is_training (bool) – default: False.

Returns

dict, the postprocessing result.