Skip to content

Prediction API

run_instance_segmentation(image, net_size=256, mode='2D', isotrope=True, patches=True, voxel_size=(1.0, 1.0, 1.0), z_axis=0, weights_path=None)

Segment a grayscale image into labeled cell instances.

Parameters:

Name Type Description Default
image ndarray

Two-dimensional image or three-dimensional volume.

required
net_size int

Published model patch size: 256 for 2D; 128 or 256 for 3D.

256
mode ('2D', '3D')

Dimension of the input image.

"2D"
isotrope bool

Rescale a 3D volume to isotropic spacing before inference.

True
patches bool

Predict on overlapping patches. If false, resize the whole image to the model input size before prediction.

True
voxel_size tuple of float

Physical spacing for each array axis. Used for 3D isotropic rescaling.

(1.0, 1.0, 1.0)
z_axis int

Axis treated as the axial direction for 3D rescaling.

0
weights_path path - like

Local model weights. If omitted, use the published model cache.

None

Returns:

Type Description
ndarray

Integer instance labels, with the same shape as image; zero is background.

Raises:

Type Description
ValueError

If the dimension, patch size, or voxel spacing is invalid.

FileNotFoundError

If weights_path does not exist.

run_instance_segmentation is the supported Python prediction entry point. It returns an integer NumPy array with the same shape as the input image.