In this example, we show how to use a customized CNN and a customized loss function to segment the lung from X-Ray images. The configurations are the same as those in the JSRT
example except for the network structure and loss function.
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 define a focal dice loss named as MyFocalDiceLoss. We use MyFocalDiceLoss + CrossEntropyLoss
to train the customized network.
We also write a customized main function in jsrt_net_run.py
so that we can combine SegmentationAgent from PyMIC with our customized CNN and loss function.
- We use the same dataset as in the the
JSRT
example.
- Start to train by running:
python net_run_jsrt.py train config/mynet.cfg
- During training or after training, run
tensorboard --logdir model/mynet
and you will see a link in the output, such ashttp://your-computer:6006
. Open the link in the browser and you can observe the average Dice score and loss during the training stage, such as shown in the following images, where red and blue curves are for training set and validation set respectively.
- Edit the
testing
section inconfig/mynet.cfg
, and run the following command for testing:
python net_run_jsrt.py test config/mynet.cfg
- Use the following command to obtain quantitative evaluation results in terms of dice.
pymic_eval_seg config/evaluation.cfg
The obtained dice score by default setting should be close to 97.999%.