Example #1
0
def export_to_bioimageio(checkpoint, output, input_, affs_to_bd,
                         additional_formats):

    root, ckpt_name = os.path.split(checkpoint)
    organelle = os.path.split(root)[0]
    assert organelle in ("cells", "mitochondria", "nuclei"), organelle

    if input_ is None:
        input_data = None
    else:
        input_data = _load_data(input_, organelle)

    is_aff_model = "affinity" in ckpt_name
    if is_aff_model and affs_to_bd:
        if organelle in ("cells", ):
            postprocessing = "affinities_to_boundaries_anisotropic"
        elif organelle in ("mitochondria", "nuclei"):
            postprocessing = "affinities_with_foreground_to_boundaries3d"
    else:
        postprocessing = None

    if is_aff_model and affs_to_bd:
        is_aff_model = False
    name, description = _get_name_and_description(is_aff_model, organelle)
    tags = [
        "unet", organelle, "instance-segmentation", "electron-microscopy",
        "platynereis"
    ]
    tags += ["boundary-prediction"
             ] if is_aff_model else ["affinity-prediction"]

    cite = get_default_citations(
        model="AnisotropicUNet",
        model_output="affinities" if is_aff_model else "boundaries")
    cite["data"] = "https://doi.org/10.1101/2020.02.26.961037"

    doc = _get_doc(checkpoint, name, organelle)

    if additional_formats is None:
        additional_formats = []

    export_bioimageio_model(
        checkpoint,
        output,
        input_data=input_data,
        name=name,
        description=description,
        authors=[{
            "name": "Constantin Pape; @constantinpape"
        }],
        tags=tags,
        license="CC-BY-4.0",
        documentation=doc,
        git_repo="https://github.com/constantinpape/torch-em.git",
        cite=cite,
        model_postprocessing=postprocessing,
        input_optional_parameters=False,
        for_deepimagej="torchscript" in additional_formats,
        links=[get_bioimageio_dataset_id("platynereis")])
    add_weight_formats(output, additional_formats)
def export_to_bioimageio(checkpoint, input_, output, affs_to_bd,
                         additional_formats):

    ckpt_name = os.path.split(checkpoint)[1]

    ndim = 3 if "3d" in ckpt_name else 2
    input_data = _load_data(input_, ndim)

    is_aff_model = "affinity" in ckpt_name
    if is_aff_model and affs_to_bd:
        postprocessing = f"affinities_to_boundaries{ndim}d"
    else:
        postprocessing = None
    if is_aff_model and affs_to_bd:
        is_aff_model = False

    if is_aff_model:
        offsets = [[-1, 0], [0, -1], [-3, 0], [0, -3], [-9, 0], [0, -9],
                   [-27, 0], [0, -27]]
        config = {"mws": {"offsets": offsets}}
    else:
        config = {}

    name = _get_name(is_aff_model, ndim)
    tags = [
        "unet", "neurons", "instance-segmentation", "electron-microscopy",
        "isbi2012-challenge"
    ]
    tags += ["boundary-prediction"
             ] if is_aff_model else ["affinity-prediction"]

    cite = get_default_citations(
        model="UNet2d" if ndim == 2 else "AnisotropicUNet",
        model_output="affinities" if is_aff_model else "boundaries")
    cite["data"] = "https://doi.org/10.3389/fnana.2015.00142"
    doc = _get_doc(is_aff_model, ndim)

    if additional_formats is None:
        additional_formats = []

    export_biomageio_model(
        checkpoint,
        output,
        input_data,
        name=name,
        authors=[{
            "name": "Constantin Pape; @constantinpape"
        }],
        tags=tags,
        license="CC-BY-4.0",
        documentation=doc,
        git_repo="https://github.com/constantinpape/torch-em.git",
        cite=cite,
        model_postprocessing=postprocessing,
        input_optional_parameters=False,
        for_deepimagej="torchscript" in additional_formats,
        links=[get_bioimageio_dataset_id("isbi2012")],
        config=config)
    add_weight_formats(output, additional_formats)
