Esempio n. 1
0
def test_dataset_rdf_round_trip():
    from bioimageio.spec import load_raw_resource_description, serialize_raw_resource_description_to_dict

    data = dict(
        id="platynereis_em_training_data",
        authors=[{
            "name": "Constantin Pape"
        }],
        cite=[{
            "doi": "https://doi.org/10.1016/j.cell.2021.07.017",
            "text": "Vergara, Pape, Meechan et al."
        }],
        covers=[
            "https://raw.githubusercontent.com/ilastik/bioimage-io-models/main/dataset_src/platy-cover0.png"
        ],
        description=
        "Training data for EM segmentation of cellular membranes, nuclei, cuticle and cilia in Platynereis.",
        documentation=
        "https://raw.githubusercontent.com/ilastik/bioimage-io-models/main/dataset_src/platy.md",
        format_version="0.2.2",
        license="CC-BY-4.0",
        name="Platynereis EM Traning Data",
        source="https://doi.org/10.5281/zenodo.3675220",
        tags=[
            "electron-microscopy", "platynereis", "cells", "cilia", "nuclei",
            "instance-segmentation", "3D"
        ],
        type="dataset",
    )
    raw = load_raw_resource_description(data)
    serialized = serialize_raw_resource_description_to_dict(raw)
    assert data == serialized
Esempio n. 2
0
def test_spec_round_trip(unet2d_nuclei_broad_any_minor):
    from bioimageio.spec import load_raw_resource_description, serialize_raw_resource_description_to_dict

    data = unet2d_nuclei_broad_any_minor
    # monkeypatch: yaml.load already converts timestamp to datetime.datetime, while we serialize it to ISO 8601
    if "timestamp" in data:
        data["timestamp"] = data["timestamp"].isoformat()

    raw_model = load_raw_resource_description(unet2d_nuclei_broad_any_minor)

    serialized = serialize_raw_resource_description_to_dict(raw_model)
    assert isinstance(serialized, dict)
    assert serialized == data

    raw_model_from_serialized = load_raw_resource_description(serialized)
    assert raw_model_from_serialized == raw_model
Esempio n. 3
0
def test_update_format(unet2d_nuclei_broad_before_latest, tmp_path):
    from bioimageio.spec.commands import update_format

    path = tmp_path / "rdf_new.yaml"
    update_format(unet2d_nuclei_broad_before_latest, path)

    assert path.exists()
    model = load_raw_resource_description(path)
    assert model.format_version == format_version
Esempio n. 4
0
def test_load_raw_model_unet2d_keras_tf(unet2d_keras_tf):
    from bioimageio.spec import load_raw_resource_description

    raw_model = load_raw_resource_description(unet2d_keras_tf,
                                              update_to_format="latest")
    assert isinstance(raw_model, raw_nodes.Model)
    # test attachments
    assert len(raw_model.attachments.files) == 1
    assert (raw_model.root_path / raw_model.attachments.files[0]).exists()
Esempio n. 5
0
def test_update_rdf_using_rd(unet2d_nuclei_broad_latest):
    from bioimageio.spec.commands import update_rdf

    source = load_raw_resource_description(unet2d_nuclei_broad_latest)
    update = dict(name="updated",
                  outputs=[{
                      "name": "updated",
                      "halo": ["KEEP", "DROP", 0, 9, 9]
                  }])
    actual = update_rdf(source, update)
    assert isinstance(actual, raw_nodes.Model)
    assert actual.name == "updated"
    assert actual.outputs[0].name == "updated"
    assert actual.outputs[0].halo == [0, 0, 9, 9]
Esempio n. 6
0
def test_spec_round_trip_w_attachments(unet2d_nuclei_broad_latest):
    from bioimageio.spec import load_raw_resource_description, serialize_raw_resource_description_to_dict

    data = unet2d_nuclei_broad_latest
    # monkeypatch: yaml.load already converts timestamp to datetime.datetime, while we serialize it to ISO 8601
    if "timestamp" in data:
        data["timestamp"] = data["timestamp"].isoformat()

    data["attachments"] = {
        "files": ["some_file.ext"],
        "another_unknown_attachment": ["sub", "whatever", {
            "weird": 10
        }]
    }

    raw_model = load_raw_resource_description(data)

    serialized = serialize_raw_resource_description_to_dict(raw_model)
    assert isinstance(serialized, dict)
    assert serialized == data

    raw_model_from_serialized = load_raw_resource_description(serialized)
    assert raw_model_from_serialized == raw_model
Esempio n. 7
0
def test_load_raw_model_to_format(unet2d_nuclei_broad_before_latest):
    from bioimageio.spec import load_raw_resource_description

    format_targets = [(0, 3), (0, 4)]
    format_version = tuple(
        map(int, unet2d_nuclei_broad_before_latest["format_version"].split(".")
            [:2]))

    for target in format_targets:
        if format_version <= target:
            to_format = ".".join(map(str, target))
            raw_model = load_raw_resource_description(
                unet2d_nuclei_broad_before_latest, update_to_format=to_format)
            assert raw_model.format_version[:raw_model.format_version.
                                            rfind(".")] == to_format
Esempio n. 8
0
def test_load_raw_model_stardist(stardist_model):
    from bioimageio.spec import load_raw_resource_description

    raw_model = load_raw_resource_description(stardist_model)
    assert raw_model
Esempio n. 9
0
def test_load_raw_model_hpa(hpa_model):
    from bioimageio.spec import load_raw_resource_description

    raw_model = load_raw_resource_description(hpa_model)
    assert raw_model
Esempio n. 10
0
def test_load_raw_model_multi_tensor(unet2d_multi_tensor):
    from bioimageio.spec import load_raw_resource_description

    raw_model = load_raw_resource_description(unet2d_multi_tensor)
    assert raw_model
Esempio n. 11
0
def test_load_raw_model(unet2d_nuclei_broad_any):
    from bioimageio.spec import load_raw_resource_description

    raw_model = load_raw_resource_description(unet2d_nuclei_broad_any)
    assert raw_model
Esempio n. 12
0
def test_load_raw_model_diff_output_shape(unet2d_diff_output_shape):
    from bioimageio.spec import load_raw_resource_description

    raw_model = load_raw_resource_description(unet2d_diff_output_shape)
    assert raw_model
Esempio n. 13
0
def test_loaded_remote_raw_model_is_valid(unet2d_nuclei_broad_url):
    from bioimageio.spec import load_raw_resource_description

    raw_model = load_raw_resource_description(unet2d_nuclei_broad_url)
    raw_model = load_raw_resource_description(raw_model)
    assert raw_model