Bootstrapper Bootstrapper docs

Python API for developers

This page is for developers who import bootstrapper or change its code. To run Bootstrapper, see the commands and the config files.

This reference covers the bootstrapper package, except the model scripts in bootstrapper/models.

bootstrapper

Bootstrapper makes dense 3D instance segmentations of microscopy volumes from sparse 2D labels.

The bs command is bootstrapper.cli.cli. The package exports prepare, train, predict, segment, evaluate, refine, view and utils as click commands.

bootstrapper.blockwise

Run daisy and volara tasks blockwise, and raise when a block fails.

daisy 1.x counts a failed block as done. run_blockwise and run_volara_task check the task states and raise instead, and Monitor prints one short line per task.

bootstrapper.catalog

The models, what each reads and gives, and the chains that make one round.

bootstrapper.cli

This module defines the bs command group and bs run.

bs run runs the steps of a round in file order. Without --only or --from, bs run skips the leading steps of a directory round that are done and unchanged, but repeats every selected step of a single-file round.

Each run that starts a step writes a receipt into runs/. The entry point is cli.

bootstrapper.config

A config file contains one step or a whole round. [volumes.<name>] describes the data; [train.<name>], [predict.<name>], [segment], [segment.<name>], [refine] and [evaluate] are steps. A step needs a name only when its kind has several steps. Below your keys, a run tail of [run.<step>] tables contains the keys bs prepare derives.

load and load_round read the steps of a file or a round, and load_volumes reads its volumes.

bootstrapper.configs

Model setups and their checkpoints.

MODEL_DIR contains the model scripts, and MODEL_URLS gives the download URL of each shipped checkpoint. The functions copy a model's scripts into a setup and find or download its checkpoints.

bootstrapper.data

Array utilities: the commands of bs utils, and the masks bs prepare writes.

bootstrapper.data.bbox

bs utils bbox: crop an array to the bounding box of its positive voxels.

bootstrapper.data.convert

bs utils convert: convert a 3D image or a directory of 2D images to a Zarr array.

bootstrapper.data.mask

bs utils mask, and the training masks that bs prepare writes.

mask writes a mask of an image (nonzero voxels, closed in xy) or of labels (labels > 0). training_mask returns the path of a volume's training mask, and write_training_mask writes that mask.

bootstrapper.data.merge

bs utils merge: apply the merges of a LUTs file to a segmentation, blockwise.

bootstrapper.data.paths

The output path of a mask of an input array.

bootstrapper.data.scale_pyramid

bs utils scale-pyramid: write coarser or finer scale levels of an array, blockwise.

The command samples label arrays and never averages them. It averages image arrays to downscale and interpolates them to upscale.

bootstrapper.data.tissue_mask

bs utils tissue-mask: a tissue mask with no holes, for bs refine mask.

bootstrapper.derive

The run tail has the keys that bs prepare derives for each step from the volumes and the keys above. derive reads array metadata and net_config.json files, never voxels. A key that you set above stays out of the tail, and the keys that bs prepare derives from it use your value.

bootstrapper.discover

Find the arrays of a zarr container from their metadata alone.

bootstrapper.eval

The metrics and error maps of bs evaluate.

bootstrapper.eval.compute_errors

Error maps of a segmentation against the predictions that made it.

compute_errors computes affinities or LSDs from the segmentation. It writes their differences from the predictions as an error map and a thresholded error mask.

bootstrapper.eval.compute_metrics

Scores of a segmentation against ground truth, and the report of one segmentation.

compute_metrics gives VOI and NVI against ground-truth labels, and ERL and nERL against ground-truth skeletons. seg_report counts objects and foreground.

bootstrapper.evaluate

bs evaluate: score each segmentation of a round.

evaluate reports the object count, the foreground and the ids of the largest objects of each segmentation. It also compares each segmentation with ground-truth labels or skeletons when the step has [evaluate.gt], and with the predictions that made it when the step has [evaluate.pred]. The entry point is evaluate.

bootstrapper.gp

Gunpowder nodes for training and evaluation.

The nodes compute LSD targets and error maps, augment intensities and labels, and make synthetic labels. The model train.py scripts build their pipelines from them.

bootstrapper.gp.add_2d_lsds

A gunpowder node that computes 2D local shape descriptors, one section at a time.

bootstrapper.gp.add_aff_errors

A gunpowder node that computes an affinity error map and mask from a segmentation and predicted affinities.

bootstrapper.gp.add_lsd_errors

A gunpowder node that computes an LSD error map and mask from a segmentation and predicted LSDs.

bootstrapper.gp.add_lsds

A gunpowder node that computes the 3D local shape descriptors of a segmentation.

bootstrapper.gp.clahe_augment

A gunpowder node that applies CLAHE contrast augmentation at random, section by section.

bootstrapper.gp.create_labels

A gunpowder node that provides synthetic 3D labels.

bootstrapper.gp.create_mask

A gunpowder node that makes a uint8 mask where the input array is greater than zero.

bootstrapper.gp.custom_grow_boundary

A gunpowder node that grows the boundaries between labels.

bootstrapper.gp.defect_augment

A gunpowder node that adds section defects such as missing sections, low contrast and deformation.

bootstrapper.gp.deform_augment

A gunpowder node for elastic deformation that keeps raw and labels aligned.

bootstrapper.gp.expand_labels