def export_to_bioimageio(checkpoint, output, input_, affs_to_bd,
                         additional_formats):

    ckpt_name = os.path.split(checkpoint)[1]

    if input_ is None:
        input_data = None
    else:
        input_data = _load_data(input_)

    is_aff_model = "affinity" in ckpt_name
    if is_aff_model and affs_to_bd:
        postprocessing = "affinities_to_boundaries_anisotropic"
    else:
        postprocessing = None

    if is_aff_model and affs_to_bd:
        is_aff_model = False
    name, description = _get_name_and_description(is_aff_model)
    tags = [
        "unet", "neurons", "instance-segmentation", "electron-microscopy",
        "cremi", "connectomics", "3d"
    ]
    tags += ["boundary-prediction"
             ] if is_aff_model else ["affinity-prediction"]

    # eventually we should refactor the citation logic
    cite = get_default_citations(
        model="AnisotropicUNet",
        model_output="affinities" if is_aff_model else "boundaries")
    cite["data"] = "https://cremi.org"

    doc = _get_doc(is_aff_model, checkpoint, name)
    if is_aff_model:
        offsets = [[-1, 0, 0], [0, -1, 0], [0, 0, -1], [-2, 0, 0], [0, -3, 0],
                   [0, 0, -3], [-3, 0, 0], [0, -9, 0], [0, 0, -9], [-4, 0, 0],
                   [0, -27, 0], [0, 0, -27]]
        config = {"mws": {"offsets": offsets}}
    else:
        config = {}

    if additional_formats is None:
        additional_formats = []

    export_bioimageio_model(
        checkpoint,
        output,
        input_data=input_data,
        name=name,
        description=description,
        authors=[{
            "name": "Constantin Pape; @constantinpape"
        }],
        tags=tags,
        license="CC-BY-4.0",
        documentation=doc,
        git_repo="https://github.com/constantinpape/torch-em.git",
        cite=cite,
        model_postprocessing=postprocessing,
        input_optional_parameters=False,
        for_deepimagej="torchscript" in additional_formats,
        links=[get_bioimageio_dataset_id("cremi")],
        config=config)
    if additional_formats:
        add_weight_formats(output, additional_formats)
def export_to_bioimageio(checkpoint, output, input_, affs_to_bd,
                         additional_formats):

    ckpt_name = os.path.split(checkpoint)[1]
    if input_ is None:
        input_data = None
    else:
        input_data = imageio.imread(input_)

    is_aff_model = "affinity" in ckpt_name
    if is_aff_model and affs_to_bd:
        postprocessing = "affinities_with_foreground_to_boundaries2d"
    else:
        postprocessing = None

    if is_aff_model and affs_to_bd:
        is_aff_model = False
    name, description = _get_name_and_description(is_aff_model)
    tags = [
        "fluorescence-light-microscopy", "nuclei", "unet",
        "instance-segmentation", "2d"
    ]

    # eventually we should refactor the citation logic
    cite = get_default_citations(
        model="UNet2d",
        model_output="affinities" if is_aff_model else "boundaries")
    cite["data"] = "https://www.nature.com/articles/s41592-019-0612-7"

    doc = _get_doc(is_aff_model, checkpoint, name)
    if is_aff_model:
        offsets = [[-1, 0], [0, -1], [-3, 0], [0, -3], [-9, 0], [0, -9],
                   [-27, 0], [0, -27]]
        config = {"mws": {"offsets": offsets}}
    else:
        config = {}

    if additional_formats is None:
        additional_formats = []

    export_bioimageio_model(
        checkpoint,
        output,
        input_data=input_data,
        name=name,
        authors=[{
            "name": "Constantin Pape",
            "affiliation": "EMBL Heidelberg"
        }],
        tags=tags,
        license="CC-BY-4.0",
        documentation=doc,
        git_repo="https://github.com/constantinpape/torch-em.git",
        cite=cite,
        model_postprocessing=postprocessing,
        input_optional_parameters=False,
        description=description,
        # need custom deepimagej fields if we have torchscript export
        for_deepimagej="torchscript" in additional_formats,
        links=[get_bioimageio_dataset_id("dsb")],
        config=config,
        maintainers=[{
            "github_user": "******"
        }],
    )
    add_weight_formats(output, additional_formats)
Example #5
0
def export_to_bioimageio(checkpoint, output, input_, affs_to_bd,
                         additional_formats):

    ckpt_name = os.path.split(checkpoint)[1]
    if input_ is None:
        input_data = None
    else:
        with h5py.File(input_, "r") as f:
            input_data = f["raw/serum_IgG/s0"][:512, :512]

    is_aff_model = "affinity" in ckpt_name
    if is_aff_model and affs_to_bd:
        postprocessing = "affinities_with_foreground_to_boundaries2d"
    else:
        postprocessing = None
    if is_aff_model and affs_to_bd:
        is_aff_model = False

    name, description = _get_name_and_description(is_aff_model)
    tags = [
        "unet", "cells", "high-content-microscopy", "instance-segmentation",
        "covid19", "immunofluorescence-microscopy", "2d"
    ]

    # eventually we should refactor the citation logic
    covid_if_pub = "https://doi.org/10.1002/bies.202000257"
    cite = get_default_citations(
        model="UNet2d",
        model_output="affinities" if is_aff_model else "boundaries")
    cite["data"] = covid_if_pub
    if not is_aff_model:
        cite["segmentation algorithm"] = covid_if_pub

    doc = _get_doc(is_aff_model, checkpoint, name)
    if is_aff_model:
        offsets = [[-1, 0], [0, -1], [-3, 0], [0, -3], [-9, 0], [0, -9],
                   [-27, 0], [0, -27]]
        config = {"mws": {"offsets": offsets}}
    else:
        config = {}

    if additional_formats is None:
        additional_formats = []

    export_bioimageio_model(
        checkpoint,
        output,
        input_data=input_data,
        name=name,
        authors=[{
            "name": "Constantin Pape",
            "affiliation": "EMBL Heidelberg"
        }],
        tags=tags,
        license="CC-BY-4.0",
        documentation=doc,
        description=description,
        git_repo="https://github.com/constantinpape/torch-em.git",
        cite=cite,
        config=config,
        model_postprocessing=postprocessing,
        input_optional_parameters=False,
        # need custom deepimagej fields if we have torchscript export
        for_deepimagej="torchscript" in additional_formats,
        links=[get_bioimageio_dataset_id("covid_if")],
        maintainers=[{
            "github_user": "******"
        }],
    )
    add_weight_formats(output, additional_formats)
