lacss.deploy
Attributes:
Name | Type | Description |
---|---|---|
model_urls |
URLs for build-in pretrain models. e.g model_urls["default"]. |
Predictor
dataclass
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)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str | PathLike | tuple[Lacss, dict]
|
Model file (local or remote) or (module, parameters) tuple. If the parameters are a sequence instead of a dictionary, treat it as a model ensemble. |
required |
f16
|
bool
|
If true, compute in f16 precision (instead of the default f32) |
False
|
grid_size
|
int
|
Grid size for large images. Large image are broken down into grids to avoid GPU memeory overflow. |
544
|
step_size
|
int
|
Should be slightly smaller than grid_size to allow some overlap between grids. |
480
|
grid_size_3d
|
int
|
Grid_size for 3D input. |
256
|
step_size_3d
|
int
|
Step_size for 3D input. |
192
|
mask_size
|
int
|
Only use for bbox output. The dimension of the segmentation mask output. |
36
|
mc_step_size
|
int
|
Only used for 3D contour output. The step size during the mesh generation. |
1
|
chain_approx
|
int
|
Only used for 2D contour output. Polygon generation rule. |
CHAIN_APPROX_SIMPLE
|
__post_init__()
validate parameters
_call_model(patch, score_threshold, size_threshold, threshold, padding_value)
Core inference routine: 1. Pad input image to regular size and call model function 2. clean up results 3. compute contours
_compute_contours_2d(predictions, img_sz, threshold)
2D contour using cv2
_process_image(image, score_threshold, size_threshold, threshold, padding_value)
process a 2d/3d image in grids
predict(image, *, output_type='label', reshape_to=None, min_area=0, score_threshold=0.5, segmentation_threshold=0.5, nms_iou=0.4, 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] | ndarray | 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:
|
dict
|
For "contour" output:
|
dict
|
For "bbox" output (ie MaskRCNN):
|
_ensemble_model_fn(module, params, image)
A JIT compiled function to call Lacss model ensemble if params is a sequence (not a dict), assuming a model ensemble and generate ensembed prediction.