General How-To
Quick start: download annotations and convert to dataframe/csv
Access project
Example output
Download annotations and images
Download annotations only
Download model outputs
Download DICOM metadata
You can download the DICOM metadata in either json
or csv
format.
Annotations dataframe and csv
There is a method available to convert the downloaded annotations json file to a csv that can be read using pandas. Copy the downloaded file name from the output above or from your downloaded json file. If you get a json error, try downloading outside of your firewall.
Notebooks
Download and/or upload annotations
The linked notebook gives examples for using the mdai library to
- download annotations from your project
- turn the exported file into a Pandas dataframe
- and import data back into your project
- You'll need to supply the specifics for your project, but this should get you started: Get and/or upload annotations notebook
Create assignments and get user info using CLI
Get and create assignments notebook
Get user progress
User the Manager class to subclass the function 'get_done_exams' to specify conditions for exam completion
Images
Display images
Get DICOM pixel array
to_RGB
returns a 3D array, rescale
returns uint8 scaled to 255
Convert Mask annotation output to a binary mask
Function to load a single Mask instance from one row of annotation data. This will turn the data output for a Mask annotation into a binary mask sized to the corresponding image.
Get binary mask from shape annotations using library
This will output a tuple of all the masks for the image and a list of the label numbers corresponding to each mask layer. The label numbers are those you created with labels_dict
.
To see the masks applied to an image, use
Using the mask on the original image allows you to get segmented pixels for ROI and radiomic measurements.
Get binary mask without library
Function to load a single mask instance from one row of annotation data. This will turn one box, free form, polygon, etc into a binary mask sized to the corresponding image.
Get image with all annotations and masks
Display image and masks
Getting UIDs from your original files
Use this code on your original data to create dictionaries of the UIDs from the image filenames
Convert json file to dataframe
Obtain the json file either by the export tab in the Annotator tool or by using mdai_client.project(PROJECT_ID, annotations_only=True)
JSON is the path and name of the resulting json file. You can choose a dataset or it will default to all datasets
Simple
or
Optional choose datasets
Custom annotations dataset
- Create a project and dataset using the quickstart section
- Get annotation data
- Edit annotations and feed back into dataset data
- Initialize custom dataset with edited data
Split data into training and validation datasets
train_test_split(dataset, shuffle=True, validation_split=0.1)
DataGenerator
DataGenerator(dataset, batch_size=32, dim=(32, 32), n_channels=1, n_classes=10, shuffle=True, to_RGB=True, rescale=False)
Write to TFRecords
QA Python Examples
Get all user ids
Get all labels
Check for label conflicts in data
Results
Training models using library
Display label classes
Example output:
Working with Large Languge Models (LLMs)
GPT Chat Completion
Create Chat Completion
Create a new chat completion request with MD.ai client
Example Output:
Function Calling
Create a completion call by describing functions to GPT and have the model intelligently choose to output a JSON object containing arguments to call those functions. The Chat Completions API does not call the function; instead, the model generates JSON that you can use to call the function in your code.
Example Output: