MD.ai

Export Formats

Structure of exported DICOM metadata, annotations, model outputs and models

This page describes the files produced by Export Data. To work with them in Python, see the Python client.

Conventions used in every export:

  • IDs are strings with a prefix: G_ label group, L_ label, D_ dataset, A_ annotation, O_ model output, M_ model, U_ user. Model version and task IDs are numbers.
  • Dates are ISO 8601 strings in UTC.
  • Exams are DICOM studies, so they use StudyInstanceUID. Each exam's number is its exam number in the dataset.
  • UID keys that don't apply are left out rather than set to null. For example, an exam-scoped annotation has no SeriesInstanceUID or SOPInstanceUID.
  • A multi-frame DICOM instance is one image. Items on one of its frames carry a 0-based frameNumber.
  • Export files are named like mdai_<domain>_project_<projectId>_<type>_..._<timestamp>, with the dataset, label group or model ID included when you export only one. A [zip] format wraps the single JSON or CSV file in a zip archive.

DICOM metadata

JSON

{
  "id": "String", // project id
  "createdAt": "Date",
  "updatedAt": "Date",
  "name": "String",
  "description": "String",
  "isPrivate": "Boolean",
  "datasets": [
    {
      "id": "String", // starts with `D_`
      "type": "String", // DICOM
      "createdAt": "Date",
      "updatedAt": "Date",
      "name": "String",
      "description": "String",
      "studies": [
        {
          "StudyInstanceUID": "String",
          "number": "Number" // exam number in the dataset
        }
      ],
      "dicomMetadata": [
        {
          "StudyInstanceUID": "String",
          "SeriesInstanceUID": "String",
          "SOPInstanceUID": "String",
          "dicomTags": "Object" // DICOM keyword to value, e.g. {"Modality": "CT"}
        }
      ],
      "videoMetadata": [
        // only for datasets with videos
        {
          "StudyInstanceUID": "String",
          "SeriesInstanceUID": "String",
          "origFileName": "String", // name of the uploaded video
          "fileExtension": "String" // extension of the uploaded video, or .mp4 if the frame rate was changed
        }
      ]
    }
  ]
}

A multi-frame instance has a single dicomMetadata entry. Tag values are strings, numbers or arrays, depending on the tag.

CSV

One row per image, plus one row per video. The columns are datasetId, then every keyword in the DICOM dictionary in alphabetical order, then videoOrigFileName and videoFileExtension. Tags an image doesn't have are left empty.

Annotations

