# Deep Learning Tutorial for Pulmonary Nodules Segmentation, using Keras
## 天池医疗AI大赛[第一季]:U-Net训练基于卷积神经网络的肺结节分割器
> ##### @author Jeniffer Wu
> As I received some emails from the readers about the "pulmonary nodule intelligent diagnosis" project on my Github these days, I have written to answer some of these questions.
[Letters to readers](https://github.com/JenifferWuUCLA/pulmonary-nodules-segmentation/blob/master/Letters%20to%20readers.pdf)
> I have answered the questions of intelligent diagnosis of pulmonary nodules
[Questions and answers](https://github.com/JenifferWuUCLA/pulmonary-nodules-segmentation/blob/master/Questions%20and%20answers.pdf)
##### See picture below(肺癌检测系统框图)
![肺癌检测系统框图_sz.jpeg](img/肺癌检测系统框图_sz.jpeg)
##### See picture below(Fig. Extracting the mask of the nodules and training the network on the Segmented lungs)
![Extracting the mask of the nodules and training the network on the Segmented lungs.jpeg](https://github.com/JenifferWuUCLA/pulmonary-nodules-segmentation/blob/master/img/Pulmonary_nodule_intelligent_diagnosis_flow_chart.jpeg)
#### Lung nodule prediction error:
>##### ![Index Page](https://github.com/JenifferWuUCLA/pulmonary-nodules-segmentation/blob/master/image-coordinate/Lung%20nodule%20prediction%20error.png)
This tutorial shows how to use [Keras library](http://keras.io/) to build deep neural network for pulmonary nodules image segmentation.
This deep neural network achieves **~0.57 score on the leaderboard** based on test images,
and can be a good staring point for further, more serious approaches.
The architecture was inspired by [U-Net: Convolutional Networks for Biomedical Image Segmentation](http://lmb.informatik.uni-freiburg.de/people/ronneber/u-net/).
---
- using Keras 2
- using TF backend instead of Theano
- using scikit-image instead of cv2
- added code for saving predicted images to disk
- training data is now split into train/validation data (80%/20%)
---
## Overview
### Data
Train and test data set in built by ```tianchi```, and the .mhd is processed by ```*_dataset_mask_extraction.py```, ```*_dataset_segment_lung_ROI.py```, ```*_dataset_preprocessing_2DUnet.py``` script.
This script just loads the images and saves them into NumPy binary format files **.npy** for faster loading later.
### Pre-processing
The images are not pre-processed in any way, except resizing to 512 x 512. Since the images are pretty noisy,
I expect that some thoughtful pre-processing could yield better performance of the model.
Output images (masks) are scaled to \[0, 1\] interval.
### Model
The provided model is basically a convolutional auto-encoder, but with a twist - it has skip connections from encoder layers to decoder layers that are on the same "level".
See picture below (note that image size and numbers of convolutional filters in this tutorial differs from the original U-Net architecture).
![img/u-net-architecture.png](img/u-net-architecture.png)
This deep neural network is implemented with Keras functional API, which makes it extremely easy to experiment with different interesting architectures.
Output from the network is a 512 x 512 which represents mask that should be learned. Sigmoid activation function
makes sure that mask pixels are in \[0, 1\] range.
### Training
The model is trained for 20 epochs, where each epoch took ~30 seconds on Titan X. Memory footprint of the model is ~800MB.
After 20 epochs, calculated Dice coefficient is ~0.68, which yielded ~0.57 score on leaderboard, so obviously this model overfits (cross-validation pull requests anyone? ;)).
Loss function for the training is basically just a **negative of Dice coefficient**
(which is used as [evaluation metric on the competition](https://www.kaggle.com/c/ultrasound-nerve-segmentation/details/evaluation)),
and this is implemented as custom loss function using Keras backend - check ```dice_coef()``` and ```dice_coef_loss()``` functions in ```deep_learning_2DUnet.py```, ```deep_learning_unet.py``` for more detail.
Also, for making the loss function smooth, a factor ```smooth = 1``` factor is added.
The weights are updated by Adam optimizer, with a 1e-5 learning rate. During training, model's weights are saved in HDF5 format.
---
## How to use
### Dependencies
This tutorial depends on the following libraries:
* scikit-image
* Tensorflow
* Keras >= 2.0
Also, this code should be compatible with Python versions 2.7-3.5.
### Prepare the data
In order to extract raw images and save them to *.npy* files, you should first prepare its structure.
* Now run ```python *_dataset_mask_extraction.py```, ```*_dataset_segment_lung_ROI.py``` or ```*_dataset_preprocessing_2DUnet.py```.
Running this script will create train and test images and save them to **.npy** files.
### Define the model
* Check out ```get_unet()``` in ```deep_learning_2DUnet.py``` to modify the model, optimizer and loss function.
### Train the model and generate masks for test images
* Run ```python deep_learning_2DUnet.py``` to train the model.
Check out ```train_predict()``` to modify the number of iterations (epochs), batch size, etc.
After this script finishes, in ```imgs_mask_test.npy``` masks for corresponding images in ```imgs_test.npy```
should be generated. I suggest you examine these masks for getting further insight of your model's performance.
### Generate submission
* Run ```python generate_submission.py``` to generate the submission file ```submission.csv``` for the generated masks.
Check out function ```submission()``` and ```run_length_enc()``` (thanks woshialex) for details.
### Authors
Pulmonary-nodules-segmentation is designed and implemented by Yingyi Wu <yywu@szucla.org>.
## About Keras
Keras is a minimalist, highly modular neural networks library, written in Python and capable of running on top of either TensorFlow or Theano. It was developed with a focus on enabling fast experimentation. Being able to go from idea to result with the least possible delay is key to doing good research.
Use Keras if you need a deep learning library that:
allows for easy and fast prototyping (through total modularity, minimalism, and extensibility).
supports both convolutional networks and recurrent networks, as well as combinations of the two.
supports arbitrary connectivity schemes (including multi-input and multi-output training).
runs seamlessly on CPU and GPU.
Read the documentation [Keras.io](http://keras.io/)
Keras is compatible with: Python 2.7-3.5.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
天池医学AI大赛【第一季】-U-Net肺结节图像分割. U-Net训练基于卷积神经网 (169个子文件)
statistics.csv 65KB
imgs_mask_test_coordinate.csv 38KB
pulmonary_nodule_probability.csv 25KB
annotations.csv 17KB
annotations.csv 5KB
submission.csv 4KB
seriesuids.csv 3KB
tianchi_segment_lung_ROI.ipynb 300KB
Legend lung nodule prediction error.ipynb 109KB
Lung nodule prediction error.ipynb 75KB
肺癌检测系统框图_sz.jpeg 48KB
Pulmonary_nodule_intelligent_diagnosis_flow_chart.jpeg 40KB
肺癌检测系统框图.jpeg 26KB
lung_nodule_predict_MSE_curve.log 9KB
DataSciBowl2017_9th.md 13KB
README.md 6KB
readme.md 1KB
readme.md 1KB
merge_caffe_data_file 879B
Mask R-CNN.pdf 7.34MB
Bayesian SegNet_ Model Uncertainty in Deep Convolutional Encoder-Decoder Architectures for Scene Understanding.pdf 6.69MB
DeepLab_ Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully Connected CRFs.pdf 5.82MB
Learning Deconvolution Network for Semantic Segmentation.pdf 5.08MB
SEMANTIC IMAGES EGMENTATION WITH DEEP CON-VOLUTIONAL NETS AND FULLY CONNECTED CRFS.pdf 4.5MB
Fully Convolutional Networks for Semantic Segmentation.pdf 4.48MB
PixelNet_ Representation of the pixels, by the pixels, and for the pixels.pdf 4.48MB
Pyramid Scene Parsing Network.pdf 4.29MB
V-Net_ Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation.pdf 4.1MB
ICNet for Real-Time Semantic Segmentation on High-Resolution Images.pdf 3.84MB
ENet_ A Deep Neural Network Architecture for Real-Time Semantic Segmentation.pdf 2.94MB
MULTI -SCALE CONTEXT AGGREGATION BY DILATED CONVOLUTIONS.pdf 2.86MB
Weakly- and Semi-Supervised Learning of a Deep Convolutional Network for Semantic Image Segmentation.pdf 2.49MB
PixelNet_ Towards a General Pixel-Level Architecture.pdf 2.41MB
SegNet_ A Deep Convolutional Encoder-Decoder Architecture for Image Segmentation.pdf 2.17MB
Conditional Random Fields as Recurrent Neural Networks.pdf 1.74MB
Deep Learning for Lung Cancer Detection_ Tackling the Kaggle Data Science Bowl 2017 Challenge.pdf 752KB
CNN as Guided Multi-layer RECOS Transform.pdf 599KB
3D U-Net_ Learning Dense Volumetric Segmentation from Sparse Annotation.pdf 579KB
Lung nodule prediction error.png 82KB
u-net-architecture.png 40KB
in-resnet.prototxt 122KB
resnet_152.prototxt 117KB
deploy.prototxt 96KB
resnet_101.prototxt 78KB
deploy.prototxt 64KB
googlenet_bn.prototxt 53KB
deploy.prototxt 49KB
googlenet.prototxt 40KB
resnet_50.prototxt 38KB
pre_152_train_val.prototxt 38KB
pre_50_train_val.prototxt 38KB
pre_101_train_val.prototxt 38KB
pre_200_train_val.prototxt 38KB
resnet_152_train_val.prototxt 36KB
resnet_101_train_val.prototxt 36KB
resnet_50_train_val.prototxt 36KB
deploy.prototxt 35KB
deploy.prototxt 32KB
ResNet-50-deploy.prototxt 32KB
resnet_34_train_val.prototxt 27KB
resnet_32.prototxt 23KB
deploy.prototxt 23KB
resnet_18_train_val.prototxt 20KB
deploy.prototxt 19KB
segnet.prototxt 19KB
deploy.prototxt 18KB
resnet_18.prototxt 14KB
deeplab_vgg16.prototxt 12KB
pspnet_vgg16.prototxt 12KB
deploy.prototxt 12KB
deploy.prototxt 11KB
squeezenet.prototxt 11KB
deploy.prototxt 11KB
unet.prototxt 10KB
deploy.prototxt 10KB
deploy.prototxt 10KB
nin.prototxt 7KB
vdcnn_9.prototxt 7KB
deploy.prototxt 6KB
deploy.prototxt 6KB
alexnet.prototxt 5KB
vgg_16.prototxt 5KB
deploy.prototxt 5KB
deploy.prototxt 4KB
cifar.prototxt 3KB
deploy.prototxt 3KB
convnet.prototxt 1KB
mlp.prototxt 1KB
deploy.prototxt 939B
deploy.prototxt 932B
cifar_solver.prototxt 863B
lregression.prototxt 845B
squeezenet_solver.prototxt 723B
deploy.prototxt 494B
deeplab_vgg16_solver.prototxt 303B
pspnet_vgg16_solver.prototxt 301B
googlenet_bn_solver.prototxt 299B
googlenet_solver.prototxt 295B
resnet_101_solver.prototxt 294B
resnet_152_solver.prototxt 294B
共 169 条
- 1
- 2
资源评论
好家伙VCC
- 粉丝: 2393
- 资源: 9142
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 小型液压打包机sw16可编辑全套技术资料100%好用.zip
- Comsol散射体手性 基板上的周期性金属阵列 散射光谱多极分解
- 具有多个领导者的平均一致包容分布式优化(需要安装cvx工具包)
- 小型立库自动进出料系统sw19可编辑全套技术资料100%好用.zip
- MATLAB 和Processing 的仿真环境用于对Stewart 平台问题进行建模,采用GUI界面进行控制 MATLAB 模型用于绘制腿部驱动图 该代码可以确保真实的模拟器腿不会超过操作范围内的
- 斯图尔特机器人Stewart平台 并联机构仿真 逆向运动学 simulink simscape ①首先在Solidworks中设计并导入 Matlab Simscape Multibody; ②设计控
- 预测太阳、月亮和行星的升起和落下-预测太阳、月亮和行星的升起和落下-matlab
- INFO-KELM回归,基于向量加权平均算法(INFO)优化核极限学习机(KELM)的数据回归预测(需要时序预测和分类都有),Matlab代码,可直接运行,适合小白新手 程序已经调试好,无需更改代码替
- 油漆桶外膜自动包装机ug10全套技术资料100%好用.zip
- 移载传送机sw18可编辑全套技术资料100%好用.zip
- 医用拖鞋筐子清洗烘干机sw18全套技术资料100%好用.zip
- 性能达到雷赛dm556步进电机驱动器全套资料
- 基于正弦PWM的永磁同步电机开环V/F控制-Open loop V/F control of PMSM using Sine PWM-matlab
- 自适应迭代无迹卡尔曼滤波算法AIUKF 锂离子电池SOC估计 递推最小二乘法辩识电池参数 具有良好的鲁棒性,初值误差为30%,仍能快速收敛 采用马里兰大学18650电池公开数据集 FUDS工况
- 基于FOC的永磁同步电机闭环速度控制-Closed Loop Speed Control of PMSM using FOC-matlab
- 电池二阶等效电路模型(2RC ECM) 基于最小二乘法的参数辩识代码 基于EKF的SOC估计代码 ps.有参考文献,可简单
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功