Switch to unified view

a/README.md b/README.md
1
---
1
---
2
languages:
2
languages:
3
- python
3
- python
4
products:
4
products:
5
- Azure Machine Learning Service
5
- Azure Machine Learning Service
6
- Tensorflow 2.0
6
- Tensorflow 2.0
7
description: "Image segmentation TensorFlow model for Cardiac MRI's"
7
description: "Image segmentation TensorFlow model for Cardiac MRI's"
8
---
8
---
9
9
10
![sample_prediction](readme/sample_prediction.png)
10
11
12
#  Image Segmentation Cardiac MRI's with Azure Machine Learning Service and TensorFlow 
11
#  Image Segmentation Cardiac MRI's with Azure Machine Learning Service and TensorFlow 
13
12
14
There are a variety of important image analysis deep learning applications that need to go beyond detecting individual objects within an image and instead segment the image into spatial regions of interest. For example, in medical imagery analysis it is often important to separate the pixels corresponding to different types of tissue, blood or abnormal cells so that we can isolate a particular organ. In this self-paced, hands-on lab we will use the [TensorFlow](https://www.tensorflow.org/) machine learning framework to train and evaluate an image segmentation network using a medical imagery dataset.
13
There are a variety of important image analysis deep learning applications that need to go beyond detecting individual objects within an image and instead segment the image into spatial regions of interest. For example, in medical imagery analysis it is often important to separate the pixels corresponding to different types of tissue, blood or abnormal cells so that we can isolate a particular organ. In this self-paced, hands-on lab we will use the [TensorFlow](https://www.tensorflow.org/) machine learning framework to train and evaluate an image segmentation network using a medical imagery dataset.
15
14
16
## Objectives
15
## Objectives
17
16
18
* Understand how Neural Networks can solve imaging problems
17
* Understand how Neural Networks can solve imaging problems
19
* Use Transpose Convolutional Neural Networks
18
* Use Transpose Convolutional Neural Networks
20
* Use Keras and TensorFlow 2 to analyze image data
19
* Use Keras and TensorFlow 2 to analyze image data
21
* Use Azure Machine learning Service
20
* Use Azure Machine learning Service
22
21
23
|Technology|
22
|Technology|
24
|----------|
23
|----------|
25
|Azure Machine Learning |
24
|Azure Machine Learning |
26
|Tensorflow 2.0 |
25
|Tensorflow 2.0 |
27
|Unet Architecture |
26
|Unet Architecture |
28
27
29
## Why Azure Machine Learning Service?
28
## Why Azure Machine Learning Service?
30
29
31
![mlops](readme/ml-lifecycle.png)
30
32
33
Azure Machine Learning Service give to use the capability to use MLOps techniques, it empowers data scientists and app developers to help bring ML models to production.
31
Azure Machine Learning Service give to use the capability to use MLOps techniques, it empowers data scientists and app developers to help bring ML models to production.
34
32
35
This MLOps functionalities that Azure Machine Learning have, enables you to track / version / audit / certify / re-use every asset in your ML lifecycle and provides orchestration services to streamline managing this lifecycle.
33
This MLOps functionalities that Azure Machine Learning have, enables you to track / version / audit / certify / re-use every asset in your ML lifecycle and provides orchestration services to streamline managing this lifecycle.
36
34
37
### What are the key challenges we wish to solve with?
35
### What are the key challenges we wish to solve with?
38
36
39
![mlops_flow](readme/mlops.png)
37
40
41
**Model reproducibility & versioning**
38
**Model reproducibility & versioning**
42
- Track, snapshot & manage assets used to create the model
39
- Track, snapshot & manage assets used to create the model
43
- Enable collaboration and sharing of ML pipelines
40
- Enable collaboration and sharing of ML pipelines
44
41
45
**Model packaging & validation**
42
**Model packaging & validation**
46
- Support model portability across a variety of platforms
43
- Support model portability across a variety of platforms
47
- Certify model performance meets functional and latency requirements
44
- Certify model performance meets functional and latency requirements
48
45
49
**[Not implemented] Model auditability & explainability**
46
**[Not implemented] Model auditability & explainability**
50
- Maintain asset integrity & persist access control logs
47
- Maintain asset integrity & persist access control logs
51
- Certify model behavior meets regulatory & adversarial standards
48
- Certify model behavior meets regulatory & adversarial standards
52
49
53
**[Not implemented] Model deployment & monitoring**
50
**[Not implemented] Model deployment & monitoring**
54
- Release models with confidence
51
- Release models with confidence
55
- Monitor & know when to retrain by analyzing signals such as data drift
52
- Monitor & know when to retrain by analyzing signals such as data drift
56
53
57
## Deploy Infrastructure
54
## Deploy Infrastructure
58
55
59
Follow the next documentation if you dont have Azure Machine Learning up and running yet
56
Follow the next documentation if you dont have Azure Machine Learning up and running yet
60
57
61
#### [Set up Azure Resources with Azure Reource Manager (ARM)](./infrastructure/README.md)
58
#### [Set up Azure Resources with Azure Reource Manager (ARM)](./infrastructure/README.md)
62
59
63
60
64
## Virtual environment to execute Azure Machine Learning notebook
61
## Virtual environment to execute Azure Machine Learning notebook
65
62
66
### Ananconda and Jupyter Notebook Local
63
### Ananconda and Jupyter Notebook Local
67
64
68
To create the virual environment, we need to have anaconda installed in our computer. It can be downloaded in this [link](https://www.anaconda.com/download/)
65
To create the virual environment, we need to have anaconda installed in our computer. It can be downloaded in this [link](https://www.anaconda.com/download/)
69
66
70
- Instalation: https://www.anaconda.com/distribution/
67
- Instalation: https://www.anaconda.com/distribution/
71
- Conda commands to create local env by environment.yml: ```conda env create -f environment.yml```
68
- Conda commands to create local env by environment.yml: ```conda env create -f environment.yml```
72
- Set conda env into jupyter notebook: ```python -m ipykernel install --user --name <environment_name> --display-name "Python (<environment_name>)"```
69
- Set conda env into jupyter notebook: ```python -m ipykernel install --user --name <environment_name> --display-name "Python (<environment_name>)"```
73
70
74
Once the environment is created, to activate it:
71
Once the environment is created, to activate it:
75
72
76
`conda activate <environment-name>`
73
`conda activate <environment-name>`
77
74
78
To deactivate the environment:
75
To deactivate the environment:
79
76
80
`conda deactivate <environment-name>`
77
`conda deactivate <environment-name>`
81
78
82
### Dataset
79
### Dataset
83
80
84
Cardiac MRI short-axis (SAX) scans:
81
Cardiac MRI short-axis (SAX) scans:
85
82
86
- Sunnybrook cardiac images from earlier competition
83
- Sunnybrook cardiac images from earlier competition
87
http://smial.sri.utoronto.ca/LV_Challenge/Data.html
84
http://smial.sri.utoronto.ca/LV_Challenge/Data.html
88
85
89
- "Sunnybrook Cardiac MR Database" is made available under the CC0 1.0 Universal
86
- "Sunnybrook Cardiac MR Database" is made available under the CC0 1.0 Universal
90
license described above, and with more detail here:
87
license described above, and with more detail here:
91
http://creativecommons.org/publicdomain/zero/1.0/
88
http://creativecommons.org/publicdomain/zero/1.0/
92
89
93
Original images are 256 x 256 grayscale DICOM format
90
Original images are 256 x 256 grayscale DICOM format
94
91
95
- Output is a tensor of size 256 x 256 x 2
92
- Output is a tensor of size 256 x 256 x 2
96
93
97
- Each pixel belongs to one of two classes
94
- Each pixel belongs to one of two classes
98
95
99
- Training set consist of 234 images
96
- Training set consist of 234 images
100
97
101
- Validation set consist of 26 images
98
- Validation set consist of 26 images
102
99
103
Download here TFrecords: https://drive.google.com/drive/folders/1bYoJMycuKsTg2LUWRKircUzjtQYYGzNf?usp=sharing
100
Download here TFrecords: https://drive.google.com/drive/folders/1bYoJMycuKsTg2LUWRKircUzjtQYYGzNf?usp=sharing
104
101
105
#### Attribution: 
102
#### Attribution: 
106
103
107
Radau P, Lu Y, Connelly K, Paul G, Dick AJ, Wright GA. "Evaluation Framework for
104
Radau P, Lu Y, Connelly K, Paul G, Dick AJ, Wright GA. "Evaluation Framework for
108
    Algorithms Segmenting Short Axis Cardiac MRI." The MIDAS Journal -Cardiac MR Left
105
    Algorithms Segmenting Short Axis Cardiac MRI." The MIDAS Journal -Cardiac MR Left
109
    Ventricle Segmentation Challenge, http://hdl.handle.net/10380/3070
106
    Ventricle Segmentation Challenge, http://hdl.handle.net/10380/3070
110
107
111
# Image Segmentation
108
# Image Segmentation
112
109
113
In this repository you will work through a series of exercises performing image segmentation, also called semantic segmentation.  Semantic segmentation is the task of placing each pixel into a specific class.  In a sense it's a classification problem where you'll classify on a pixel basis rather than an entire image.  In this lab the task will be classifying each pixel in a cardiac MRI image based on whether the pixel is a part of the left ventricle (LV) or not.
110
In this repository you will work through a series of exercises performing image segmentation, also called semantic segmentation.  Semantic segmentation is the task of placing each pixel into a specific class.  In a sense it's a classification problem where you'll classify on a pixel basis rather than an entire image.  In this lab the task will be classifying each pixel in a cardiac MRI image based on whether the pixel is a part of the left ventricle (LV) or not.
114
111
115
This lab is not an introduction to deep learning, nor is it intended to be a rigorous mathematical formalism of convolutional neural networks.  We'll assume that you have at least a passing understanding of neural networks including concepts like forward and backpropagation, activations, SGD, convolutions, pooling, bias, and the like.  It is helpful if you've encountered convolutional neural networks (CNN) already and you understand image recognition tasks.  The lab will use Google's TensorFlow machine learning framework so if you have Python and TensorFlow experience it is helpful, but not required.  Most of the work we'll do in this lab is not coding per se, but setting up and running training and evaluation tasks using TensorFlow.
112
This lab is not an introduction to deep learning, nor is it intended to be a rigorous mathematical formalism of convolutional neural networks.  We'll assume that you have at least a passing understanding of neural networks including concepts like forward and backpropagation, activations, SGD, convolutions, pooling, bias, and the like.  It is helpful if you've encountered convolutional neural networks (CNN) already and you understand image recognition tasks.  The lab will use Google's TensorFlow machine learning framework so if you have Python and TensorFlow experience it is helpful, but not required.  Most of the work we'll do in this lab is not coding per se, but setting up and running training and evaluation tasks using TensorFlow.
116
113
117
114
118
## Input Data Set
115
## Input Data Set
119
116
120
![dataset](readme/dataset_sample.png)
121
122
The data set you'll be utilizing is a series of cardiac images (specifically MRI short-axis (SAX) scans) that have been expertly labeled.  See  References for full citation information. 
117
The data set you'll be utilizing is a series of cardiac images (specifically MRI short-axis (SAX) scans) that have been expertly labeled.  See  References for full citation information. 
123
118
124
Four representative examples of the data are shown below.  Each row of images is an instance of the data.  On the left are the MRI images and the right are the expertly-segmented regions (often called contours).  The portions of the images that are part of the LV are denoted in white.  Note that the size of LV varies from image to image, but the LV typically takes up a relatively small region of the entire image.
119
Four representative examples of the data are shown below.  Each row of images is an instance of the data.  On the left are the MRI images and the right are the expertly-segmented regions (often called contours).  The portions of the images that are part of the LV are denoted in white.  Note that the size of LV varies from image to image, but the LV typically takes up a relatively small region of the entire image.
125
120
126
The data extraction from the raw images and then subsequent preparation of these images for ingestion into TensorFlow will not be showcased in this lab.  Suffice it to say that data preparation is a non-trivial aspect of machine learning workflows and is outside the scope of this lab.
121
The data extraction from the raw images and then subsequent preparation of these images for ingestion into TensorFlow will not be showcased in this lab.  Suffice it to say that data preparation is a non-trivial aspect of machine learning workflows and is outside the scope of this lab.
127
122
128
For those that are interested in the details, we obtained guidance and partial code from a prior [Kaggle competition](https://www.kaggle.com/c/second-annual-data-science-bowl/details/deep-learning-tutorial) on how to extract the images properly.  At that point we took the images, converted them to TensorFlow records (TFRecords), and stored them to files.  [TFRecords](https://www.tensorflow.org/programmers_guide/reading_data) are a special file format provided by TensorFlow, which allow you to use built-in TensorFlow functions for data management including multi-threaded data reading and sophisticated pre-processing of the data such as randomizing and even augmenting the training data.
123
For those that are interested in the details, we obtained guidance and partial code from a prior [Kaggle competition](https://www.kaggle.com/c/second-annual-data-science-bowl/details/deep-learning-tutorial) on how to extract the images properly.  At that point we took the images, converted them to TensorFlow records (TFRecords), and stored them to files.  [TFRecords](https://www.tensorflow.org/programmers_guide/reading_data) are a special file format provided by TensorFlow, which allow you to use built-in TensorFlow functions for data management including multi-threaded data reading and sophisticated pre-processing of the data such as randomizing and even augmenting the training data.
129
124
130
The images themselves are originally 256 x 256 grayscale [DICOM](https://en.wikipedia.org/wiki/DICOM) format, a common image format in medical imaging.  The label is a tensor of size 256 x 256 x 2.  The reason the last dimension is a 2 is that the pixel is in one of two classes so each pixel label has a vector of size 2 associated with it.  The training set is 234 images and the validation set (data NOT used for training but used to test the accuracy of the model) is 26 images.
125
The images themselves are originally 256 x 256 grayscale [DICOM](https://en.wikipedia.org/wiki/DICOM) format, a common image format in medical imaging.  The label is a tensor of size 256 x 256 x 2.  The reason the last dimension is a 2 is that the pixel is in one of two classes so each pixel label has a vector of size 2 associated with it.  The training set is 234 images and the validation set (data NOT used for training but used to test the accuracy of the model) is 26 images.
131
126
132
# TensorBoard
127
# TensorBoard
133
128
134
In this experiment we generate TensorFlow logs. Tensorboard allows you to visualize many aspects of your program. In TensorBoard, you can see a visual representation of your computation graph and you can plot different metrics of your computation such as loss, accuracy, and learning rate.  Essentially any data that is generated during the execution of TensorFlow can be visually displayed by TensorBoard with the addition of a few extra API calls in your program.
129
In this experiment we generate TensorFlow logs. Tensorboard allows you to visualize many aspects of your program. In TensorBoard, you can see a visual representation of your computation graph and you can plot different metrics of your computation such as loss, accuracy, and learning rate.  Essentially any data that is generated during the execution of TensorFlow can be visually displayed by TensorBoard with the addition of a few extra API calls in your program.
135
130
136
Inside aml-pipeline.ipynb notebook you have the correspondant cells to execute Tensorboard after model training.
131
Inside aml-pipeline.ipynb notebook you have the correspondant cells to execute Tensorboard after model training.
137
132
138
![tensorboard](readme/tensorboard_execution.png)
133
139
140
Tensorboard hooks into Keras through a [training callback](https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/TensorBoard)
134
Tensorboard hooks into Keras through a [training callback](https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/TensorBoard)
141
135
142
<a id="References"></a>
136
<a id="References"></a>
143
# References
137
# References
144
138
145
Thanks to **NVIDIA** and **Tensorflow** Community for give the facilities to obtains this kind of dataset and lend for everyone the opportunity to train, analyze and prove this kind of images that usually we found that are private.
139
Thanks to **NVIDIA** and **Tensorflow** Community for give the facilities to obtains this kind of dataset and lend for everyone the opportunity to train, analyze and prove this kind of images that usually we found that are private.
146
140
147
- [Tensorflow 2.0](https://www.tensorflow.org/learn)
141
- [Tensorflow 2.0](https://www.tensorflow.org/learn)
148
- [Azure Machine Learning](https://azure.microsoft.com/es-es/services/machine-learning/)
142
- [Azure Machine Learning](https://azure.microsoft.com/es-es/services/machine-learning/)
149
- [UNET](https://arxiv.org/abs/1505.04597)
143
- [UNET](https://arxiv.org/abs/1505.04597)
150
144
151
<a id="1"></a>
145
<a id="1"></a>
152
[1] Sunnybrook cardiac images from earlier competition https://smial.sri.utoronto.ca/LV_Challenge/Data.html
146
[1] Sunnybrook cardiac images from earlier competition https://smial.sri.utoronto.ca/LV_Challenge/Data.html
153
147
154
<a id="2"></a>
148
<a id="2"></a>
155
[2] This "Sunnybrook Cardiac MR Database" is made available under the CC0 1.0 Universal license described above, and with more detail here: https://www.cardiacatlas.org/studies/sunnybrook-cardiac-data/
149
[2] This "Sunnybrook Cardiac MR Database" is made available under the CC0 1.0 Universal license described above, and with more detail here: https://www.cardiacatlas.org/studies/sunnybrook-cardiac-data/
156
150
157
<a id="3"></a>
151
<a id="3"></a>
158
[3] Attribution:
152
[3] Attribution:
159
Radau P, Lu Y, Connelly K, Paul G, Dick AJ, Wright GA. "Evaluation Framework for Algorithms Segmenting Short Axis Cardiac MRI." The MIDAS Journal -Cardiac MR Left Ventricle Segmentation Challenge, http://hdl.handle.net/10380/3070
153
Radau P, Lu Y, Connelly K, Paul G, Dick AJ, Wright GA. "Evaluation Framework for Algorithms Segmenting Short Axis Cardiac MRI." The MIDAS Journal -Cardiac MR Left Ventricle Segmentation Challenge, http://hdl.handle.net/10380/3070
160
154
161
<a id="4"></a>
155
<a id="4"></a>
162
[4] http://fcn.berkeleyvision.org/
156
[4] http://fcn.berkeleyvision.org/
163
157
164
<a id="5"></a>
158
<a id="5"></a>
165
[5] Long, Shelhamer, Darrell; "Fully Convoutional Networks for Semantic Segmentation", CVPR 2015.
159
[5] Long, Shelhamer, Darrell; "Fully Convoutional Networks for Semantic Segmentation", CVPR 2015.
166
160
167
<a id="6"></a>
161
<a id="6"></a>
168
[6] Zeiler, Krishnan, Taylor, Fergus; "Deconvolutional Networks", CVPR 2010.
162
[6] Zeiler, Krishnan, Taylor, Fergus; "Deconvolutional Networks", CVPR 2010.
169
163
170
<a id="7"></a>
164
<a id="7"></a>
171
[7] https://www.kaggle.com/c/second-annual-data-science-bowl/details/deep-learning-tutorial
165
[7] https://www.kaggle.com/c/second-annual-data-science-bowl/details/deep-learning-tutorial
172
166
173
<a id="8"></a>
167
<a id="8"></a>
174
[8] https://www.tensorflow.org/tutorials/images/segmentation
168
[8] https://www.tensorflow.org/tutorials/images/segmentation