Inference
from tifffile import imread
from napari_cellseg3d.config import ModelInfo
from napari_cellseg3d.dev_scripts import remote_inference as cs3d
image = imread("examples/c5image.tif")
config = cs3d.CONFIG # InferenceWorkerConfig with defaults for a single volume
config.model_info = ModelInfo(name="SwinUNetR", model_input_size=64, num_classes=2)
results = cs3d.inference_on_images(image, config=config)
labels, stats = cs3d.post_processing(
results[0].semantic_segmentation,
config=cs3d.PostProcessConfig(),
)
For WNet3D, pass results[0].semantic_segmentation[1] to post_processing.
Functions
napari_cellseg3d.dev_scripts.remote_inference.inference_on_images
inference_on_images(image: array, config: InferenceWorkerConfig = CONFIG)
This function provides inference on an image with minimal config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array
|
Image to perform inference on. |
required |
config
|
InferenceWorkerConfig
|
Config for InferenceWorker. Defaults to CONFIG, see above. |
CONFIG
|
Source code in napari_cellseg3d/dev_scripts/remote_inference.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
napari_cellseg3d.dev_scripts.remote_inference.post_processing
post_processing(semantic_segmentation, config: PostProcessConfig = None)
Run post-processing on inference results.
Source code in napari_cellseg3d/dev_scripts/remote_inference.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
napari_cellseg3d.dev_scripts.remote_inference.PostProcessConfig
dataclass
Config for post-processing.
Source code in napari_cellseg3d/dev_scripts/remote_inference.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
Configuration and worker
InferenceWorkerConfig: device, model, weights, sliding window and post-processing settings.ModelInfo: model name, input size and number of classes.SlidingWindowConfig: window size and overlap.InferenceResult: whatinference_on_imagesreturns, one per image.InferenceWorker: the workerinference_on_imagesruns.