MD.ai

Command Reference

Every mdai CLI command, with examples

Run mdai <command> --help for the options of any command. Before you start, configure your domain and access token.

Finding IDs: the annotator's Info panel shows the project ID and each dataset's ID. Get user IDs with project list-users, and model version IDs with model info.

Command overview

CommandPurpose
project infoShow project details
project list-datasetsList a project's datasets
project createCreate a project, optionally with a model
project setApply project settings from a YAML file
project deleteDelete an empty project
project add-userAdd a user to a project
project list-usersList project users
project list-user-assignmentsList user assignments
project update-user-assignmentAssign exams and label groups to a user
dataset infoShow dataset details
dataset createCreate a dataset
dataset cloneClone a dataset into another project
dataset loadUpload files to an upload dataset
dataset connectConnect a GCS or S3 bucket
dataset progressCheck processing progress
dataset deleteDelete a dataset
dataset remove-study, -series, -instanceRemove DICOM resources by UID
model infoShow model details, labels and versions
model createAdd a sample model to a project
model cloneClone models between projects
model setUpdate model settings
model deleteDelete a model
model create-taskRun inference on a dataset
model task-infoCheck an inference task
model clone-outputCopy a task's outputs into annotations
deid create-taskRun de-identification
deid task-infoCheck a de-identification task
deid export-tagsExport the default tag de-identification config

JSON output

Commands that return data accept -j, --json for machine-readable output. The response is wrapped in a { "data": ..., "error": ... } envelope: error is null on success, and data is null on failure.

$ mdai project list-datasets --project-id MwBeWjNr --json

{
  "data": [
    {
      "id": "D_NbrqAB",
      "name": "Head CT",
      "type": "DICOM",
      "source": "upload",
      "createdAt": "2018-10-07 19:11:39",
      "updatedAt": "2018-10-07 19:11:39",
      "processing": false
    }
  ],
  "error": null
}

--json is available on project info, list-datasets, list-users and list-user-assignments; dataset info, create, clone and progress; model info, create, clone, create-task and task-info; and deid create-task and task-info.

Commands exit with status 0 on success and 1 on failure, with or without --json. (Before v0.29.0, failed commands also exited with 0.) Set MDAI_DEBUG=1 to show the full cause of an error.

Projects

Project info

$ mdai project info --project-id MwBeWjNr

Project MwBeWjNr - Test Project
--------------------------------------------------
Private:      YES
Created:      2018-10-07 19:10:16
Updated:      2018-10-07 19:11:39
Description:

List datasets

$ mdai project list-datasets --project-id MwBeWjNr

Project MwBeWjNr - Test Project
--------------------------------------------------
Datasets:
ID         Name      Type    Source   Created               Updated               Processing
D_NbrqAB   Head CT   DICOM   upload   2018-10-07 19:11:39   2018-10-07 19:11:39

Processing shows running while the dataset is processing.

Create a project

Options:
  -n, --name <name>                project name (use quotes if contains spaces)
  -d, --description <description>  [optional] project description (use quotes if contains spaces)
  -m, --model <name>               [optional] sample model name
  -s, --setting <pathname>         [optional] project settings
  -h, --help                       Print help
$ mdai project create --name 'New Project' --description 'This is a _markdown_ formatted description.'

Successfully created project New Project [id: L4RJwoNP]

To start the project with a sample model, pass its name with --model. See available sample models.

$ mdai project create --name "Test Project" --model mdai:xray-classifier

Successfully created project Test Project [id: Y2qrE9Nv] and model mdai:xray-classifier [id: M_0N3ADm]

--setting takes a YAML file in the same format as project set.

Update project settings

Apply project settings from a YAML file. Only the settings in the file change: within a section such as label, settings you leave out keep their current values. Set a setting, or a whole section, to null to remove it. Lists such as hangingProtocols are replaced as a whole.

Usage: mdai project set [OPTIONS] <PATHNAME>

Arguments:
  <PATHNAME>  project settings YAML file

Options:
  -i, --project-id <id>  project id
  -h, --help             Print help

Sections include navigation, windowing, export, label, model, clone, hangingProtocols, dicom and slack. For example:

settings.yaml
windowing:
  windowCenter: 40
  windowWidth: 400
