PlantSeg CNN Prediction
plantseg.functionals.prediction.prediction.unet_prediction(raw: np.ndarray, input_layout: ImageLayout, model_name: str | None, model_id: str | None, patch: tuple[int, int, int] | None = None, patch_halo: tuple[int, int, int] | None = None, single_batch_mode: bool = True, device: str = 'cuda', model_update: bool = False, disable_tqdm: bool = False, config_path: Path | None = None, model_weights_path: Path | None = None) -> np.ndarray
Generate prediction from raw data using a specified 3D U-Net model.
This function handles both single and multi-channel outputs from the model, returning appropriately shaped arrays based on the output channel configuration.
For Bioimage.IO Model Zoo models, weights are downloaded and loaded into UNet3D
or UNet2D
in plantseg.training.model
, i.e. bioimageio.core
is not used. biio_prediction()
uses
bioimageio.core
for loading and running models.
Parameters:
-
raw
(ndarray
) –Raw input data.
-
Input_layout
(ImageLayout
) –The layout of the input data.
-
model_name
(str | None
) –The name of the model to use.
-
model_id
(str | None
) –The ID of the model from the BioImage.IO model zoo.
-
patch
(tuple[int, int, int]
, default:None
) –Patch size for prediction. Defaults to (80, 160, 160).
-
patch_halo
(tuple[int, int, int] | None
, default:None
) –Halo size around patches. Defaults to None.
-
single_batch_mode
(bool
, default:True
) –Whether to use a single batch for prediction. Defaults to True.
-
device
(str
, default:'cuda'
) –The computation device ('cpu', 'cuda', etc.). Defaults to 'cuda'.
-
model_update
(bool
, default:False
) –Whether to update the model to the latest version. Defaults to False.
-
disable_tqdm
(bool
, default:False
) –If True, disables the tqdm progress bar. Defaults to False.
-
config_path
(Path | None
, default:None
) –Path to the model configuration file. Defaults to None.
-
model_weights_path
(Path | None
, default:None
) –Path to the model weights file. Defaults to None.
Returns:
-
ndarray
–np.ndarray: The predicted boundaries as a 3D (Z, Y, X) or 4D (C, Z, Y, X) array, normalized between 0 and 1.
Raises:
-
ValueError
–If neither
model_name
,model_id
, norconfig_path
are provided.
Source code in plantseg/functionals/prediction/prediction.py
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|