.. _model-reference: Model Reference =============== All models are specified using JSON files. These specifications tell ABLInfer how to interface with the model, what parameters it expects, any pre/post-processing, as well as some helpful metadata for the user. The format of model specification files used by ABLInfer is based on the model specifications for DeepInfer, with the notable additions of the standardization of metadata fields and the addition of pre/post-processing blocks. Throughout the following examples, a line containing ``"..."`` indicates that part of the model specification has been omitted for clarity. Metadata (``/``) ---------------- .. list-table:: :widths: 10, 50 :header-rows: 1 * - Field - Description * - ``json_version`` - The version of the JSON model format that this model conforms to. * - ``type`` - The type of application to run. Currently, only ``"docker"`` is supported. * - ``id`` - The ID for the model. Must be a valid Python identifier. * - ``name`` - The name of the model, in a human-friendly format. * - ``organ`` - The organ that the model operates on, in a human-friendly format. * - ``task`` - The model's task, e.g. ``"Segmentation"``, ``"Registration"`` * - ``status`` - A user-friendly indication of the status of the model, e.g. ``"Testing"``, ``"Production"`` * - ``modality`` - The modality of images involved, e.g. ``"CT"`` * - ``version`` - The model's version. There is no format enforced here; comparison between versions is done using a Python string comparison * - ``description`` - [Optional] A detailed description of the model. * - ``website`` - [Optional] A website for where users can go for support/more information about the model. * - ``maintainers`` - [Optional] A list of the maintainers of the model, e.g. ``["Some Person (SomeOrg)", "Another Person (AnotherOrg)"]`` * - ``citation`` - [Optional] What users should cite if they use this model. An example of these fields is: .. code-block:: json { "json_version": "1.3", "type": "docker", "name": "Test Segmenter", "organ": "Third Hair from the Left", "task": "Segmentation", "status": "Production", "modality": "CT", "version": "1.0.1", "description": "This is where I would put a great deal of text explaining the function of the model, as it will be displayed when the user selects a model for use. Maybe some instructions or something.", "website": "elgoog.com", "maintainers": ["Ben Connors (UWO)"], "citation": "Paper currently nonexistant", "..." } Docker Parameters (``/docker``) ------------------------------- This section should only be present for ``type="docker"`` models. .. list-table:: :widths: 10, 50 :header-rows: 1 * - Field - Description * - ``image_name`` - The name of the Docker image to use, e.g. ``alpine``, ``nvidia/cuda`` * - ``image_tag`` - The image tag, or ``"latest"`` if there isn't one. * - ``data_path`` - The folder inside the container where the input/output should be written to/read from. This should be world-read/write-able. Use only forward slashes (``/``) in the path, not backward slashes. For most cases ``/tmp`` suffices. An example of these fields is: .. code-block:: json { "...", "docker": { "image_name": "testimage", "image_tag": "latest", "data_path": "/tmp" }, "..." } Input Parameters (``/inputs``) ------------------------------ This section defines the inputs for the models. Inputs are volumes, segmentations, and others that must be written to a file to be provided as input; parameters are those values which may be passed as command-line arguments. The actual ``/inputs`` field should be an object mapping Python-friendly (i.e. they work as a Python variable name) to the specification for that input. Note that the Python-friendly name of the input must be unique among the inputs, outputs, and parameters sections. The available fields on the input objects depend on the type of input; the fields common to all types are: .. list-table:: :widths: 10, 50 :header-rows: 1 * - Field - Description * - ``name`` - A user-friendly (but short) name for the input. * - ``description`` - A longer description of the input. * - ``status`` - One of ``"optional"`` (disabled by default but can be enabled), ``"suggested"`` (enabled by default but can be disabled), and ``"required"`` (always enabled). * - ``flag`` - The flag that will be used to provide the filename of the input to the model, including the leading dash(es). If the flag is ``""`` (the empty string), the filename is passed without a flag. If the flag ends with ``=``, then the filename is passed like ``--flag=thefilename``. * - ``extension`` - The extension to save the file as. This should be something that makes sense for the given type, e.g. ``".nii"`` or ``".nrrd"`` for volumes, and is NOT inferred from the input type. * - ``type`` - The type of input. Currently supported are ``"volume"`` and ``"segmentation"``. * - ``pre`` - [Optional] A list of pre-processing operations (explained later). An example is: .. code-block:: json { "...", "inputs": { "input1": { "name": "Volume Input", "description": "Please select the volume to segment.", "status": "required", "flag": "-i", "extension": ".nrrd", "type": "volume", "...", "pre": ["..."] }, "..." }, "..." } Volume Inputs (``type="volume"``) """"""""""""""""""""""""""""""""" .. list-table:: :widths: 10, 50 :header-rows: 1 * - Field - Description * - ``labelmap`` - Whether or not the volume is a labelmap. Only really meaningful for output volumes. An example is: .. code-block:: json { "...", "inputs": { "input1": { "name": "Volume Input", "description": "Please select the volume to segment.", "status": "required", "flag": "-i", "extension": ".nrrd", "type": "volume", "labelmap": true, "..." }, "..." }, "..." } Segmentation Inputs (``type="segmentation"``) """"""""""""""""""""""""""""""""""""""""""""" .. list-table:: :widths: 10, 50 :header-rows: 1 * - Field - Description * - ``labelmap`` - Whether or not the input is actually a labelmap but should be converted to a segmentation before use. Don't use circular references or Slicer may explode. Note that in most cases this should be set to false, as labelmaps can be loaded directly as segmentations. * - ``colours`` - [Optional] A mapping from label value (typically a string representation of a positive integer) to the desired colour, which is a 3- or 4-tuple of floats on [0,1] corresponding to the segmentation's red, green, blue, and, if desired, opacity (assumed to be 1 if omitted). Not all labels need be present; those labels that aren't added are left with the default colours of whatever software is used. * - ``names`` - [Optional] A mapping from label value (see ``colours``) to a string name for that component. * - ``master`` - [Optional] The name of the master volume for this segmentation (e.g. ``"input1"``, not the friendly name). Note that for Slicer, this field is mandatory for any segmentations requiring pre- or post-processing using the Segment Editor. An example is: .. code-block:: json { "...", "inputs": { "...", "input2": { "name": "Segmentation Input", "description": "Please select the initial segmentation.", "status": "required", "flag": "--seg=", "extension": ".nrrd", "type": "segmentation", "labelmap": true, "colours": { "2": [0.5, 0.2, 1, 0.5], "4": [1, 0, 0] }, "names": { "3": "The One We Really Care About" }, "master": "input1", "..." }, "..." }, "..." } Preprocessing (``/inputs/ --gpus=-1 --accuracy=1 -v -i /tmp/input_vol.nrrd -c RED --seg=/tmp/input_seg.nrrd output_seg.nii.gz Please use saner flags and ordering in your model.