Skip to content

Commit 85b8cf2

Browse files
diazandr3spre-commit-ci[bot]yiheng-wang-nv
authored
Update DeepEdit infer to accept clicks from viewer (Project-MONAI#491)
Update DeepEdit Infer config to accept clicks from the user --------- Signed-off-by: Andres <[email protected]> Signed-off-by: Yiheng Wang <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Yiheng Wang <[email protected]>
1 parent 7117a85 commit 85b8cf2

File tree

6 files changed

+114
-44
lines changed

6 files changed

+114
-44
lines changed

.github/workflows/premerge-cpu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ jobs:
4040
run: |
4141
# clean up temporary files
4242
$(pwd)/runtests.sh --clean
43+
df -h
4344
bash $(pwd)/ci/run_premerge_cpu.sh changed
4445
shell: bash

ci/run_premerge_cpu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ remove_pipenv() {
4343

4444
verify_bundle() {
4545
echo 'Run verify bundle...'
46-
init_pipenv requirements-dev.txt
46+
init_pipenv requirements.txt
4747
head_ref=$(git rev-parse HEAD)
4848
git fetch origin dev $head_ref
4949
# achieve all changed files in 'models'

ci/unit_tests/test_spleen_deepedit_annotation.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ def test_infer_config(self, override):
120120
)
121121
check_workflow(inferrer, check_properties=True)
122122

123+
@parameterized.expand([TEST_CASE_2])
124+
def test_infer_click_config(self, override):
125+
override["dataset_dir"] = self.dataset_dir
126+
override["use_click"] = True
127+
override[
128+
"dataset#data"
129+
] = "$[{'image': i, 'background': [], 'spleen': [[6, 6, 6], [8, 8, 8]]} for i in @datalist]"
130+
bundle_root = override["bundle_root"]
131+
print(override)
132+
133+
inferrer = ConfigWorkflow(
134+
workflow="infer",
135+
config_file=os.path.join(bundle_root, "configs/inference.json"),
136+
logging_file=os.path.join(bundle_root, "configs/logging.conf"),
137+
meta_file=os.path.join(bundle_root, "configs/metadata.json"),
138+
**override,
139+
)
140+
check_workflow(inferrer, check_properties=True)
141+
123142

124143
if __name__ == "__main__":
125144
loader = unittest.TestLoader()

models/spleen_deepedit_annotation/configs/inference.json

Lines changed: 72 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
],
2020
"number_intensity_ch": 1,
2121
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
22+
"use_click": false,
2223
"network_def": {
2324
"_target_": "DynUNet",
2425
"spatial_dims": 3,
@@ -60,49 +61,79 @@
6061
"res_block": true
6162
},
6263
"network": "$@network_def.to(@device)",
64+
"preprocessing_transforms": [
65+
{
66+
"_target_": "LoadImaged",
67+
"keys": "image",
68+
"reader": "ITKReader"
69+
},
70+
{
71+
"_target_": "EnsureChannelFirstd",
72+
"keys": "image"
73+
},
74+
{
75+
"_target_": "Orientationd",
76+
"keys": "image",
77+
"axcodes": "RAS"
78+
},
79+
{
80+
"_target_": "ScaleIntensityRanged",
81+
"keys": "image",
82+
"a_min": -175,
83+
"a_max": 250,
84+
"b_min": 0.0,
85+
"b_max": 1.0,
86+
"clip": true
87+
}
88+
],
89+
"auto_seg_transforms": [
90+
{
91+
"_target_": "Resized",
92+
"keys": "image",
93+
"spatial_size": "@spatial_size",
94+
"mode": "area"
95+
},
96+
{
97+
"_target_": "DiscardAddGuidanced",
98+
"keys": "image",
99+
"label_names": "@label_names",
100+
"number_intensity_ch": "@number_intensity_ch"
101+
}
102+
],
103+
"deepedit_transforms": [
104+
{
105+
"_target_": "AddGuidanceFromPointsDeepEditd",
106+
"ref_image": "image",
107+
"guidance": "guidance",
108+
"label_names": "@label_names"
109+
},
110+
{
111+
"_target_": "Resized",
112+
"keys": "image",
113+
"spatial_size": "@spatial_size",
114+
"mode": "area"
115+
},
116+
{
117+
"_target_": "ResizeGuidanceMultipleLabelDeepEditd",
118+
"guidance": "guidance",
119+
"ref_image": "image"
120+
},
121+
{
122+
"_target_": "AddGuidanceSignalDeepEditd",
123+
"keys": "image",
124+
"guidance": "guidance",
125+
"number_intensity_ch": "@number_intensity_ch"
126+
}
127+
],
128+
"extra_transforms": [
129+
{
130+
"_target_": "EnsureTyped",
131+
"keys": "image"
132+
}
133+
],
63134
"preprocessing": {
64135
"_target_": "Compose",
65-
"transforms": [
66-
{
67-
"_target_": "LoadImaged",
68-
"keys": "image",
69-
"reader": "ITKReader"
70-
},
71-
{
72-
"_target_": "EnsureChannelFirstd",
73-
"keys": "image"
74-
},
75-
{
76-
"_target_": "Orientationd",
77-
"keys": "image",
78-
"axcodes": "RAS"
79-
},
80-
{
81-
"_target_": "ScaleIntensityRanged",
82-
"keys": "image",
83-
"a_min": -175,
84-
"a_max": 250,
85-
"b_min": 0.0,
86-
"b_max": 1.0,
87-
"clip": true
88-
},
89-
{
90-
"_target_": "Resized",
91-
"keys": "image",
92-
"spatial_size": "@spatial_size",
93-
"mode": "area"
94-
},
95-
{
96-
"_target_": "DiscardAddGuidanced",
97-
"keys": "image",
98-
"label_names": "@label_names",
99-
"number_intensity_ch": "@number_intensity_ch"
100-
},
101-
{
102-
"_target_": "EnsureTyped",
103-
"keys": "image"
104-
}
105-
]
136+
"transforms": "$@preprocessing_transforms + (@deepedit_transforms if @use_click else @auto_seg_transforms) + @extra_transforms"
106137
},
107138
"dataset": {
108139
"_target_": "Dataset",

models/spleen_deepedit_annotation/configs/metadata.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
3-
"version": "0.4.7",
3+
"version": "0.4.8",
44
"changelog": {
5+
"0.4.8": "Add infer transforms to manage clicks from viewer",
56
"0.4.7": "fix the wrong GPU index issue of multi-node",
67
"0.4.6": "update to use rc7 which solves dynunet issue",
78
"0.4.5": "remove error dollar symbol in readme",
@@ -28,7 +29,7 @@
2829
"pytorch_version": "1.13.1",
2930
"numpy_version": "1.22.2",
3031
"optional_packages_version": {
31-
"nibabel": "4.0.1",
32+
"itk": "5.3.0",
3233
"pytorch-ignite": "0.4.9",
3334
"scikit-image": "0.19.3"
3435
},

models/spleen_deepedit_annotation/docs/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,28 @@ python -m monai.bundle run --config_file "['configs/train.json','configs/evaluat
118118

119119
#### Execute inference:
120120

121+
122+
For automatic inference mode:
123+
124+
121125
```
122126
python -m monai.bundle run --config_file configs/inference.json
123127
```
124128

129+
For interactive segmentation mode, in which the user provides clicks, set the **use_click** flag to true:
130+
131+
132+
```
133+
python -m monai.bundle run --config_file configs/inference.json --use_click true
134+
```
135+
136+
Clicks should be added to the data dictionary that is passed to the preprocessing transforms. The add keys are defined in `label_names` in `configs/inference.json`, and the corresponding values are the point coordinates. The following is an example of a data dictionary:
137+
138+
```
139+
{"image": "example.nii.gz", "background": [], "spleen": [[I1, J1, K1], [I2, J2, K2]]}
140+
```
141+
where **[I1,J1,K1]** and **[I2,J2,K2]** are the point coordinates.
142+
125143
#### Export checkpoint to TensorRT based models with fp32 or fp16 precision:
126144

127145
```bash

0 commit comments

Comments
 (0)