# 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.
没有合适的资源?快使用搜索试试~ 我知道了~
Python-天池医疗AI大赛第一季肺部结节UNet图像分割
共168个文件
prototxt:73个
py:55个
pdf:19个
需积分: 50 149 下载量 175 浏览量
2019-08-10
04:56:32
上传
评论 23
收藏 64.08MB ZIP 举报
温馨提示
天池医疗AI大赛[第一季]:肺部结节U-Net图像分割
资源推荐
资源详情
资源评论
收起资源包目录
Python-天池医疗AI大赛第一季肺部结节UNet图像分割 (168个子文件)
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_50_train_val.prototxt 38KB
pre_200_train_val.prototxt 38KB
pre_152_train_val.prototxt 38KB
pre_101_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_152_solver.prototxt 294B
resnet_101_solver.prototxt 294B
共 168 条
- 1
- 2
资源评论
weixin_39840924
- 粉丝: 492
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功