navigation:
  cacheMultiImageSeries: true
label:
  hideMetadataLabelGroup: true
  expandWriterRoleEditScope: false
  applySingleSublabel: false
export:
  disableExportImages: true
  disableExportDicomMetadata: false
  disableExportAnnotations: false
  disableExportModels: false
  disableExportModelOutputs: false
mdai project set settings.yaml --project-id MwBeWjNr

The command prints the settings it applied.

Delete a project

Deletes a project. All of its datasets must be deleted first. You confirm by typing the project name. In a script, pipe the name in: echo "My Project" | mdai project delete -i MwBeWjNr.

mdai project delete --project-id MwBeWjNr

Users and assignments

Add a user

Options:
  -i, --project-id <id>  project id
  -e, --email <email>    user email
  -r, --role <role>      role of project user [ READER, WRITER, QA, ADMIN ]
  -h, --help             Print help
$ mdai project add-user --project-id maBjAq5 --email user@email.com --role WRITER

Successfully added user U_eMzVMx with WRITER role.

See roles for what each role can do.

List users

$ mdai project list-users --project-id MwBeWjNr

ID           Name            Email             Role    Pending
-----------------------------------------------------------------
 U_y01508    Jane Doe        jane@md.ai        ADMIN    No

Pending is Yes for invited users who haven't signed in yet.

List assignments

Lists each user's label group restrictions and assigned exams (dicomStudyRestriction).

$ mdai project list-user-assignments --project-id MwBeWjNr

userId    name                labelGroupRestriction   dicomStudyRestriction
U_8dX2w8  femur@yopmail.com   G_WjoBx1,G_ADkazj       D_WmRdXB: 20-30,35,37
U_6vkyr8  ulna@yopmail.com    G_A1AXoD                None

With --json:

{
  "data": [
    {
      "userId": "U_8dX2w8",
      "name": "femur@yopmail.com",
      "labelGroupRestriction": ["G_WjoBx1", "G_ADkazj"],
      "dicomStudyRestriction": [
        { "dicomDatasetId": "D_WmRdXB", "dicomDatasetStudyNumbers": "20-30,35,37" }
      ]
    },
    {
      "userId": "U_6vkyr8",
      "name": "ulna@yopmail.com",
      "labelGroupRestriction": ["G_A1AXoD"],
      "dicomStudyRestriction": []
    }
  ],
  "error": null
}

Add or update assignments

Assigns exams and label groups to a user. The user must already be in the project.

Options:
  -i, --project-id <id>          project id
  -u, --user-id <id>             user id
  -d, --dataset-id <id>          [optional: use with --exams] dataset id
  -e, --exams <sequence>         [optional: use with --dataset-id] for specified dataset, assign
                                 exams such as 1-3,3-4 (use '' to reset)
  -g, --label-group <number(s)>  [optional] label group number, or multiple comma-separated numbers
                                 (use '' to reset)
  -h, --help                     Print help
$ mdai project update-user-assignment --project-id maBjAq5 --user-id U_oVjzV \
  --dataset-id D_v0B1N --exams '1-30,47,51-100' \
  --label-group '1,4'

Successfully updated project user assignment.
  • Exams are numbered per dataset, so --exams always needs --dataset-id. Run the command once per dataset.
  • --label-group takes label group numbers, not IDs.
  • Pass an empty string to clear part of an assignment:
mdai project update-user-assignment --project-id maBjAq5 --user-id U_oVjzV \
  --dataset-id D_v0B1N --exams '' --label-group ''

Assignments don't apply to project admins, who always see everything. To assign work to an admin, invite them with a second email address as a non-admin user.

Datasets

Dataset info

$ mdai dataset info --dataset-id D_NbrqAB

Dataset D_NbrqAB - Head CT
--------------------------------------------------
Type:          DICOM
Source:        upload
# Studies:     1
# Series:      1
# Images:      11
Created:       2018-10-07 19:11:39
Updated:       2018-10-07 19:14:50
Description:

While the dataset is processing, a Processing line shows the batch ID.

Create a dataset

