Skip to content

lacss.deploy

Attributes:

Name Type Description
model_urls

URLs for build-in pretrain models. e.g model_urls["default"].

Predictor

Main class interface for model deployment. This is the only class you need if you don't train your own model

Examples:

The most common use case is to use a build-in pretrained model.

import lacss.deploy

# look up the url of a build-in mode
url = lacss.deploy.model_urls["default"]

# create the predictor instance
predictor = lacss.deploy.Predictor(url)

# make a prediction
label = predictor.predict(image)

Attributes:

Name Type Description
module

The underlying FLAX module

params

Model weights.

__init__(url, *, grid_size=544, step_size=480)

Construct Predictor

Parameters:

Name Type Description Default
url str | tuple[Module, dict]

A URL or local path to the saved model. URLs for build-in pretrained models can be found in lacss.deploy.model_urls

required

predict(image, *, output_type='label', reshape_to=None, min_area=0, score_threshold=0.5, segmentation_threshold=0.5, nms_iou=1, normalize=True, remove_out_of_bound=None)

Predict segmentation.

Parameters:

Name Type Description Default
image ArrayLike

A ndarray of (h,w,c) or (d,h,w,c) format. c must be 1-3

required

Other Parameters:

Name Type Description
output_type str

"label" | "contour" | "bbox"

reshape_to int | tuple[int] | None

If not None, the input image will be resized internally before send to the model. The results will be resized back to the scale of the orginal input image.

min_area float

Minimum area of a valid prediction.

score_threshold float

Min score needed to be included in the output.

segmentation_threshold float

Threshold value for segmentation

nms_iou float

IOU threshold value for non-max-supression post-processing

Returns:

Type Description
dict

For "label" output:

  • pred_scores: The prediction scores of each instance.
  • pred_label: a 2D image label. 0 is background.
dict

For "contour" output:

  • pred_scores: The prediction scores of each instance.
  • pred_contours: a list of polygon arrays in x-y format.
dict

For "bbox" output (ie MaskRCNN):

  • pred_scores: The prediction scores of each instance.
  • pred_bboxes: The bounding-boxes of detected instances in y0x0y1x1 format
  • pred_masks: A 3d array representing (rescaled) segmentation mask within bboxes

predict_on_large_image(image, *, reshape_to=None, gs=None, ss=None, nms_iou=0.0, score_threshold=0.5, segmentation_threshold=0.5, min_area=0, min_cells_per_patch=0, output_type='label')

Make prediction on very large image by dividing into a grid.

Direct model prediction on large image may cause out-of-memory error. This method divided the large image to smaller grid and then stitch the results to form the complete prediction.

Parameters:

Name Type Description Default
image ArrayLike

An image with (H, W, C) format.

required
gs int | None

An int value. Grid size of the computation.

None
ss int | None

An int value of stepping size. Must be small than gs to produce valid results.

None

Other Parameters:

Name Type Description
min_area float

Minimum area of a valid prediction.

score_threshold float

Min score needed to be included in the output.

segmentation_threshold float

Threshold value for segmentation.

nms_iou float

IOU threshold value for non-max-supression durint post-processing

Returns:

Type Description
dict
  • pred_scores: The prediction scores of each instance.
dict
  • pred_bboxes: The bounding-boxes of detected instances in y0x0y1x1 format
dict
  • pred_masks: A 3d array representing segmentation within bboxes