lacss.deploy
Attributes:
Name | Type | Description |
---|---|---|
model_urls |
Mapping[str, str]
|
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 |
Module
|
The underlying FLAX module |
params |
Params
|
Model weights. |
detector |
Detector
|
The detector submodule for convinence. A common use case is to customize this submodule during inference. e.g.
Detector submodule has no trained paramters. |
__init__(url, precompile_shape=None)
Construct Predictor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
A URL or local path to the saved model. URLs for build-in pretrained models can be found in lacss.deploy.model_urls |
required |
precompile_shape |
Optional[Shape]
|
Image shape(s) for precompiling. Otherwise the model will be recompiled for every new input image shape. |
None
|
predict(image, *, min_area=0, remove_out_of_bound=False, scaling=1.0, output_type='label', score_threshold=0.5, segmentation_threshold=0.5, nms_iou=1, **kwargs)
Predict segmentation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
ArrayLike
|
A ndarray of (h,w,c) format. Value of c must be 1-3 |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
output_type |
str
|
"label" | "contour" | "bbox" |
min_area |
float
|
Minimum area of a valid prediction. |
scaling |
float
|
A image scaling factor. If not 1, the input image will be resized internally before fed to the model. The results will be resized back to the scale of the orginal input image. |
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
|
For "label" output:
|
dict
|
For "contour" output:
|
dict
|
For "bbox" output (ie MaskRCNN):
|
predict_on_large_image(image, gs, ss, *, scaling=1, min_area=0, nms_iou=0.25, segmentation_threshold=0.5, score_threshold=0.5, output_type='label', min_cells_per_patch=0, disable_padding=False, **kwargs)
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
|
An int value. Grid size of the computation. |
required |
ss |
int
|
An int value of stepping size. Must be small than gs to produce valid results. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
output_type |
str
|
label" | "contour" | "bbox" |
min_area |
int
|
Minimum area of a valid prediction. |
scaling |
float
|
A image scaling factor. If not 1, the input image will be resized internally before fed to the model. The results will be resized back to the scale of the orginal input image. |
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
|
For "label" output:
|
dict
|
For "contour" output:
|
dict
|
For "bbox" output (ie MaskRCNN):
|
save(save_path)
Re-save the model by pickling.
In the form of (module, weights).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_path |
Path to the pkl file |
required |