segmenter_model_zoo package

Subpackages

Submodules

segmenter_model_zoo.quilt_utils module

class segmenter_model_zoo.quilt_utils.QuiltModelZoo[source]

Bases: object

download model from quilt

connect to model zoo on quilt3

download_model(model_name: str, save_path: Union[str, pathlib.Path] = './zoo/model.pth')[source]

download the model “model_name” to “out_path”

Paremeters — model_name: str

the name of the model to be downloaded

save_path: Union(str, Path)

the path to save the model, default is ‘./zoo/model.pth’

peak_all_models() → List[source]

print out names of existing models in the model zoo

segmenter_model_zoo.quilt_utils.validate_model(model_name, save_path)[source]

check if model exists, otherwise download it

segmenter_model_zoo.utils module

segmenter_model_zoo.utils.bb_intersection_over_union(boxA, boxB)[source]

computer IOU of two bounding boxes

segmenter_model_zoo.utils.exist_double_assignment(cell_pairs)[source]

check if one object is associated with multiple pairs

segmenter_model_zoo.utils.find_multi_assignment(cell_pairs)[source]

find all multi-assignment

segmenter_model_zoo.utils.find_strongest_associate(main_score, aux_score)[source]

find the most likely pair from all candidate in one bounding box

segmenter_model_zoo.utils.getLargestCC(labels, is_label=True)[source]

return the largest connect component from a label image or a binary image

segmenter_model_zoo.utils.load_filenames(data_config)[source]

load the filenames of all the images need to be processed based on config. Three types of loading are currently supported: - “folder”

  • two parameters are required: “dir” and “search”. Basically, we just

search using the rules defined by “search” (either “*” for all files or a regular expression) inside the folder “dir”. * one optional parameter: “data_range”. If provided, a specific range of all files will be processed, e.g. [0, 100] or [100, -1]. This is useful when running in a distributed setting.

  • “zstack”
    • one parameter: “dir” specifying the filepath

  • “csv”
    • two parameters are required: “file” and “column”. After loading the

    csv pointed by “file”, all filenames in the column defined by “column” will be identified as files to be processed.

segmenter_model_zoo.utils.prune_cell_pairs(multi_pair, current_best_pair)[source]

update candidates after taking out one pair

segmenter_model_zoo.utils.save_as_uint(img: numpy.ndarray, save_path: Union[str, pathlib.Path], core_fn: str, overwrite: bool = False, tag: str = 'segmentation')[source]

save the segmentation to disk as uint type (either 8-bit or 16-bit depending on data)

Parameters
  • img (np.ndarray) – the image to save

  • save_path (Union[str, Path]) – the path to save the image

  • core_fn (str) – saved filename will be {core_fn}_{tag}.tiff

  • overwrite (bool) – whether allowing overwriting existing results

  • tag (str) – the tag to be added to the end of output filename default is “segmentation”

segmenter_model_zoo.zoo module

class segmenter_model_zoo.zoo.SegModel[source]

Bases: object

apply_on_single_zstack(input_img: numpy.ndarray = None, filename: str = None, inputCh: Union[int, List[int]] = None, normalization: int = None, already_normalized: bool = False, cutoff: float = None, inference_param: Dict = {}) → numpy.ndarray[source]

Apply a trained model on an image

input_img: np.ndarray

the image to be applied can be passed in as a numpy array

filename: str

the image to be appplied can be passed in as a filename. If input_img is used, the filename will be omitted

inputCh: Union(int, List(int))

when filename is used, inputCh must be specified. It can be an integer (if only one channel is needed), or a list of integers (if multiple channels are needed). Each model may have different requirement.

normalization: int

an index to indicate which normalization reciepy will be used to normalize the image

already_normalized: bool

A flag to indicate whether the image has been normalized or not. This is applicable to both cases: numpy array or filename.

cutoff: float

a cutoff value can be passed in, which will be applied on the prediction. If nothing passed in, default value will be used.

inference_param: Dict

a dictionary to pass in extra parameters for inference. Currently, only one parameter is allowed: “ResizeRatio” (a list of three float numbers to indicate the ResizeRatio to apply on ZYX axis). More parameters may be added in the future.

output_img: np.ndarray

the segmentation result

get_cutoff()[source]

load the cutoff value to be applied on the prediction

list_all_trained_models()[source]

print all current models

load_train(checkpoint_name: str, model_param: Dict = {'local_path': './'})[source]

load a trained model

Parameters
  • checkpoint_name (str) – the name of the model, use list_all_trained_models() to get a list of all current models

  • model_param (Dict) – a dictionary of additional parameters can be passed in. If nothing is passed in, default parameters will be used. There are two important parameters: “local_path” and “model_path”. If “model_path” is specified, it will be loaded directly. Otherwise, the model will be downloaded from quilt and save at “local_path” (default is the current working directory).

reset()[source]
to_gpu(gpu_id)[source]
class segmenter_model_zoo.zoo.SuperModel(model_name: str, model_param: Dict = {'local_path': './'})[source]

Bases: object

Define a SuperModel

model_name: str

the name of the super model

model_param: Dict

the extra parameters for the super model. the order must match the order of models in this SuperModel. For each dict, there are two importance parameters: “local_path” and “model_path”. “model_path” is a dictionary specifying the path to each basic model, e.g. “model_path”: {“DNA_mask_production”: “/path/to/mask/model”, “DNA_seed_production”: “path/to/seed/model”}. If “model_path” is specified, the model will be loaded directly. Otherwise, the models will be downloaded from quilt and saved at “local_path” (default is the current working directory).

apply_on_single_zstack(input_img: numpy.ndarray = None, filename: Union[str, pathlib.Path] = None, inputCh: List = [0], **kwargs) → Union[numpy.ndarray, List][source]

Appply a super model on one image

input_img: np.ndarray

the image to be segmented, if it is not None, filename and inputCh will not be used. Otherwise, use filename and inputCh to read image

filename: Union(str, Path)

when input_img is None, use filename to load image

inputCh: List

when input_img is None, take specific channels from the image loaded from filename

output: Union[np.ndarray, List]

the segmentation result

segmenter_model_zoo.zoo.list_all_super_models(item: str = 'all')[source]

print all available super models

Module contents

Top-level package for segmenter_model_zoo.

segmenter_model_zoo.get_module_version()[source]