Skip to content

Commit fec928b

Browse files
committed
update readme
1 parent 5af56d9 commit fec928b

File tree

7 files changed

+47
-27
lines changed

7 files changed

+47
-27
lines changed

examples/JSRT/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mkdir result
3838
pymic_net_run test config/train_test.cfg
3939
```
4040

41-
2. Then edit `config/evaluation.cfg` by setting `ground_truth_folder_list` as your `JSRT_root/label`, and run the following command to obtain quantitative evaluation results in terms of dice.
41+
2. Then edit `config/evaluation.cfg` by setting `ground_truth_folder_root` as your `JSRT_root`, and run the following command to obtain quantitative evaluation results in terms of dice.
4242

4343
```bash
4444
pymic_evaluate config/evaluation.cfg

examples/JSRT2/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
![image_example](../JSRT/picture/JPCLN001.png)
44
![label_example](../JSRT/picture/JPCLN001_seg.png)
55

6-
In this example, we show how to use a customized CNN to segment the heart from X-Ray images. The configurations are the same as those in the `JSRT` example except the network structure.
6+
In this example, we show how to use a customized CNN and a customized loss function to segment the heart from X-Ray images. The configurations are the same as those in the `JSRT` example except the network structure and loss function.
77

8-
The customized CNN is detailed in `my_net2d.py`, which is a modification of the 2D UNet. In this new network, we use a residual connection in each block.
8+
The customized CNN is detailed in `my_net2d.py`, which is a modification of the 2D UNet. In this new network, we use a residual connection in each block. The customized loss is detailed in `my_loss.py`, where we combine Dice loss and MAE loss as our new loss function.
99

10-
To use the customized CNN, we also write a customized main function in `jsrt_train_infer.py`, where we import a TrainInferAgent from PyMIC and set the network as our customized CNN.
10+
We also write a customized main function in `jsrt_train_infer.py` so that we can combine TrainInferAgent from PyMIC with our customized CNN and loss function.
1111

1212
## Data and preprocessing
1313
1. Data preprocessing is the same as that in the the `JSRT` example. Please follow that example for details.
@@ -31,7 +31,7 @@ python jsrt_net_run.py train config/train_test.cfg
3131
python jsrt_net_run.py test config/train_test.cfg
3232
```
3333

34-
2. Edit `config/evaluation.cfg` by setting `ground_truth_folder_list` as your `JSRT_root/label`, and run the following command to obtain quantitative evaluation results in terms of dice.
34+
2. Edit `config/evaluation.cfg` by setting `ground_truth_folder_root` as your `JSRT_root`, and run the following command to obtain quantitative evaluation results in terms of dice.
3535

3636
```
3737
pymic_evaluate config/evaluation.cfg

examples/JSRT2/config/evaluation.cfg

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ metric = dice
33
label_list = [255]
44
organ_name = heart
55

6-
segmentation_folder_list = [result]
7-
segmentation_postfix =
8-
segmentation_format = png
9-
10-
ground_truth_folder_list = [/home/disk2t/data/JSRT/label]
11-
ground_truth_postfix =
12-
ground_truth_format = png
13-
14-
patient_file_names = ../JSRT/config/jsrt_test_names.txt
15-
6+
ground_truth_folder_root = /home/disk2t/data/JSRT
7+
segmentation_folder_root = result
8+
evaluation_image_pair = ../JSRT/config/jsrt_test_gt_seg.csv
9+
10+
ground_truth_label_convert_source = None
11+
ground_truth_label_convert_target = None
12+
segmentation_label_convert_source = None
13+
segmentation_label_convert_target = None

examples/JSRT2/config/train_test.cfg

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ train_csv = ../JSRT/config/jsrt_train.csv
77
valid_csv = ../JSRT/config/jsrt_valid.csv
88
test_csv = ../JSRT/config/jsrt_test.csv
99

10+
load_pixelwise_weight = False
1011
# modality number
1112
modal_num = 1
1213

@@ -37,12 +38,22 @@ LabelToProbability_inverse = False
3738
# this section gives parameters for network
3839
# In this example, a customized network is used.
3940

41+
# type of network
42+
net_type = MyUNet2D
43+
44+
# number of class, required for segmentation task
45+
class_num = 2
46+
in_chns = 1
47+
feature_chns = [4, 16, 24, 32, 48]
48+
dropout = [0.0, 0.0, 0.3, 0.3, 0.4, 0.5]
49+
bilinear = True
50+
4051
[training]
4152
# device name" cuda:n or cpu
4253
device_name = cuda:0
4354

4455
batch_size = 4
45-
loss_function = dice_loss
56+
loss_function = my_loss
4657

4758
# for optimizers
4859
optimizer = Adam

examples/JSRT2/jsrt_net_run.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,24 @@
33

44
import sys
55
from pymic.net_run.net_run import TrainInferAgent
6+
from pymic.net_run.net_factory import net_dict
67
from pymic.util.parse_config import parse_config
78
from my_net2d import MyUNet2D
9+
from my_loss import MySegmentationLossCalculator
10+
11+
my_net_dict = {
12+
"MyUNet2D": MyUNet2D
13+
}
14+
15+
def get_network(params):
16+
net_type = params["net_type"]
17+
if(net_type in my_net_dict):
18+
net = my_net_dict[net_type](params)
19+
elif(net_type in net_dict):
20+
net = net_dict[net_type](params)
21+
else:
22+
raise ValueError("Undefined network: {0:}".format(net_type))
23+
return net
824

925
def main():
1026
if(len(sys.argv) < 3):
@@ -15,17 +31,12 @@ def main():
1531
cfg_file = str(sys.argv[2])
1632
config = parse_config(cfg_file)
1733

18-
# use custormized CNN
19-
net_param = {'in_chns':1,
20-
'feature_chns':[4, 16, 32, 64, 128],
21-
'dropout': [0, 0, 0.3, 0.4, 0.5],
22-
'class_num': 2,
23-
'bilinear': True}
24-
config['network'] = net_param
25-
net = MyUNet2D(net_param)
26-
34+
# use custormized CNN and loss function
35+
net = get_network(config['network'])
36+
loss_cal = MySegmentationLossCalculator(config['training'])
2737
agent = TrainInferAgent(config, stage)
2838
agent.set_network(net)
39+
agent.set_loss_calculater(loss_cal)
2940
agent.run()
3041

3142
if __name__ == "__main__":

examples/fetal_hc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mkdir result
3535
pymic_net_run test config/train_test.cfg
3636
```
3737

38-
2. Then edit `config/evaluation.cfg` by setting `ground_truth_folder_list` as your `HC_root/training_set_label`, and run the following command to obtain quantitative evaluation results in terms of dice.
38+
2. Then edit `config/evaluation.cfg` by setting `ground_truth_folder_root` as your `HC_root`, and run the following command to obtain quantitative evaluation results in terms of dice.
3939

4040
```bash
4141
pymic_evaluate config/evaluation.cfg

examples/prostate/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mkdir result
3333
pymic_net_run test config/train_test.cfg
3434
```
3535

36-
2. Then edit `config/evaluation.cfg` by setting `ground_truth_folder_list` as your `data/promise12/preprocess/label`, and run the following command to obtain quantitative evaluation results in terms of dice.
36+
2. Then edit `config/evaluation.cfg` by setting `ground_truth_folder_root` as your `data/promise12/preprocess`, and run the following command to obtain quantitative evaluation results in terms of dice.
3737

3838
```bash
3939
pymic_evaluate config/evaluation.cfg

0 commit comments

Comments
 (0)