def export_to_bioimageio(checkpoint, output, input_, affs_to_bd,
                         additional_formats):

    root, ckpt_name = os.path.split(checkpoint)
    specimen = os.path.split(root)[0]
    assert specimen in ("ovules", "roots"), specimen

    is2d = checkpoint.endswith('2d')
    ndim = 2 if is2d else 3
    if input_ is None:
        input_data = None
    else:
        input_data = _load_data(input_, is2d)

    is_aff_model = "affinity" in ckpt_name
    if is_aff_model and affs_to_bd:
        postprocessing = "affinities_to_boundaries3d"
    else:
        postprocessing = None

    if is_aff_model and affs_to_bd:
        is_aff_model = False
    name = _get_name(is_aff_model, specimen, ndim)
    tags = [
        "u-net", f"{specimen}-segmentation", "segmentation",
        "light-microscopy", "arabidopsis"
    ]
    if specimen == "ovules":
        tags += ["ovules", "confocal-microscopy"]
    else:
        tags += ["primordial-root", "light-sheet-microscopy"]
    tags += ["boundary-prediction"
             ] if is_aff_model else ["affinity-prediction"]

    # eventually we should refactor the citation logic
    plantseg_pub = "https://doi.org/10.7554/eLife.57613.sa2"
    cite = get_default_citations(
        model="UNet2d" if is2d else "UNet3d",
        model_output="affinities" if is_aff_model else "boundaries")
    cite["data"] = plantseg_pub
    cite["segmentation algorithm"] = plantseg_pub

    doc = _get_doc(is_aff_model, specimen, ndim)

    export_biomageio_model(
        checkpoint,
        output,
        input_data=input_data,
        name=name,
        authors=[{
            "name": "Constantin Pape; @constantinpape"
        }],
        tags=tags,
        license='CC-BY-4.0',
        documentation=doc,
        git_repo='https://github.com/constantinpape/torch-em.git',
        cite=cite,
        model_postprocessing=postprocessing,
        input_optional_parameters=False,
        # need custom deepimagej fields if we have torchscript export
        for_deepimagej="torchscript" in additional_formats,
        links=[get_bioimageio_dataset_id("ovules")])
    add_weight_formats(output, additional_formats)
Example #7
0
def export_to_bioimageio(checkpoint, input_, output, affs_to_bd,
                         additional_formats):

    root, ckpt_name = os.path.split(checkpoint)
    if input_ is None:
        input_data = None
    else:
        input_data = _load_data(input_)

    is_aff_model = "affinity" in ckpt_name
    if is_aff_model and affs_to_bd:
        postprocessing = "affinities_with_foreground_to_boundaries3d"
    else:
        postprocessing = None

    if is_aff_model and affs_to_bd:
        is_aff_model = False

    name, desc = _get_name_and_description(is_aff_model)
    if is_aff_model:
        offsets = [[-1, 0, 0], [0, -1, 0], [0, 0, -1], [-2, 0, 0], [0, -3, 0],
                   [0, 0, -3], [-3, 0, 0], [0, -9, 0], [0, 0, -9]]
        config = {"mws": {"offsets": offsets}}
    else:
        config = {}

    cite = get_default_citations(
        model="AnisotropicUNet",
        model_output="affinities" if is_aff_model else "boundaries")
    cite["data"] = "https://doi.org/10.1007/978-3-030-59722-1_7"
    tags = [
        "3d", "electron-microscopy", "mitochondria", "instance-segmentation",
        "unet"
    ]

    doc = _get_doc(is_aff_model, checkpoint, name)

    if additional_formats is None:
        additional_formats = []

    export_bioimageio_model(
        checkpoint,
        output,
        input_data=input_data,
        name=name,
        description=desc,
        authors=[{
            "name": "Constantin Pape; @constantinpape"
        }],
        tags=tags,
        license="CC-BY-4.0",
        documentation=doc,
        git_repo="https://github.com/constantinpape/torch-em.git",
        cite=cite,
        model_postprocessing=postprocessing,
        input_optional_parameters=False,
        for_deepimagej="torchscript" in additional_formats,
        links=[get_bioimageio_dataset_id("mitoem")],
        maintainers=[{
            "github_user": "******"
        }],
        config=config,
    )
    add_weight_formats(output, additional_formats)