Options:
  -i, --project-id <id>            project id
  -s, --source <source>            dataset source, one of: [ upload, dicom-push,
                                   google-cloud-storage, google-cloud-healthcare-api, amazon-s3,
                                   azure-blob-storage ]
  -n, --name <name>                dataset name (use quotes if contains spaces)
  -d, --description <description>  [optional] dataset description (use quotes if contains spaces)
  -j, --json                       [optional] output as JSON
  -h, --help                       Print help

Sources are upload, dicom-push, google-cloud-storage, google-cloud-healthcare-api, amazon-s3 and azure-blob-storage. Which ones you can use depends on your MD.ai domain. An invalid source fails with an error that lists the valid ones, and a source your domain doesn't allow fails with Dataset source '<source>' is not allowed within the configured domain.

$ mdai dataset create --project-id L4RJwoNP --source upload --name 'New Dataset'

Successfully created DICOM dataset New Dataset with upload source [id: D_GmxvgB]

Clone a dataset

Copies a dataset into another project. You must be an admin of both projects.

$ mdai dataset clone --dataset-id D_6BWvjY --project-id VpBQwNA6

Successfully cloned dataset Test_Dataset [id: D_6BWvjY] to Project Test_Project [id: VpBQwNA6]

Upload files

Uploads files and folders to a dataset with the upload source. Everything under the path is included, following symlinks. Requires the project admin role.

Usage: mdai dataset load [OPTIONS] <PATHNAME>

Arguments:
  <PATHNAME>  file or folder to upload (folders are uploaded recursively)

Options:
  -i, --dataset-id <id>            dataset id
  -o, --order-exams-by <ordering>  [optional] order exams by [ default, patient_id, study_date_time,
                                   study_desc, random ] [default: default]
  -h, --help                       Print help
$ mdai dataset load --dataset-id D_GmxvgB dicom_dir

Dataset D_GmxvgB - New Dataset
--------------------------------------------------
Preparing to upload dicom_dir ...
File count: 11
Total size: 5.52 MB

Uploading:
100% [==================================================] 11/11 [0.0s<0.0s, 478/s]
Completed. No errors.

Done uploading for batch id 1e6ddfed-a32f-4cd4-8113-c683b9122134.
Run `mdai dataset progress -i D_GmxvgB` to track progress.

See exam ordering for what --order-exams-by does.

Files that fail to upload after retries are listed in errors_<batch id>.log in the current directory. Press Ctrl-C to stop an upload: the CLI cancels the processing batch, so you can run dataset load again straight away.

Connect a bucket

Connects a Google Cloud Storage or Amazon S3 bucket to a dataset with the matching source. First grant MD.ai read access to the bucket, as described for Google Cloud Storage or Amazon S3. Azure containers can only be connected in the web app.

Options:
  -i, --dataset-id <id>            dataset id
  -b, --bucket <bucket>            bucket name
  -p, --prefix <prefix>            [optional] folder prefix
  -o, --order-exams-by <ordering>  [optional] order exams by [ default, patient_id, study_date_time,
                                   study_desc, random ] [default: default]
  -h, --help                       Print help
$ mdai dataset connect --dataset-id D_1j4M2B --bucket mdai-test-bucket --prefix test

Dataset D_1j4M2B - New Dataset 2
──────────────────────────────────────────────────
       Bucket: mdai-test-bucket
       Prefix: test
  Order Exams: default

Successfully connected bucket. Run `mdai dataset progress -i D_1j4M2B` to track progress.

Check processing progress

$ mdai dataset progress --dataset-id D_NbrqAB

Dataset D_NbrqAB - Head CT
--------------------------------------------------
Type: DICOM
Source: upload
Processing progress for batch id 1e6ddfed-a32f-4cd4-8113-c683b9122134

Status:                           FINISHED
Started:                          2018-10-07 19:13:36
Elapsed time:                     42 seconds
Percent complete:                 100%
Subtask - process uploaded files
  # Completed:                    11
  # Remaining:                    0
  # Errors:                       0
Subtask - generate series thumbnails
  # Completed:                    1
  # Remaining:                    0
  # Errors:                       0

While processing runs, Estimated time remaining is also shown.

Delete a dataset

Deletes a dataset with all of its annotations and model outputs. You confirm by typing the dataset name, or pipe it in from a script.

$ mdai dataset delete -i D_Zb5Eb4