{
  "id": "String", // project id
  "createdAt": "Date",
  "updatedAt": "Date",
  "name": "String",
  "description": "String",
  "isPrivate": "Boolean",
  "labelGroups": [
    {
      "id": "String", // starts with `G_`
      "createdAt": "Date",
      "updatedAt": "Date",
      "name": "String",
      "description": "String",
      "type": "String", // STANDARD or METADATA
      "labels": [
        {
          "id": "String", // starts with `L_`
          "parentId": "String", // parent label, for sublabels
          "createdAt": "Date",
          "updatedAt": "Date",
          "name": "String",
          "shortName": "String",
          "description": "String",
          "color": "String", // hex color
          "type": "String", // GLOBAL or LOCAL
          "scope": "String", // STUDY, SERIES or INSTANCE
          "annotationMode": "String", // bbox, polygon, freeform, line, location, mask or ellipse; null for GLOBAL
          "radlexTagIds": ["String"],
          "valueConfig": { "integer": "Boolean", "min": "Number", "max": "Number" } // null if the label doesn't record a number
        }
      ]
    }
  ],
  "datasets": [
    {
      "id": "String", // starts with `D_`
      "type": "String", // DICOM
      "createdAt": "Date",
      "updatedAt": "Date",
      "name": "String",
      "description": "String",
      "studies": [
        {
          "StudyInstanceUID": "String",
          "number": "Number"
        }
      ],
      "ophthalmicGrids": [
        // ETDRS grids, one per reader per fundus image
        {
          "centerX": "Number", // foveal center, in fundus image pixels
          "centerY": "Number",
          "rotation": "Number", // radians, counter-clockwise; 0 for the standard orientation
          "ringDiametersMm": ["Number"], // e.g. [1, 3, 6]
          "laterality": "String", // R or L, from DICOM ImageLaterality
          "mmPerPixelX": "Number", // millimeter scale of the fundus image
          "mmPerPixelY": "Number",
          "calibrationSource": "String", // FRAME_LOCATION, PIXEL_SPACING or MANUAL
          "createdAt": "Date",
          "createdById": "String",
          "updatedAt": "Date",
          "updatedById": "String",
          "StudyInstanceUID": "String", // the fundus image
          "SeriesInstanceUID": "String",
          "SOPInstanceUID": "String",
          "frameNumber": "Number" // multi-frame fundus images only
        }
      ],
      "annotations": [
        {
          "id": "String", // starts with `A_`
          "parentId": "String", // parent annotation, for sublabel annotations
          "isImported": "Boolean",
          "isInterpolated": "Boolean",
          "clonedFromModelOutputId": "String", // starts with `O_`, if cloned from a model output
          "createdAt": "Date",
          "createdById": "String",
          "updatedAt": "Date",
          "updatedById": "String",
          "updateHistory": [{ "updatedAt": "Date", "updatedById": "String" }],
          "StudyInstanceUID": "String",
          "SeriesInstanceUID": "String",
          "SOPInstanceUID": "String",
          "frameNumber": "Number", // 0-based frame, for multi-frame images and videos
          "timestamp": "Number", // videos only: time of the frame, in milliseconds
          "labelId": "String", // starts with `L_`
          "annotationNumber": "Number", // numbers multiple annotations of a LOCAL label on an image; otherwise null
          "height": "Number", // image height, for LOCAL annotations drawn in MD.ai; otherwise null
          "width": "Number", // image width, for LOCAL annotations drawn in MD.ai; otherwise null
          "data": "Object", // see below
          "note": "String",
          "value": "Number", // number recorded with the annotation; null if none
          "radlexTagIds": ["String"],
          "reviews": [
            {
              "userId": "String",
              "review": "String", // POSITIVE or NEGATIVE
              "createdAt": "Date",
              "updatedAt": "Date"
            }
          ],
          "reviewsPositiveCount": "Number",
          "reviewsNegativeCount": "Number",
          "groupId": "String" // shared by annotations that belong together, e.g. the frames of an interval on a video
        }
      ]
    }
  ]
}

The export leaves out the Metadata label group unless a project admin exports it explicitly. ETDRS grids are included whatever label group you export. Grids are not restored when annotations are imported into another project.

Annotation data

data depends on the label's annotationMode. Coordinates are in image pixels, with [0, 0] at the top-left corner, x increasing to the right and y increasing downward. Coordinates may be fractional; round them if you need whole pixels.

annotationModedata
bbox{ "x", "y", "width", "height" }, where x, y is the top-left corner
polygon, freeform, line{ "vertices": [[x, y], ...] }. Vertices lie in the middle of the drawn outline.
location{ "x", "y" }
mask{ "foreground": [[[x, y], ...], ...], "background": [[[x, y], ...], ...] }: polygons of the masked area, and of holes in it
ellipse{ "cx", "cy", "rx", "ry", "rotation" }: center, radii and rotation in degrees

To turn a mask into a pixel array, fill the foreground polygons, then clear the background polygons:

import cv2
import numpy as np

# height and width are null for annotations cloned from model outputs. Then use the image's
# Rows and Columns tags, e.g. from the DICOM metadata export.
mask = np.zeros((annotation["height"] or rows, annotation["width"] or columns), dtype=np.uint8)
for polygon in annotation["data"]["foreground"]:
    cv2.fillPoly(mask, [np.array(polygon, dtype=np.int32)], 1)
for polygon in annotation["data"]["background"]:
    cv2.fillPoly(mask, [np.array(polygon, dtype=np.int32)], 0)

To go the other way when importing masks, mdai.common_utils.convert_mask_data(array) converts a pixel array into this format.

For GLOBAL labels, data is null, except for SERIES scope labels on videos narrowed to part of the clip. These carry { "startFrameNumber", "endFrameNumber" }, both 0-based and inclusive. Without them, the annotation applies to the whole video.

Recorded values

value is the number a reader recorded for a label set to record a number. It's null when the label doesn't record one, or none was entered.

The label's valueConfig gives the rules: integer (whole numbers only), and an inclusive min and max, each null when unbounded. Rules are checked when a value is entered, so values recorded before a range was narrowed can fall outside it.

Model outputs

