client
¤
Classes:
| Name | Description |
|---|---|
DescriptionSerializer |
Description serializer intended for client/server communication, NOT for sharing resource descriptions. |
GradioModelAdapter |
Model adapter to use the bioimage-io-gradio-runner as a backend for model inference. |
GradioPredictionPipeline |
Prediction pipeline to use the bioimage-io-gradio-runner as a fully remote prediction pipeline. |
Attributes:
| Name | Type | Description |
|---|---|---|
SerializedSampleBlock |
|
SerializedSampleBlock
module-attribute
¤
SerializedSampleBlock = Dict[str, JsonValue]
DescriptionSerializer
¤
Description serializer intended for client/server communication, NOT for sharing resource descriptions.
This serializer only includes local files to keep the serialized package small.
Methods:
| Name | Description |
|---|---|
deserialize |
|
deserialize_from_string |
|
serialize |
|
serialize_to_string |
|
serialize_to_string_and_hash |
|
Attributes:
| Name | Type | Description |
|---|---|---|
STRING_ENCODING |
|
deserialize
staticmethod
¤
deserialize(serialized: bytes) -> ResourceDescr
Source code in src/bioimageio/core/_description_serializer.py
51 52 53 54 55 56 57 | |
deserialize_from_string
classmethod
¤
deserialize_from_string(serialized: str) -> ResourceDescr
Source code in src/bioimageio/core/_description_serializer.py
46 47 48 49 | |
serialize
staticmethod
¤
serialize(rd: ResourceDescr) -> bytes
Source code in src/bioimageio/core/_description_serializer.py
24 25 26 27 28 | |
serialize_to_string
classmethod
¤
serialize_to_string(rd: ResourceDescr) -> str
Source code in src/bioimageio/core/_description_serializer.py
30 31 32 33 34 35 36 37 38 39 40 | |
serialize_to_string_and_hash
classmethod
¤
serialize_to_string_and_hash(rd: ResourceDescr) -> Tuple[str, Sha256]
Source code in src/bioimageio/core/_description_serializer.py
59 60 61 62 63 64 65 66 67 68 69 | |
GradioModelAdapter
¤
GradioModelAdapter(model_description: AnyModelDescr, *, server: Optional[str] = None)
Bases: RemoteModelAdapter[SerializedSampleBlock]
flowchart TD
bioimageio.core.remote_backends.gradio.client.GradioModelAdapter[GradioModelAdapter]
bioimageio.core._model_adapter.RemoteModelAdapter[RemoteModelAdapter]
bioimageio.core._model_adapter.ModelAdapter[ModelAdapter]
bioimageio.core._model_adapter.RemoteModelAdapter --> bioimageio.core.remote_backends.gradio.client.GradioModelAdapter
bioimageio.core._model_adapter.ModelAdapter --> bioimageio.core._model_adapter.RemoteModelAdapter
click bioimageio.core.remote_backends.gradio.client.GradioModelAdapter href "" "bioimageio.core.remote_backends.gradio.client.GradioModelAdapter"
click bioimageio.core._model_adapter.RemoteModelAdapter href "" "bioimageio.core._model_adapter.RemoteModelAdapter"
click bioimageio.core._model_adapter.ModelAdapter href "" "bioimageio.core._model_adapter.ModelAdapter"
Model adapter to use the bioimage-io-gradio-runner as a backend for model inference.
Note
- This adapter requires an environment with the same gradio version as the one used on the bioimage-io-gradio-runner server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AnyModelDescr
|
The model to run inference with. |
required |
|
Optional[str]
|
The URL of a running bioimage-io-gradio-server instance (default server might not be availability/compatible). |
None
|
-
API Reference
remote_backendscreate_remote_model_adapter
Methods:
| Name | Description |
|---|---|
close |
Close the model adapter, freeing any resources. |
forward |
|
load |
|
test |
Run the bioimageio model test. |
unload |
Unload model from any devices, freeing their memory. |
Attributes:
| Name | Type | Description |
|---|---|---|
model_descr |
AnyModelDescr
|
|
server |
str
|
|
Source code in src/bioimageio/core/remote_backends/gradio/client.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
close
¤
close()
Close the model adapter, freeing any resources.
Note
The moder adapter should be considered unusable afterwards.
Source code in src/bioimageio/core/_model_adapter.py
96 97 98 99 100 101 102 | |
forward
¤
Source code in src/bioimageio/core/_model_adapter.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
load
¤
load() -> None
Source code in src/bioimageio/core/remote_backends/gradio/client.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
test
¤
test() -> Optional[ValidationSummary]
Run the bioimageio model test.
Source code in src/bioimageio/core/remote_backends/gradio/client.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
unload
¤
unload()
Unload model from any devices, freeing their memory.
Note
The moder adapter should be considered unusable afterwards.
Source code in src/bioimageio/core/remote_backends/gradio/client.py
69 70 | |
GradioPredictionPipeline
¤
GradioPredictionPipeline(model_description: AnyModelDescr, *, server: Optional[str] = None, precomputed_statistics: Mapping[Measure, MeasureValue] = MappingProxyType({}), default_blocksize_parameter: BlocksizeParameter = 10, default_batch_size: int = 1)
Bases: RemotePredictionPipeline
flowchart TD
bioimageio.core.remote_backends.gradio.client.GradioPredictionPipeline[GradioPredictionPipeline]
bioimageio.core._prediction_pipeline.RemotePredictionPipeline[RemotePredictionPipeline]
bioimageio.core._prediction_pipeline._PredictionPipelineBase[_PredictionPipelineBase]
bioimageio.core._prediction_pipeline.RemotePredictionPipeline --> bioimageio.core.remote_backends.gradio.client.GradioPredictionPipeline
bioimageio.core._prediction_pipeline._PredictionPipelineBase --> bioimageio.core._prediction_pipeline.RemotePredictionPipeline
click bioimageio.core.remote_backends.gradio.client.GradioPredictionPipeline href "" "bioimageio.core.remote_backends.gradio.client.GradioPredictionPipeline"
click bioimageio.core._prediction_pipeline.RemotePredictionPipeline href "" "bioimageio.core._prediction_pipeline.RemotePredictionPipeline"
click bioimageio.core._prediction_pipeline._PredictionPipelineBase href "" "bioimageio.core._prediction_pipeline._PredictionPipelineBase"
Prediction pipeline to use the bioimage-io-gradio-runner as a fully remote prediction pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AnyModelDescr
|
The model to run inference with. |
required |
|
Optional[str]
|
The URL or Hugging Face space name of a running bioimageio gradio server instance (Note: default server might not be availabile/compatible!). |
None
|
Methods:
| Name | Description |
|---|---|
predict_sample_block |
Predict a single sample block. |
predict_sample_with_blocking |
Predict a sample by predicting sample blocks. |
predict_sample_with_blocking_yield_intermediates |
Predict |
predict_sample_with_fixed_blocking |
Predict |
predict_sample_with_fixed_blocking_yield_intermediates |
Predict |
predict_sample_without_blocking |
Predict a whole sample at once. |
Attributes:
| Name | Type | Description |
|---|---|---|
input_ids |
Sequence[MemberId]
|
|
model_descr |
AnyModelDescr
|
|
model_description |
AnyModelDescr
|
|
output_ids |
Sequence[MemberId]
|
|
pad_mode |
|
|
server |
str
|
|
Source code in src/bioimageio/core/remote_backends/gradio/client.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
pad_mode
instance-attribute
¤
pad_mode = {} if isinstance(model_descr, v0_4.ModelDescr) else {(descr.id): (descr.pad or v0_5.SymmetricPadding()) for descr in (model_descr.inputs)}
predict_sample_block
¤
predict_sample_block(sample_block: SampleBlock, skip_preprocessing: bool = False, skip_postprocessing: bool = False) -> SampleBlock
Predict a single sample block.
Note that this does not apply samplewise preprocessing or postprocessing steps, but only blockwise ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
SampleBlock
|
The sample block to predict on. |
required |
|
bool
|
If |
False
|
|
bool
|
If |
False
|
Source code in src/bioimageio/core/remote_backends/gradio/client.py
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 | |
predict_sample_with_blocking
¤
predict_sample_with_blocking(sample: Sample, skip_preprocessing: bool = False, skip_postprocessing: bool = False, ns: Optional[Union[v0_5.ParameterizedSize_N, Mapping[Tuple[MemberId, AxisId], v0_5.ParameterizedSize_N]]] = None, batch_size: Optional[int] = None) -> Sample
Predict a sample by predicting sample blocks.
Note: For fixed/known blocksizes use predict_sample_with_fixed_blocking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Sample
|
The sample to predict on. |
required |
|
bool
|
If |
False
|
|
bool
|
If |
False
|
|
Optional[Union[v0_5.ParameterizedSize_N, Mapping[Tuple[MemberId, AxisId], v0_5.ParameterizedSize_N]]]
|
Block size parameter(s) allows scaling the model's default input block size. Blocksize parameters are only applied to parameterized input axes, all other axis sizes are fixed/derived or (for output axes) data dependent. Unapplicable blocksize parameters are ignored. |
None
|
|
Optional[int]
|
Batch size to use for prediction. |
None
|
Source code in src/bioimageio/core/_prediction_pipeline.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
predict_sample_with_blocking_yield_intermediates
¤
predict_sample_with_blocking_yield_intermediates(sample: Sample, skip_preprocessing: bool = False, skip_postprocessing: bool = False, ns: Optional[Union[v0_5.ParameterizedSize_N, Mapping[Tuple[MemberId, AxisId], v0_5.ParameterizedSize_N]]] = None, batch_size: Optional[int] = None) -> Tuple[int, Iterable[IntermediatePrediction]]
Predict sample by predicting sample blocks and yield intermediate predictions if no samplewise postprocessing is included.
Also yields intermediate predictions if there are preceding prediction pipelines (model inputs depend on another model's outputs).
For preceding prediction pipelines ns and batch_size are shared, but pre- and postprocessing are never skipped in preceding pipelines.
Returns:
| Type | Description |
|---|---|
Tuple[int, Iterable[IntermediatePrediction]]
|
Tuple of number of prediction steps and an iterator of predicted intermediate samples with the last predicted block, All samples, but the last one, are intermediate samples with more and more blocks predicted. In case samplewise postprocessing needs to be applied, no intermediate results are yielded, but only the final sample after all blocks are predicted and postprocessed. In case of preceding prediction pipelines (model inputs depend on another model's outputs), intermediate results initially do not include the final output tensors at all. |
Source code in src/bioimageio/core/_prediction_pipeline.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
predict_sample_with_fixed_blocking
¤
predict_sample_with_fixed_blocking(sample: Sample, input_block_shape: PerMember[PerAxis[int]], skip_preprocessing: bool = False, skip_postprocessing: bool = False) -> Sample
Predict sample with given input_block_shape.
Note
input_block_shapeis expected to be a valid input shape for the model.- Use
predict_sample_with_blockingif you want to control block sizes via generic block size parameters rather than fixed block shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Sample
|
The sample to predict on. |
required |
|
PerMember[PerAxis[int]]
|
Mapping of input member id to mapping of axis id to block size for that axis. |
required |
|
bool
|
If |
False
|
|
bool
|
If |
False
|
Source code in src/bioimageio/core/_prediction_pipeline.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
predict_sample_with_fixed_blocking_yield_intermediates
¤
predict_sample_with_fixed_blocking_yield_intermediates(sample: Sample, input_block_shape: PerMember[PerAxis[int]], *, skip_preprocessing: bool = False, skip_postprocessing: bool = False, fill_value: float = float('nan')) -> Tuple[int, Iterable[IntermediatePrediction]]
Predict sample by predicting sample blocks of input_block_shape and yield intermediate predictions if no samplewise postprocessing is included.
Also yields intermediate predictions if there are preceding prediction pipelines (model inputs depend on another model's outputs).
For preceding prediction pipelines input_block_shape and fill_value are shared, but pre- and postprocessing are never skipped in preceding pipelines.
Returns:
| Type | Description |
|---|---|
Tuple[int, Iterable[IntermediatePrediction]]
|
Tuple of number of prediction steps and an iterator of predicted intermediate samples with the last predicted block, All samples, but the last one, are intermediate samples with more and more blocks predicted. In case samplewise postprocessing needs to be applied, no intermediate results are yielded, but only the final sample after all blocks are predicted and postprocessed. In case of preceding prediction pipelines (model inputs depend on another model's outputs), intermediate results initially do not include the final output tensors at all. |
Source code in src/bioimageio/core/_prediction_pipeline.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
predict_sample_without_blocking
¤
predict_sample_without_blocking(sample: Sample, skip_preprocessing: bool = False, skip_postprocessing: bool = False, skip_input_padding: bool = False, skip_output_cropping: bool = False) -> Sample
Predict a whole sample at once.
Note
The sample's tensor shapes have to match the model's input tensor description.
If that is not the case, consider predict_sample_with_blocking
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Sample
|
input sample |
required |
|
bool
|
if |
False
|
|
bool
|
if |
False
|
|
bool
|
if |
False
|
|
bool
|
if |
False
|
Source code in src/bioimageio/core/_prediction_pipeline.py
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 | |