A gunpowder node that grows labels into the background, one section at a time.

bootstrapper.gp.gamma_augment

A gunpowder node that changes the gamma of intensity arrays at random.

bootstrapper.gp.impulse_noise_augment

A gunpowder node that adds random impulse noise to intensity arrays.

bootstrapper.gp.obfuscate_labels

A gunpowder node that adds random splits, merges and artifacts to labels.

bootstrapper.gp.reject_sparse_labels

A gunpowder node that rejects batches with too few labelled voxels, and stops when no batch passes.

bootstrapper.gp.renumber

A gunpowder node that gives each connected component of a label array its own id.

bootstrapper.gp.smooth_augment

A gunpowder node that applies a random Gaussian blur to an intensity array.

bootstrapper.inputs

Open native Zarr arrays with funlib, or read OME-Zarr image levels (OME-NGFF 0.4 in Zarr format 2). For OME-Zarr, remove singleton time and channel axes and use its scale and translation in nm. docs/inputs.md gives the rules.

bootstrapper.params

The keys that bs prepare writes into the config files, with each key's value and what it does. A table name has * in place of a model or volume name. bs prepare writes an off key as a commented example.

bootstrapper.post

The segmentation methods of bs segment, and their helpers.

watershed, watershed_mutex and connected_components each give one method's entry point. The other modules supply the blockwise tasks, the graph database, the output names and the seeds.

bootstrapper.post.blockwise

Volara blockwise tasks for watershed segmentation.

bootstrapper.post.blockwise.extract_frags

Volara fragment extraction for mutex watershed, plain and seeded.

bootstrapper.post.blockwise.watershed_frags

A volara task that makes watershed fragments from affinities and writes their nodes to the graph database.

bootstrapper.post.blockwise.waterz_agglom

A volara task that writes waterz merge scores to the fragment graph.

bootstrapper.post.cc

Connected components of thresholded affinities, compiled with numba.

bootstrapper.post.connected_components

The cc method of bs segment thresholds the affinities, then labels connected components.

The entry point is cc_segmentation. It runs as one block over the ROI.

bootstrapper.post.merge_tree

A merge tree over a waterz merge history, for the merge score of two fragments.

bootstrapper.post.naming

Output names from segmentation params, and the params recorded on each output.

bootstrapper.post.seeds

Graph constraints and final ids for user-seeded mutex watershed. The graph database stores seed_id as text, so ids above 2^31 fit in a PostgreSQL column. Readers convert seed_id to int.

bootstrapper.post.sqlite

The SQLite graph database that the blockwise segmentation tasks share.

bootstrapper.post.watershed

The ws method of bs segment makes watershed fragments, agglomerates them with waterz, then writes one segmentation per threshold.

The entry point is watershed_segmentation. Fragment arrays use Zarr, LUT files go in lut_dir, and the graph database stores fragment nodes and edges for blockwise runs.

bootstrapper.post.watershed_mutex

The mws method of bs segment runs mutex watershed over the fragments and the affinity graph.

The entry point is mutex_watershed_segmentation. A seeds array, if given, keeps each seed id in one object. Fragment arrays use Zarr, LUT files go in lut_dir, and the graph database stores fragment nodes and edges for blockwise runs.

bootstrapper.post.ws

Watershed fragments from affinities or boundary distances, for one block.

bootstrapper.predict

bs predict: run a model's predict.py script over a volume.

With one GPU or none, and one worker, the script tiles the ROI with a gunpowder Scan. With more of either, daisy runs the script over ROI blocks on the selected GPUs or CPUs. The entry point is predict.

bootstrapper.prepare

bs prepare: collect data settings through a dialogue or flags, then write the round. For an existing round, add the volume that the flags give and rewrite its run tails.

bootstrapper.refine

bs refine: run blockwise operations on a segmentation.

Filter objects by size, size outliers or z extent; remove or merge ids; or zero labels outside a mask. For morphology (dilate, erode, opening, closing and fill-holes), use bs refine morph --op; the other operations have their own commands. bs run chains the operations of a [refine] step.

bootstrapper.segment

bs segment: make segmentations from affinities.

The method is ws (watershed and waterz agglomeration), mws (mutex watershed) or cc (connected components). DEFAULTS gives the default parameters of each method. The entry point is segment; the methods are in bootstrapper.post.

bootstrapper.styles

The colors of the bs messages, with one palette for each step.

bootstrapper.train

bs train: train a model on the labelled volumes of a [train.*] step.

setup_train checks the samples, assigns their batch shares, and writes train.toml for the setup's train.py. run_training then runs that script. The entry point is train.

bootstrapper.training

The PyTorch Lightning training loop that the model train.py scripts share.

fit trains a model on gunpowder batches and saves checkpoints and snapshots in the setup. It resumes from the newest checkpoint.

bootstrapper.utils

bs utils: crop, mask, merge and rescale arrays, convert images to Zarr, and download checkpoints.

Each command except download-ckpts comes from a module of bootstrapper.data.

bootstrapper.view

bs view: show what the steps of a round wrote, a training snapshot, or array paths in neuroglancer. layer_type picks the layer type of each array from its name, dtype and channels.

bootstrapper.write

Build the TOML text of a config file. Each key in params.KEYS gets a comment that says what it does, and off keys and tables appear as comments. The run tail goes below a banner, and bs prepare replaces only the tail.