{
  "id": "String", // project id
  "createdAt": "Date",
  "updatedAt": "Date",
  "name": "String",
  "description": "String",
  "isPrivate": "Boolean",
  "labelGroups": [
    // the label groups and labels the exported models output, without valueConfig
  ],
  "models": [
    {
      "id": "String", // starts with `M_`
      "createdAt": "Date",
      "createdById": "String",
      "updatedAt": "Date",
      "name": "String",
      "description": "String",
      "scope": "String", // input scope: STUDY, SERIES or INSTANCE
      "labelClasses": [
        {
          "classIndex": "Number", // class index output by the model
          "labelId": "String" // MD.ai label for that class
        }
      ],
      "versions": [
        {
          "id": "Number",
          "isDefault": "Boolean",
          "versionNumber": "Number",
          "createdAt": "Date",
          "dockerImageName": "String",
          "dockerImageTag": "String",
          "config": "Object", // runtime config, e.g. cpuLimit, memoryLimit, acceleratorType, batchSize, fileType
          "args": [{ "key": "String", "default": "String" }]
        }
      ],
      "tasks": [
        {
          "id": "Number",
          "modelVersionId": "Number",
          "type": "String", // INFERENCE or TRAINING
          "config": {
            "resourceIds": ["Number"],
            "resourceType": "String", // DATASET, STUDY, SERIES or INSTANCE
            "dicomDatasetId": "Number"
          },
          "args": [{ "key": "String", "value": "String" }],
          "createdAt": "Date",
          "status": "String", // QUEUED, PROVISIONING_RESOURCES, PREPARING_INPUTS, RUNNING, SUCCEEDED, FAILED or MODEL_OUTDATED
          "startTime": "Date",
          "endTime": "Date",
          "progress": "Number", // 0-100
          "summary": {
            "errorCount": "Number",
            "successCount": "Number"
          }
        }
      ]
    }
  ],
  "datasets": [
    {
      "id": "String",
      "type": "String",
      "createdAt": "Date",
      "updatedAt": "Date",
      "name": "String",
      "description": "String",
      "studies": [{ "StudyInstanceUID": "String", "number": "Number" }],
      "modelOutputs": [
        {
          "id": "String", // starts with `O_`
          "modelId": "Number", // internal model number, not the `M_` id
          "modelVersionId": "Number", // matches versions[].id
          "modelTaskId": "Number", // matches tasks[].id
          "type": "String", // ANNOTATION, DICOM, IMAGE, TEXT or NONE
          "createdAt": "Date",
          "labelId": "String",
          "data": "Object", // as returned by the model; see below
          "probability": [{ "labelId": "String", "probability": "Number" }], // or null
          "note": "Object", // note returned by the model, or null
          "StudyInstanceUID": "String",
          "SeriesInstanceUID": "String",
          "SOPInstanceUID": "String",
          "frameNumber": "Number"
        }
      ]
    }
  ]
}

Output data has the shape the model returned for the label's annotation mode. See model outputs.

modelId on an output is an internal number, not the M_ model ID. To find an output's model, match its modelTaskId to a task, then find the model that task belongs to.

Models

A model export is a zip archive:

model/
  model.json     # model definition
  source/        # only if a selected version has uploaded code
    v1.zip       # code uploaded for version 1, named v<versionNumber> plus the original file's last extension
    v2.gz        # e.g. uploaded as .tar.gz

Only the versions you selected are included.

model.json:

{
  "model": {
    "id": "String",
    "name": "String",
    "description": "String",
    "scope": "String",
    "autoRunInference": "Boolean",
    "labelClasses": [{ "classIndex": "Number", "labelId": "String" }],
    "versions": [
      {
        "id": "Number",
        "versionNumber": "Number",
        "dockerImageName": "String",
        "dockerImageTag": "String",
        "config": "Object", // runtime config
        "isDefault": "Boolean",
        "args": [{ "key": "String", "default": "String" }],
        "status": "String",
        "source": "String" // file name in `source/`, e.g. v1.zip; null if no code was uploaded
      }
    ]
  },
  "labels": [
    {
      "id": "String",
      "parentId": "String",
      "name": "String",
      "shortName": "String",
      "description": "String",
      "color": "String",
      "type": "String",
      "scope": "String",
      "annotationMode": "String",
      "radlexTagIds": ["String"]
    }
  ]
}

On this page