Dataset D_Zb5Eb4 - VAL
This cannot be undone! Enter the dataset name VAL to comfirm deletion:
VAL

Start deleting dataset VAL

Done deleting dataset VAL

Remove exams, series or images

Removes DICOM resources from a dataset by UID, along with their annotations and model outputs. Separate multiple UIDs with commas and no spaces.

CommandOptionUIDs
dataset remove-study-U, --study-uids <uids>StudyInstanceUID
dataset remove-series-U, --series-uids <uids>SeriesInstanceUID
dataset remove-instance-U, --instance-uids <uids>SOPInstanceUID
$ mdai dataset remove-study -i D_vBnWb1 -U 1.2.276.0.7230010.3.1.2.8323329.15697.1531787477.263823,1.2.276.0.7230010.3.1.2.8323329.15695.1531787477.240488

Dataset D_vBnWb1 - TRAIN
Successfully deleted DICOM studies with StudyInstanceUID:
 1.2.276.0.7230010.3.1.2.8323329.15697.1531787477.263823
 1.2.276.0.7230010.3.1.2.8323329.15695.1531787477.240488

Models

Model info

$ mdai model info --model-id M_0N3ADm

Model M_0N3ADm - X-Ray Classifier
──────────────────────────────────────────────────
Description:   Classifies X-rays as chest or abdomen
Scope:         Image
Created:       2022-09-13 11:35:19
Updated:       2022-09-13 11:36:51
Privacy:       Private
AutoRun:       No
Exportable:    No
Cloneable:     No
──────────────────────────────────────────────────
Labels With Class Index
──────────────────────────────────────────────────────────────────
 class index  │ label id │ label name │ label type │ label scope
──────────────────────────────────────────────────────────────────
 0            │ L_QRb9NQ │ Abdomen    │ Global     │ Image
──────────────────────────────────────────────────────────────────
 1            │ L_gw3RNg │ Chest      │ Global     │ Image
──────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────
Versions
─────────────────────────────────────────────────────────────────────────────────────────────────────
 #  │ id  │ Docker Image:Tag                        │ Created             │ Build Status │ Hardware
─────────────────────────────────────────────────────────────────────────────────────────────────────
 1  │ 541 │ gcr.io/mdai-models/staging/model-198/v1 │ 2022-09-13 11:35:20 │ Success      │ CPU
─────────────────────────────────────────────────────────────────────────────────────────────────────

The version id is what model create-task takes.

Add a sample model

Adds a ready-made model, with its labels, to a project. List the available sample models with --list-models:

$ mdai model create --list-models

─────────────────────────────────────────────────────────────────────────
 name                    │ description
─────────────────────────────────────────────────────────────────────────
 mdai:xray-classifier    │ Classifies X-rays as chest or abdomen
─────────────────────────────────────────────────────────────────────────
 mdai:lung-segmentation  │ Generates segmentation for lungs in xray images
─────────────────────────────────────────────────────────────────────────
 mdai:pixel-deid         │ Pixel level De-identification
─────────────────────────────────────────────────────────────────────────

The list comes from your MD.ai domain and may differ from this example.

$ mdai model create --project-id Y2qrE9Nv --model-name mdai:xray-classifier

Successfully created model mdai:xray-classifier [id: M_0N3ADm] in project [id: Y2qrE9Nv]

Clone models

Clones models, with their labels, from one project into one or more others, optionally from another MD.ai domain. You must be an admin of each target project.

Options:
      --from-project-id <id>  original project id
      --to-project-ids <ids>  target project ids, separated by commas
      --from-model-ids <ids>  [optional] original model ids in original project, separated by commas
      --from-domain <domain>  [optional] original project MD.ai domain (e.g., public.md.ai)
  -c, --config-file <path>    [optional] clone config file (.json or .yaml)
  -j, --json                  [optional] output as JSON
  -h, --help                  Print help
$ mdai model clone --from-project-id MmRa7Mqr --to-project-ids 0pqXObNZ

Clone result of project 0pqXObNZ: Cloned 3 model into project
Clone models complete!

Leave out --from-model-ids to clone every model in the project. Instead of the options, you can pass a config file:

clone.yaml
fromDomain: public.md.ai
fromProjectId: MmRa7Mqr
fromModelIds:
  - M_0N3ADm
