Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DeepEdit infer to accept clicks from viewer #491

Merged
merged 11 commits into from
Aug 28, 2023
113 changes: 72 additions & 41 deletions models/spleen_deepedit_annotation/configs/inference.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"number_intensity_ch": 1,
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
"use_click": false,
"network_def": {
"_target_": "DynUNet",
"spatial_dims": 3,
Expand Down Expand Up @@ -60,49 +61,79 @@
"res_block": true
},
"network": "$@network_def.to(@device)",
"preprocessing_transforms": [
{
"_target_": "LoadImaged",
"keys": "image",
"reader": "ITKReader"
Nic-Ma marked this conversation as resolved.
Show resolved Hide resolved
},
{
"_target_": "EnsureChannelFirstd",
"keys": "image"
},
{
"_target_": "Orientationd",
"keys": "image",
"axcodes": "RAS"
},
{
"_target_": "ScaleIntensityRanged",
"keys": "image",
"a_min": -175,
"a_max": 250,
"b_min": 0.0,
"b_max": 1.0,
"clip": true
}
],
"auto_seg_transforms": [
{
"_target_": "Resized",
"keys": "image",
"spatial_size": "@spatial_size",
"mode": "area"
},
{
"_target_": "DiscardAddGuidanced",
"keys": "image",
"label_names": "@label_names",
"number_intensity_ch": "@number_intensity_ch"
}
],
"deepedit_transforms": [
{
"_target_": "AddGuidanceFromPointsDeepEditd",
"ref_image": "image",
"guidance": "guidance",
"label_names": "@label_names"
},
{
"_target_": "Resized",
"keys": "image",
"spatial_size": "@spatial_size",
"mode": "area"
},
{
"_target_": "ResizeGuidanceMultipleLabelDeepEditd",
"guidance": "guidance",
"ref_image": "image"
},
{
"_target_": "AddGuidanceSignalDeepEditd",
"keys": "image",
"guidance": "guidance",
"number_intensity_ch": "@number_intensity_ch"
}
],
"extra_transforms": [
{
"_target_": "EnsureTyped",
"keys": "image"
}
],
"preprocessing": {
"_target_": "Compose",
"transforms": [
{
"_target_": "LoadImaged",
"keys": "image",
"reader": "ITKReader"
},
{
"_target_": "EnsureChannelFirstd",
"keys": "image"
},
{
"_target_": "Orientationd",
"keys": "image",
"axcodes": "RAS"
},
{
"_target_": "ScaleIntensityRanged",
"keys": "image",
"a_min": -175,
"a_max": 250,
"b_min": 0.0,
"b_max": 1.0,
"clip": true
},
{
"_target_": "Resized",
"keys": "image",
"spatial_size": "@spatial_size",
"mode": "area"
},
{
"_target_": "DiscardAddGuidanced",
"keys": "image",
"label_names": "@label_names",
"number_intensity_ch": "@number_intensity_ch"
},
{
"_target_": "EnsureTyped",
"keys": "image"
}
]
"transforms": "$@preprocessing_transforms + (@deepedit_transforms if @use_click else @auto_seg_transforms) + @extra_transforms"
Nic-Ma marked this conversation as resolved.
Show resolved Hide resolved
},
"dataset": {
"_target_": "Dataset",
Expand Down
3 changes: 2 additions & 1 deletion models/spleen_deepedit_annotation/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
"version": "0.4.7",
"version": "0.4.8",
"changelog": {
"0.4.8": "Add infer transforms to manage clicks from viewer",
"0.4.7": "fix the wrong GPU index issue of multi-node",
"0.4.6": "update to use rc7 which solves dynunet issue",
"0.4.5": "remove error dollar symbol in readme",
Expand Down
20 changes: 20 additions & 0 deletions models/spleen_deepedit_annotation/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,30 @@ python -m monai.bundle run --config_file "['configs/train.json','configs/evaluat

#### Execute inference:


For automatic inference mode:


```
python -m monai.bundle run --config_file configs/inference.json
```

For interactive segmentation mode, in which the user provides clicks, set the **use_click** flag to true:


```
python -m monai.bundle run --config_file configs/inference.json --use_click true
```

Clicks should be added to the data dictionary that is passed to the preprocessing transforms. Label names are the keys and their values are the clicks coordinates.

Like the following format:

```
data_dict = {'background': [], 'spleen': [[I1, J1, K1], [I2, J2, K2]]}
yiheng-wang-nv marked this conversation as resolved.
Show resolved Hide resolved
```
where **[I1,J1,K1]** and **[I2,J2,K2]** are the point coordinates

#### Export checkpoint to TensorRT based models with fp32 or fp16 precision:

```bash
Expand Down