Skip to content

Commit 46af823

Browse files
committed
[DLMED] split to 2 examples
Signed-off-by: Nic Ma <[email protected]>
1 parent 7a9d0cb commit 46af823

File tree

18 files changed

+64
-0
lines changed

18 files changed

+64
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Description
2+
This example mainly shows a typical use case that applies customized python component(like: transform, network, metrics, etc.) in the `train` config.
3+
4+
Please note that this example depends on the `spleen_segmentation` bundle example and executes via overriding the config file of it.
5+
6+
## commands example
7+
Export the customized python code to `PYTHONPATH`:
8+
```
9+
export PYTHONPATH=$PYTHONPATH:"<path to 'hybrid_programming/scripts'>"
10+
```
11+
12+
Override the `train` config with one customized `transform` and execute training:
13+
```
14+
python -m monai.bundle run training --meta_file <spleen_configs_path>/metadata.json --config_file "['<spleen_configs_path>/train.json','configs/custom_train.json']" --logging_file <spleen_configs_path>/logging.conf
15+
```
File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"train#preprocessing#transforms#6":
3+
{
4+
"_target_": "scripts.custom_transforms.PrintEnsureTyped",
5+
"keys": ["image", "label"]
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) MONAI Consortium
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) MONAI Consortium
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
12+
from monai.config import KeysCollection
13+
from monai.transforms import EnsureTyped
14+
15+
16+
class PrintEnsureTyped(EnsureTyped):
17+
"""
18+
Extend the `EnsureTyped` transform to print the image shape.
19+
20+
Args:
21+
keys: keys of the corresponding items to be transformed.
22+
23+
"""
24+
25+
def __init__(self, keys: KeysCollection, data_type: str = "tensor") -> None:
26+
super().__init__(keys, data_type=data_type)
27+
28+
def __call__(self, data):
29+
d = dict(super().__call__(data=data))
30+
for key in self.key_iterator(d):
31+
print(f"data shape of {key}: {d[key].shape}")
32+
return d

0 commit comments

Comments
 (0)