-
Notifications
You must be signed in to change notification settings - Fork 218
Integration with Xant for data scientist using jupyter hub
Here we describe how data scientist can run training and inference on xnat data without any help from IT. This is achieved using xnat jupyter hub plugin. We will walk you through setting up:
- Xnat jupyter plugin and installing monai label gpu enabled image
- Running monai label with reverse proxy so xnat can call into it
- Container service to run inference on all data in a project
Xnat jupyter integration is very well documented here. You need to check the compatibility matrix then download the plugin into the xnat plugin folder. Your IT should follow the installation instructions as here. Once installed correctly xnat admin should be able to follow instructions here to set up the jupyter environments. Xnat instructions makes you test with the basic data scientist container. You should pull this image xnat/datascience-notebook and configure jupyter environment. Next you should test that you can launch jupyter instance form xnat and see the data folders
The above setup enables you to see your xnat data. However, you don’t have access to gpus or monai label. For this you need to pull image from aharouni334/xnat_monailabel_codeserver from docker hub
and setup the jupyter environment for it following steps here. This container has monai core 1.4, monai label 0.8.4 as well as vscode enabled. Once everything is setup correctly you can launch a jupyter lab instance using image above to get access to xnat data, monai label, and your gpu as shown below
You also have access to vscode in the browser so you can edit your files easily to write your monai label apps. Your admin would have need to configure the workspaces in the xnat jupyter plugin so you have persistent storage.
You should start monai label server by following steps in this integration with xnat wiki This would start monai label server on port 8000, However, this port is internal to the jupyter instance you are in. In order to expose this port we have installed a reverse proxy in the jupyter container. To check that monai label server is running try the url http://basurl/proxy/8000/info/ the base url should be something as http://your_xnat_ip/jupyterhub/user//<random_number_as_20250418T190212372Z>
In this step we need to add a new command for xnat using the container service which will run a curl command to monai label. This is similar to the setup we did in However, here we need to modify the curl command to use a token and use the reverse proxy.
Go to url http:///jupyterhub/hub/token.
You would need to login with the same xnat username/ password
click new token and copy it
Go to plugin settings --> image & commands then create new command. use json below to add the command
{
"name": "jupyter_monailabel_project",
"label": "jupyter_monailabel_project",
"description": "Curl to monai label to run infer for all series of a project",
"version": "1.0",
"schema-version": "1.0",
"image": "curlimages/curl:latest",
"type": "docker",
"command-line": "curl -H 'Authorization: Bearer [jh_token]' -X 'POST' [monailabel_host]/[jh_user]/[jh_lab_id]/proxy/[monailabel_port]'/xnat/infer/'[monailabel_model]'?scope=project&run_sync=true' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{\"image_ids\":[\"[PRJ_ID]/nosubject/noaccs/noscan/nosess\"] }' ",
"override-entrypoint": true,
"mounts": [],
"environment-variables": {
"monailabel_port": "8000",
"monailabel_host": "http://10.110.20.70/jupyterhub/user"
},
"ports": {},
"inputs": [
{
"name": "project_id",
"description": "The project id where the output DICOM should be stored to; if not provided the project id of the input series will be used.",
"type": "string",
"required": false,
"replacement-key": "[PRJ_ID]",
"command-line-flag": "",
"command-line-separator": "",
"select-values": []
},
{
"name": "monailabel_model",
"description": "model name to run",
"type": "string",
"required": true,
"replacement-key": "[monailabel_model]",
"command-line-flag": "",
"command-line-separator": "",
"select-values": []
},
{
"name": "jh_token",
"description": "Jupyter hub token",
"type": "string",
"required": true,
"replacement-key": "[jh_token]",
"command-line-flag": "",
"command-line-separator": "",
"select-values": []
},
{
"name": "jh_user",
"description": "Jupyter hub user name",
"type": "string",
"required": true,
"replacement-key": "[jh_user]",
"command-line-flag": "",
"command-line-separator": "",
"select-values": []
},
{
"name": "jh_lab_id",
"description": "Jupyter hub lab id ",
"type": "string",
"required": true,
"replacement-key": "[jh_lab_id]",
"command-line-flag": "",
"command-line-separator": "",
"select-values": []
}
],
"outputs": [],
"xnat": [
{
"name": "user_monailabel_project",
"description": "Jupyter Monai Label project",
"contexts": [
"xnat:projectData"
],
"external-inputs": [
{
"name": "project",
"description": "Input project",
"type": "Project",
"required": true,
"load-children": false
}
],
"derived-inputs": [
{
"name": "project-id",
"type": "string",
"required": true,
"provides-value-for-command-input": "project_id",
"user-settable": false,
"load-children": true,
"derived-from-wrapper-input": "project",
"derived-from-xnat-object-property": "label",
"multiple": false
}
],
"output-handlers": []
}
],
"reserve-memory": 1000,
"network": "dli-network",
"container-labels": {},
"generic-resources": {},
"ulimits": {},
"secrets": []
}
After creating the command you will need to enable it from the command configurations.
You would also need to enable it for your project by going to project settings as shown below.
Once you create the command and enabled it, you should see a new command appear for your project as shown below
Then you can should add information to run the command. you need your username, token you generated and the labID. labID is the numbers you can find in the jupyter lab url. if the url is http://xnat_ip/jupyterhub/user/admin/20250418T233921162Z/lab then you should use 20250418T233921162Z as your labID
- Refer to xnat integration wiki for monai label set up with xnat
- Refer to this wiki on how to setup an AI deployment workflow