Skip to content

commands ¤

These functions are used in the bioimageio command line interface defined in bioimageio.core.cli.

Functions:

Name Description
package

Save a resource's metadata with its associated files.

test

Test a bioimageio resource.

validate_format

DEPRECATED; Access the existing validation_summary attribute instead.

Attributes:

Name Type Description
WeightFormatArgAll
WeightFormatArgAny

WeightFormatArgAll module-attribute ¤

WeightFormatArgAll = Literal['keras_hdf5', 'onnx', 'pytorch_state_dict', 'tensorflow_saved_model_bundle', 'torchscript', 'all']

WeightFormatArgAny module-attribute ¤

WeightFormatArgAny = Literal['keras_hdf5', 'onnx', 'pytorch_state_dict', 'tensorflow_saved_model_bundle', 'torchscript', 'any']

package ¤

Save a resource's metadata with its associated files.

If path does not have a .zip suffix this command will save the

package as an unzipped folder instead.

Parameters:

Name Type Description Default

descr ¤

ResourceDescr

a bioimageio resource description

required

path ¤

Path

output path

required

weight_format ¤

WeightFormatArgAll

include only this single weight-format (if not 'all').

'all'
Source code in src/bioimageio/core/commands.py
 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def package(
    descr: ResourceDescr,
    path: Path,
    *,
    weight_format: WeightFormatArgAll = "all",
):
    """Save a resource's metadata with its associated files.

    Note: If `path` does not have a `.zip` suffix this command will save the
          package as an unzipped folder instead.

    Args:
        descr: a bioimageio resource description
        path: output path
        weight_format: include only this single weight-format (if not 'all').
    """
    if isinstance(descr, InvalidDescr):
        logged = descr.validation_summary.save()
        msg = f"Invalid {descr.type} description."
        if logged:
            msg += f" Details saved to {logged}."

        raise ValueError(msg)

    if weight_format == "all":
        weights_priority_order = None
    else:
        weights_priority_order = (weight_format,)

    if path.suffix == ".zip":
        _ = save_bioimageio_package(
            descr,
            output_path=path,
            weights_priority_order=weights_priority_order,
        )
    else:
        _ = save_bioimageio_package_as_folder(
            descr,
            output_path=path,
            weights_priority_order=weights_priority_order,
        )
    return 0

test ¤

test(descr: Union[ResourceDescr, InvalidDescr], *, weight_format: WeightFormatArgAll = 'all', devices: Optional[Union[str, Sequence[str]]] = None, summary: Union[Literal['display'], Path, Sequence[Union[Literal['display'], Path]]] = 'display', runtime_env: Union[Literal['currently-active', 'as-described'], Path] = 'currently-active', determinism: Literal['seed_only', 'full'] = 'seed_only', format_version: Union[FormatVersionPlaceholder, str] = 'discover', working_dir: Optional[Path] = None) -> int

Test a bioimageio resource.

Arguments as described in bioimageio.core.cli.TestCmd

Source code in src/bioimageio/core/commands.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def test(
    descr: Union[ResourceDescr, InvalidDescr],
    *,
    weight_format: WeightFormatArgAll = "all",
    devices: Optional[Union[str, Sequence[str]]] = None,
    summary: Union[
        Literal["display"], Path, Sequence[Union[Literal["display"], Path]]
    ] = "display",
    runtime_env: Union[
        Literal["currently-active", "as-described"], Path
    ] = "currently-active",
    determinism: Literal["seed_only", "full"] = "seed_only",
    format_version: Union[FormatVersionPlaceholder, str] = "discover",
    working_dir: Optional[Path] = None,
) -> int:
    """Test a bioimageio resource.

    Arguments as described in [bioimageio.core.cli.TestCmd][]
    """
    if isinstance(descr, InvalidDescr):
        test_summary = descr.validation_summary
    else:
        test_summary = test_description(
            descr,
            format_version=format_version,
            weight_format=None if weight_format == "all" else weight_format,
            devices=[devices] if isinstance(devices, str) else devices,
            runtime_env=runtime_env,
            determinism=determinism,
            working_dir=working_dir,
        )

    _ = test_summary.log(summary)
    return 0 if test_summary.status == "passed" else 1

validate_format ¤

validate_format(descr: Union[ResourceDescr, InvalidDescr], summary: Union[Path, Sequence[Path]] = ())

DEPRECATED; Access the existing validation_summary attribute instead. validate the meta data format of a bioimageio resource

Parameters:

Name Type Description Default

descr ¤

Union[ResourceDescr, InvalidDescr]

a bioimageio resource description

required
Source code in src/bioimageio/core/commands.py
78
79
80
81
82
83
84
85
86
87
88
89
def validate_format(
    descr: Union[ResourceDescr, InvalidDescr],
    summary: Union[Path, Sequence[Path]] = (),
):
    """DEPRECATED; Access the existing `validation_summary` attribute instead.
    validate the meta data format of a bioimageio resource

    Args:
        descr: a bioimageio resource description
    """
    _ = descr.validation_summary.save(summary)
    return 0 if descr.validation_summary.status in ("valid-format", "passed") else 1