1
+ """bioimageio CLI
2
+
3
+ Note: Some docstrings use a hair space ' '
4
+ to place the added '(default: ...)' on a new line.
5
+ """
6
+
1
7
import json
2
8
import shutil
3
9
import subprocess
22
28
)
23
29
24
30
from loguru import logger
25
- from pydantic import (
26
- BaseModel ,
27
- ConfigDict ,
28
- TypeAdapter ,
29
- model_validator ,
30
- )
31
+ from pydantic import BaseModel , model_validator
31
32
from pydantic_settings import (
32
33
BaseSettings ,
33
34
CliPositionalArg ,
@@ -89,7 +90,8 @@ class ArgMixin(BaseModel, use_attribute_docstrings=True):
89
90
90
91
class WithSource (ArgMixin ):
91
92
source : CliPositionalArg [str ]
92
- """Url/path to a bioimageio.yaml/rdf.yaml file or a bioimage.io resource identifier, e.g. 'affable-shark'"""
93
+ """Url/path to a bioimageio.yaml/rdf.yaml file
94
+ or a bioimage.io resource identifier, e.g. 'affable-shark'"""
93
95
94
96
@cached_property
95
97
def descr (self ):
@@ -223,8 +225,8 @@ class PredictCmd(CmdBase, WithSource):
223
225
--inputs="[[\" a_raw.tif\" ,\" a_mask.tif\" ],[\" b_raw.tif\" ,\" b_mask.tif\" ]]"
224
226
(Note that JSON double quotes need to be escaped.)
225
227
226
- Alternatively a `bioimageio-cli.yaml` (or `bioimageio-cli.json`) file may provide
227
- the arguments, e.g.:
228
+ Alternatively a `bioimageio-cli.yaml` (or `bioimageio-cli.json`) file
229
+ may provide the arguments, e.g.:
228
230
```yaml
229
231
inputs:
230
232
- [a_raw.tif, a_mask.tif]
@@ -235,6 +237,8 @@ class PredictCmd(CmdBase, WithSource):
235
237
Aavailable formats are listed at
236
238
https://imageio.readthedocs.io/en/stable/formats/index.html#all-formats.
237
239
Some formats have additional dependencies.
240
+
241
+
238
242
"""
239
243
240
244
outputs : Union [str , NotEmpty [Tuple [str , ...]]] = (
@@ -246,6 +250,8 @@ class PredictCmd(CmdBase, WithSource):
246
250
- '{model_id}' (from model description)
247
251
- '{output_id}' (from model description)
248
252
- '{sample_id}' (extracted from input paths)
253
+
254
+
249
255
"""
250
256
251
257
overwrite : bool = False
@@ -257,7 +263,8 @@ class PredictCmd(CmdBase, WithSource):
257
263
stats : Path = Path ("dataset_statistics.json" )
258
264
"""path to dataset statistics
259
265
(will be written if it does not exist,
260
- but the model requires statistical dataset measures)"""
266
+ but the model requires statistical dataset measures)
267
+ """
261
268
262
269
preview : bool = False
263
270
"""preview which files would be processed
@@ -274,6 +281,8 @@ class PredictCmd(CmdBase, WithSource):
274
281
3. writes input arguments to `{model_id}_example/bioimageio-cli.yaml`
275
282
4. executes a preview dry-run
276
283
5. executes prediction with example input
284
+
285
+
277
286
"""
278
287
279
288
def _example (self ):
@@ -305,7 +314,12 @@ def _example(self):
305
314
stats_file = "dataset_statistics.json"
306
315
stats = (example_path / stats_file ).as_posix ()
307
316
yaml .dump (
308
- dict (inputs = inputs , outputs = output_pattern , stats = stats_file ),
317
+ dict (
318
+ inputs = inputs ,
319
+ outputs = output_pattern ,
320
+ stats = stats_file ,
321
+ blockwise = self .blockwise ,
322
+ ),
309
323
bioimageio_cli_path ,
310
324
)
311
325
@@ -324,6 +338,7 @@ def get_example_command(preview: bool, escape: bool = False):
324
338
"predict" ,
325
339
f"--preview={ preview } " , # update once we use implicit flags, see `class Bioimageio` below
326
340
"--overwrite=True" ,
341
+ f"--blockwise={ self .blockwise } " ,
327
342
f"--stats={ q } { stats } { q } " ,
328
343
f"--inputs={ q } { inputs_escaped if escape else inputs_json } { q } " ,
329
344
f"--outputs={ q } { output_pattern } { q } " ,
@@ -346,7 +361,7 @@ def get_example_command(preview: bool, escape: bool = False):
346
361
logger .debug ("restored '{}'" , YAML_FILE )
347
362
348
363
print (
349
- "🎉 Sucessfully ran example prediction!"
364
+ "🎉 Sucessfully ran example prediction!\n "
350
365
+ "To predict the example input using the CLI example config file"
351
366
+ f" { example_path / YAML_FILE } , execute `bioimageio predict` from { example_path } :\n "
352
367
+ f"$ cd { str (example_path )} \n "
0 commit comments