toProjectIds:
  - 0pqXObNZ

Update a model

Changes a model's name, description or settings.

Options:
  -i, --model-id <id>
          model id
  -n, --model-name <name>
          [optional] model name (use quotes if contains spaces)
  -d, --model-description <description>
          [optional] model description (use quotes if contains spaces)
  -p, --model-privacy <privacy>
          [optional] configure model privacy (private or public)
  -a, --model-autorun-inference [<autorun>]
          [optional] configure model autorun (y/n, yes or no)
  -e, --model-exportable [<exportable>]
          [optional] configure model exportable (y/n, yes or no)
  -c, --model-cloneable [<cloneable>]
          [optional] configure model cloneable (y/n, yes or no)
  -s, --model-clone-scope <scope>
          [optional] model clone scope (SITE_ONLY or ALL_DOMAINS)
  -h, --help
          Print help
$ mdai model set --model-id M_7bxME5 --model-autorun-inference yes

Successfully set model [id: M_7bxME5] autorun inference to be yes.

Delete a model

$ mdai model delete --model-id M_BkQJWl

Successfully deleted model test [id: M_BkQJWl]

Run inference

Runs a model version on a whole dataset. Requires the QA or Admin role. Get the version ID from model info.

$ mdai model create-task --model-version-id 13 --dataset-id D_vbvwom

Successfully created model inference task [Task ID: 190] on dataset Finetuning [Dataset ID: D_vbvwom]

Check a model task

mdai model task-info --model-task-id 190

Shows the task's type, status, progress, and when it was created, started and ended.

Clone model outputs as annotations

Copies every output of a model task into annotations, so you can review and edit them.

$ mdai model clone-output --model-task-id 189

Successfully cloned 700 model outputs to annotations.

De-identification

Create a De-ID task

Starts a de-identification task on an upload or dicom-push dataset. Requires the project admin role. The result is a new, de-identified dataset; the original is not changed. The task also appears in the annotator's De-ID panel.

Options:
  -i, --dataset-id <id>
          dataset id
  -a, --auto-inference [<value>]
          [optional] Apply automatic inference (y/n, yes or no)
  -m, --auto-inference-model <name>
          [optional] Automatic inference model name (defaults to "mdai:pixel-deid")
  -l, --label-ids <ids>
          [optional] label ids, separated by commas (no spaces)
  -r, --remove-private-tags [<value>]
          [optional] Remove private tags (y/n, yes or no)
  -c, --tags-config <path or "default">
          [optional] path to DICOM tags modification JSON config file (load default if "default")
  -j, --json
          [optional] output as JSON
  -h, --help
          Print help

Run the whole pixel de-identification workflow in one step: add the De-ID model to the project, run it, and redact everything it detects:

$ mdai deid create-task -i D_emLA9j -a yes

Successfully created De-ID task [id: 126] for dataset [id: D_emLA9j]

Redact only the annotations of specific labels (for example, reviewed model outputs you cloned as annotations):

mdai deid create-task -i D_emLA9j -l L_EM2rPN,L_ZgDraE

De-identify DICOM tags with the default config:

mdai deid create-task -i D_emLA9j -c default

De-identify DICOM tags with your own config:

mdai deid export-tags                                       # writes mdai_deid_tags_config.json
# edit mdai_deid_tags_config.json
mdai deid create-task -i D_emLA9j -c mdai_deid_tags_config.json

Check a De-ID task

$ mdai deid task-info -i 125

DEID Task 125
──────────────────────────────────────────────────
Type:           DEID
Status:         SUCCEEDED
Progress:       100
Created at:     2024-01-02 16:30:25
Start Time:     2024-01-02 16:30:29
End Time:       2024-01-02 16:40:19
Success Count:  3
Error Count:
New Dataset ID: D_LNqELN

Export the default tag config

Writes the default DICOM tag de-identification config to mdai_deid_tags_config.json, in the current directory by default.

$ mdai deid export-tags

Exported DICOM tags modification default config file to mdai_deid_tags_config.json

To write the file to another directory, add -d, --export-dir <path>. This option requires CLI v0.28.1 or later; earlier versions always write to the current directory.

On this page