1© 2018 The MathWorks, Inc.
Biomedical Signal and Image Analytics Using MATLAB
Dr. Amod Anandkumar
Senior Team Lead – Signal Processing & Communications
Application Engineering Group
@_Dr_Amod
2
What they say
• Expand university programs
• Train existing analysts
3
The need for data scientists
Domain
expertise
Coding and
integration skills
Statistical and
mathematical
knowledge
4
MATLAB lets you be your own data scientist
MATLAB is Designed and
Documented to be Easy for
Engineers and Scientists to Use
“As a process engineer I had no
experience with neural networks or
machine learning. I worked through the
MATLAB examples to find the best
machine learning functions for
generating virtual metrology. I couldn’t
have done this in C or Python—it
would’ve taken too long to find, validate,
and integrate the right packages.”
Emil Schmitt-Weaver, ASML
“MATLAB enabled us, as geologists,
to use our expertise in predictive
frameworks, analytics, and analog
matching to implement algorithms that
are unique in our industry. With the
help of MathWorks consultants, we
then deployed those algorithms as an
easy-to-use application to our
colleagues worldwide.”
Nick Howes, Shell
5
Developing Motion Analysis Algorithms
for Medical, Sports, and Occupational
Safety Applications
Challenge
Accurately measure and track motion for medical, sports,
and occupational safety applications
Solution
Develop motion-tracking algorithms in MATLAB and
deploy them to a wearable, wireless motion analysis
device with MATLAB Coder
Results
▪ Time required to translate algorithms to production C
code reduced from a month to a few days
▪ Development time reduced by 50%
▪ Defect-free code generated
“With MATLAB and MATLAB Coder,
we can respond quickly to customer
requests. In a recent release, we
updated two algorithm modules,
created two new ones, and delivered
all four with a confidence that would
have been impossible using our old
workflow.”
Edgar Charry
dorsaVi
Link to article
dorsaVi sensors in use in a running test.
6
Challenge
Develop and implement an acoustic respiratory
monitoring system for wheeze detection and asthma
management
Solution
Develop algorithms for detecting wheeze and ambient
noise in MATLAB, and use MATLAB Coder to generate
code from the algorithms for mobile devices and a web
server
Results
▪ Manual coding effort reduced
▪ Algorithm development iterations accelerated
▪ Code maintenance overhead reduced
Respiri Develops Mobile App and Server
Software for Wheeze Detection and
Asthma Management
“MATLAB enables us to rapidly
develop, debug, and test sound-
processing algorithms, and
MATLAB Coder simplifies the
process of implementing those
algorithms in C. There’s no other
environment or programming
language that we could use to
produce similar results in the same
amount of time.”
Mark Mulvey
iSonea
The AirSonea device, which connects to
an asthma patient’s smartphone and
communicates with wheeze analysis
algorithms on iSonea’s server.
Link to user story
7
Data Analytics Workflow
Integrated Analytic
Systems
Desktop Apps
Enterprise Scale
Systems
Embedded Devices
and Hardware
Files
Databases
Sensors
Raw Data Models and Algorithms
Model Creation e.g.
Machine Learning
Model
Validation
Parameter
Optimization
Preprocessed Data
Working with
Messy Data
Data Reduction/
Transformation
Feature
Extraction
10
Today’s Examples
▪ Heart sound classification using machine learning
▪ MR image segmentation using deep learning
▪ Using visualizations for understanding CNN behaviour
11
Heart Sound Classification – An Example
▪ Motivation
– Heart sounds are complex signals
– Require trained clinicians for diagnosis
▪ Objective
– Develop algorithm for automatic
classification of heart sounds
▪ Dataset
– Training: 3240 recordings
– Validation: 301 recordings
– Recording Duration: 5 to 120 seconds
– Labels: Normal or Abnormal
Heart Sound
Recording
Classification
Algorithm
Normal
Abnormal
PhysioNet/CiC Challenge 2016
View Webinar
12
Hyperparameter Tuning and Feature Selection
Bayesian Optimization
▪ Tune hyperparameters of machine learning
algorithms automatically
▪ Use bayesopt function for complete control.
– Define objective function to be optimized.
– Optimize under constraints you define.
Neighbourhood Component Feature Selection
▪ Feature selection for classification (fscnca) or
regression (fsrnca)
▪ Suitable for use before any classification or
regression method
▪ Produces weights that go to 0 for irrelevant features
▪ Regularization parameter λ can be selected by
cross-validation
13
Wavelets for Signal Processing and Feature Extraction
▪ Time-Scale Analysis is
more robust and
powerful
▪ Signal Morphology &
Features can be
extracted
▪ Excellent for pre-
processing and feature
engineering on signals
Detrending ECG Signal Continuous Wavelet Transform
of an ECG Signal
14
Statistics & Machine Learning
▪ Use apps to interactively explore data, choose
algorithms to train and validate models, and
compare results
– Classification Learner app
– Regression Learner app
▪ Apply algorithms to out-of-memory data
using tall arrays
▪ Generate C code for predictive models
(requires MATLAB Coder)
MATLAB makes machine learning easy and accessible
for everyone, even if you’re not an expert
“I would have never attempted
machine learning if this app
was not available.”
15
Today’s Examples
▪ Heart sound classification using machine learning
▪ MR image segmentation using deep learning
▪ Using visualizations for understanding network behaviour
17
Perform Object Detection and Recognition
using Deep Learning
Deep Learning
▪ Convolutional Neural Networks
▪ Directed Acyclic Graph Networks
▪ Autoencoders
▪ Long Short-Term Memory Networks
Computer Vision System Toolbox
Neural Network Toolbox
Parallel Computing Toolbox
Object Detection
▪ Regions with CNN (R-CNN)
▪ Fast R-CNN
▪ Faster R-CNN
Deep Learning
…
𝟗𝟓%
𝟑%


𝟐%
Truck
Car ✓
Bicycle


Learned features
End-to-end learning
Feature learning + Classification
18
Deep Learning Challenges
▪ Accessing reference models from research
▪ Difficult to understand network behavior
▪ Tuning hyperparameters and refining architectures
▪ Training takes hours-days
▪ Labeling large sets of images
▪ Real world systems use more than deep learning
– Deep learning frameworks do not include “classical” computer vision
▪ Deployment on embedded hardware
▪ Not a deep learning expert
19
Convolutional Neural Network
Convolution +
ReLU PoolingInput
Convolution +
ReLU Pooling
…
…
Flatten Fully
Connected
Softmax
dog
…
cat
…
…
Feature Learning Classification
goldfish✓


20
Classification vs/ Regression v/s Detection v/s Semantic Segmentation
HIGHWAY_SCENE
Classification
Car Car CarDetection
Lane Lane
Regression
Semantic
Segmentation
21
Cardiac MR Left Ventricle Segmentation – An Example
▪ Motivation
– Cardiac MR images are very complex
– Require trained clinicians for manual
segmentation
▪ Objective
– Develop algorithm for automatic
segmentation of left ventricle
▪ Dataset
– Training Data: 260 images
– Pixel Labels: LV or background
LV Segmentation Challenge
22
Access Large Sets of Images
Handle Large Sets of Images
Easily manage large sets of images
- Single line of code to access images
- Operates on disk, database, big-data file system
imageData =
imageDataStore(‘vehicles’)
Easily manage large sets of images
- Single line of code to access images
- Operates on disk, database, big-data file
system
Organize Images in Folders
(~ 10,000 images , 5 folders)
23
Augment Training Images
Rotation
Reflection
Scaling
Shearing
Translation
Colour pre-processing
Resize / Random crop / Centre crop
24
Training Deep Neural Networks
trainingOptions
▪ Plot training metrics
– Training accuracy, smoothed training
accuracy, validation accuracy
– Training loss, smoothed training loss,
and validation loss
▪ Debug training
– Stop and check current state
– Save / load checkpoint networks
– Custom output function (stopping
condition, visualization, etc.)
▪ Bayesian optimization for
hyperparameter tuning Learn More
25
Training in MATLAB is fast
MATLAB is more than 4x
faster than TensorFlow
AlexNet CNN architecture trained on the ImageNet dataset, using batch size of 32, on a Windows 10 desktop with single
NVIDIA GPU (Titan Xp). TensorFlow version 1.2.0.
26
Alexnet Inference on Intel CPUs
MATLAB
(R2017b Release 2)
TensorFlow
MXNet
Caffe2
27
Scaling Training on CPU, GPU, Multi-GPU and Clusters
More GPUs
MoreCPUs
28
Semantic Segmentation
Support for
▪ Fully convolutional networks
▪ SegNets
▪ U-Nets
and other directed acyclic graph
(DAG) networks
Learn More
Manage connections
▪ addLayers, removeLayers
▪ connectLayers, disconnectLayers
Manage label data and evaluate performance
▪ pixelLabelDatastore
▪ evaluateSemanticSegmentation
▪ jaccard,dice,bfscore
29
Perform Transfer Learning with 10 lines of MATLAB Code
Load Pre-Trained
Network
Replace Final
Layers
Train Network on
New Data
Load New
Training Data
Example Available Here
30
Import Pre-Trained Models and Network Architectures
Pretrained Models
▪ AlexNet
▪ VGG-16
▪ VGG-19
▪ GoogLeNet
▪ Resnet50
▪ InceptionV3
▪ Resnet101
Import Models from Frameworks
▪ Caffe Model Importer
(including Caffe Model Zoo)
– importCaffeLayers
– importCaffeNetwork
▪ TensorFlow-Keras Model Importer
– importKerasLayers
– importKerasNetwork
Download from within MATLAB
net = alexnet;
net = vgg16;
net = vgg19;
net = googlenet;
net = resnet50;
net = inceptionv3;
net = resnet101;
31
Visualizations for Understanding Network Behavior
▪ Custom visualizations
– Example: Class Activation Maps
Filters
…
Activations
Deep Dream
http://cnnlocalization.csail.mit.edu/Zhou_Learning_Deep_Features_CVPR_2016_paper.pdf
32
How can I create
ground truth?
Specify ground truth to train detector
Object Detector
Semantic Segmentation
Network
TrainingGround Truth
Images
33
Accelerating Ground Truth Labeling
Image Labeler App
– Sequence of images
- Bounding boxes, image pixels
Use automation algorithms
to accelerate labeling
34
Generate CUDA code and deploy CNNs with GPU Coder
Alexnet
Vehicle
Detection
People detection Lane detection
~30 Fps
(Tegra X1)
~66 Fps
(Tegra X1)
~20 Fps
(K40c)
~130 Fps
(K40c)
New Product: GPU Coder
▪ Portable and readable CUDA code
generation
▪ Eliminate manual coding errors
▪ Maintain Single “Truth”
▪ Stay within MATLAB at a higher level
35
Alexnet Inference on NVIDIA Titan Xp
MATLAB GPU Coder
(R2017b)
TensorFlow (1.2.0)
Caffe2 (0.8.1)
Framespersecond
Batch Size
CPU Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz
GPU Pascal Titan Xp
cuDNN v5
Testing platform
MXNet (0.10)
MATLAB (R2017b)
2x 7x5x
37
MATLAB Beyond the Desktop
Share Applications
Integrate with Web & Enterprise
Scale Computation Scale Data
38
Implement and Prototype Algorithms in Hardware
VHDL, Verilog
ASIC
FPGA
HDL
Coder
Programmable SoC
DSP / MCU
Embedded
Coder
C, C++
ROS Node
Robotics
System
Toolbox
CUDA
GPU
Coder
39
Resources to learn and get started mathworks.com/machine-learning
mathworks.com/deep-learning
mathworks.com/solutions/medical-devices.html
40
Deep Learning Onramp
Free Introductory Course
Available Here
41
Amod.Anandkumar@mathworks.in
@_Dr_Amod
080-6632-6000

Biomedical Signal and Image Analytics using MATLAB

  • 1.
    1© 2018 TheMathWorks, Inc. Biomedical Signal and Image Analytics Using MATLAB Dr. Amod Anandkumar Senior Team Lead – Signal Processing & Communications Application Engineering Group @_Dr_Amod
  • 2.
    2 What they say •Expand university programs • Train existing analysts
  • 3.
    3 The need fordata scientists Domain expertise Coding and integration skills Statistical and mathematical knowledge
  • 4.
    4 MATLAB lets yoube your own data scientist MATLAB is Designed and Documented to be Easy for Engineers and Scientists to Use “As a process engineer I had no experience with neural networks or machine learning. I worked through the MATLAB examples to find the best machine learning functions for generating virtual metrology. I couldn’t have done this in C or Python—it would’ve taken too long to find, validate, and integrate the right packages.” Emil Schmitt-Weaver, ASML “MATLAB enabled us, as geologists, to use our expertise in predictive frameworks, analytics, and analog matching to implement algorithms that are unique in our industry. With the help of MathWorks consultants, we then deployed those algorithms as an easy-to-use application to our colleagues worldwide.” Nick Howes, Shell
  • 5.
    5 Developing Motion AnalysisAlgorithms for Medical, Sports, and Occupational Safety Applications Challenge Accurately measure and track motion for medical, sports, and occupational safety applications Solution Develop motion-tracking algorithms in MATLAB and deploy them to a wearable, wireless motion analysis device with MATLAB Coder Results ▪ Time required to translate algorithms to production C code reduced from a month to a few days ▪ Development time reduced by 50% ▪ Defect-free code generated “With MATLAB and MATLAB Coder, we can respond quickly to customer requests. In a recent release, we updated two algorithm modules, created two new ones, and delivered all four with a confidence that would have been impossible using our old workflow.” Edgar Charry dorsaVi Link to article dorsaVi sensors in use in a running test.
  • 6.
    6 Challenge Develop and implementan acoustic respiratory monitoring system for wheeze detection and asthma management Solution Develop algorithms for detecting wheeze and ambient noise in MATLAB, and use MATLAB Coder to generate code from the algorithms for mobile devices and a web server Results ▪ Manual coding effort reduced ▪ Algorithm development iterations accelerated ▪ Code maintenance overhead reduced Respiri Develops Mobile App and Server Software for Wheeze Detection and Asthma Management “MATLAB enables us to rapidly develop, debug, and test sound- processing algorithms, and MATLAB Coder simplifies the process of implementing those algorithms in C. There’s no other environment or programming language that we could use to produce similar results in the same amount of time.” Mark Mulvey iSonea The AirSonea device, which connects to an asthma patient’s smartphone and communicates with wheeze analysis algorithms on iSonea’s server. Link to user story
  • 7.
    7 Data Analytics Workflow IntegratedAnalytic Systems Desktop Apps Enterprise Scale Systems Embedded Devices and Hardware Files Databases Sensors Raw Data Models and Algorithms Model Creation e.g. Machine Learning Model Validation Parameter Optimization Preprocessed Data Working with Messy Data Data Reduction/ Transformation Feature Extraction
  • 8.
    10 Today’s Examples ▪ Heartsound classification using machine learning ▪ MR image segmentation using deep learning ▪ Using visualizations for understanding CNN behaviour
  • 9.
    11 Heart Sound Classification– An Example ▪ Motivation – Heart sounds are complex signals – Require trained clinicians for diagnosis ▪ Objective – Develop algorithm for automatic classification of heart sounds ▪ Dataset – Training: 3240 recordings – Validation: 301 recordings – Recording Duration: 5 to 120 seconds – Labels: Normal or Abnormal Heart Sound Recording Classification Algorithm Normal Abnormal PhysioNet/CiC Challenge 2016 View Webinar
  • 10.
    12 Hyperparameter Tuning andFeature Selection Bayesian Optimization ▪ Tune hyperparameters of machine learning algorithms automatically ▪ Use bayesopt function for complete control. – Define objective function to be optimized. – Optimize under constraints you define. Neighbourhood Component Feature Selection ▪ Feature selection for classification (fscnca) or regression (fsrnca) ▪ Suitable for use before any classification or regression method ▪ Produces weights that go to 0 for irrelevant features ▪ Regularization parameter λ can be selected by cross-validation
  • 11.
    13 Wavelets for SignalProcessing and Feature Extraction ▪ Time-Scale Analysis is more robust and powerful ▪ Signal Morphology & Features can be extracted ▪ Excellent for pre- processing and feature engineering on signals Detrending ECG Signal Continuous Wavelet Transform of an ECG Signal
  • 12.
    14 Statistics & MachineLearning ▪ Use apps to interactively explore data, choose algorithms to train and validate models, and compare results – Classification Learner app – Regression Learner app ▪ Apply algorithms to out-of-memory data using tall arrays ▪ Generate C code for predictive models (requires MATLAB Coder) MATLAB makes machine learning easy and accessible for everyone, even if you’re not an expert “I would have never attempted machine learning if this app was not available.”
  • 13.
    15 Today’s Examples ▪ Heartsound classification using machine learning ▪ MR image segmentation using deep learning ▪ Using visualizations for understanding network behaviour
  • 14.
    17 Perform Object Detectionand Recognition using Deep Learning Deep Learning ▪ Convolutional Neural Networks ▪ Directed Acyclic Graph Networks ▪ Autoencoders ▪ Long Short-Term Memory Networks Computer Vision System Toolbox Neural Network Toolbox Parallel Computing Toolbox Object Detection ▪ Regions with CNN (R-CNN) ▪ Fast R-CNN ▪ Faster R-CNN Deep Learning … 𝟗𝟓% 𝟑%   𝟐% Truck Car ✓ Bicycle   Learned features End-to-end learning Feature learning + Classification
  • 15.
    18 Deep Learning Challenges ▪Accessing reference models from research ▪ Difficult to understand network behavior ▪ Tuning hyperparameters and refining architectures ▪ Training takes hours-days ▪ Labeling large sets of images ▪ Real world systems use more than deep learning – Deep learning frameworks do not include “classical” computer vision ▪ Deployment on embedded hardware ▪ Not a deep learning expert
  • 16.
    19 Convolutional Neural Network Convolution+ ReLU PoolingInput Convolution + ReLU Pooling … … Flatten Fully Connected Softmax dog … cat … … Feature Learning Classification goldfish✓  
  • 17.
    20 Classification vs/ Regressionv/s Detection v/s Semantic Segmentation HIGHWAY_SCENE Classification Car Car CarDetection Lane Lane Regression Semantic Segmentation
  • 18.
    21 Cardiac MR LeftVentricle Segmentation – An Example ▪ Motivation – Cardiac MR images are very complex – Require trained clinicians for manual segmentation ▪ Objective – Develop algorithm for automatic segmentation of left ventricle ▪ Dataset – Training Data: 260 images – Pixel Labels: LV or background LV Segmentation Challenge
  • 19.
    22 Access Large Setsof Images Handle Large Sets of Images Easily manage large sets of images - Single line of code to access images - Operates on disk, database, big-data file system imageData = imageDataStore(‘vehicles’) Easily manage large sets of images - Single line of code to access images - Operates on disk, database, big-data file system Organize Images in Folders (~ 10,000 images , 5 folders)
  • 20.
  • 21.
    24 Training Deep NeuralNetworks trainingOptions ▪ Plot training metrics – Training accuracy, smoothed training accuracy, validation accuracy – Training loss, smoothed training loss, and validation loss ▪ Debug training – Stop and check current state – Save / load checkpoint networks – Custom output function (stopping condition, visualization, etc.) ▪ Bayesian optimization for hyperparameter tuning Learn More
  • 22.
    25 Training in MATLABis fast MATLAB is more than 4x faster than TensorFlow AlexNet CNN architecture trained on the ImageNet dataset, using batch size of 32, on a Windows 10 desktop with single NVIDIA GPU (Titan Xp). TensorFlow version 1.2.0.
  • 23.
    26 Alexnet Inference onIntel CPUs MATLAB (R2017b Release 2) TensorFlow MXNet Caffe2
  • 24.
    27 Scaling Training onCPU, GPU, Multi-GPU and Clusters More GPUs MoreCPUs
  • 25.
    28 Semantic Segmentation Support for ▪Fully convolutional networks ▪ SegNets ▪ U-Nets and other directed acyclic graph (DAG) networks Learn More Manage connections ▪ addLayers, removeLayers ▪ connectLayers, disconnectLayers Manage label data and evaluate performance ▪ pixelLabelDatastore ▪ evaluateSemanticSegmentation ▪ jaccard,dice,bfscore
  • 26.
    29 Perform Transfer Learningwith 10 lines of MATLAB Code Load Pre-Trained Network Replace Final Layers Train Network on New Data Load New Training Data Example Available Here
  • 27.
    30 Import Pre-Trained Modelsand Network Architectures Pretrained Models ▪ AlexNet ▪ VGG-16 ▪ VGG-19 ▪ GoogLeNet ▪ Resnet50 ▪ InceptionV3 ▪ Resnet101 Import Models from Frameworks ▪ Caffe Model Importer (including Caffe Model Zoo) – importCaffeLayers – importCaffeNetwork ▪ TensorFlow-Keras Model Importer – importKerasLayers – importKerasNetwork Download from within MATLAB net = alexnet; net = vgg16; net = vgg19; net = googlenet; net = resnet50; net = inceptionv3; net = resnet101;
  • 28.
    31 Visualizations for UnderstandingNetwork Behavior ▪ Custom visualizations – Example: Class Activation Maps Filters … Activations Deep Dream http://cnnlocalization.csail.mit.edu/Zhou_Learning_Deep_Features_CVPR_2016_paper.pdf
  • 29.
    32 How can Icreate ground truth? Specify ground truth to train detector Object Detector Semantic Segmentation Network TrainingGround Truth Images
  • 30.
    33 Accelerating Ground TruthLabeling Image Labeler App – Sequence of images - Bounding boxes, image pixels Use automation algorithms to accelerate labeling
  • 31.
    34 Generate CUDA codeand deploy CNNs with GPU Coder Alexnet Vehicle Detection People detection Lane detection ~30 Fps (Tegra X1) ~66 Fps (Tegra X1) ~20 Fps (K40c) ~130 Fps (K40c) New Product: GPU Coder ▪ Portable and readable CUDA code generation ▪ Eliminate manual coding errors ▪ Maintain Single “Truth” ▪ Stay within MATLAB at a higher level
  • 32.
    35 Alexnet Inference onNVIDIA Titan Xp MATLAB GPU Coder (R2017b) TensorFlow (1.2.0) Caffe2 (0.8.1) Framespersecond Batch Size CPU Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz GPU Pascal Titan Xp cuDNN v5 Testing platform MXNet (0.10) MATLAB (R2017b) 2x 7x5x
  • 33.
    37 MATLAB Beyond theDesktop Share Applications Integrate with Web & Enterprise Scale Computation Scale Data
  • 34.
    38 Implement and PrototypeAlgorithms in Hardware VHDL, Verilog ASIC FPGA HDL Coder Programmable SoC DSP / MCU Embedded Coder C, C++ ROS Node Robotics System Toolbox CUDA GPU Coder
  • 35.
    39 Resources to learnand get started mathworks.com/machine-learning mathworks.com/deep-learning mathworks.com/solutions/medical-devices.html
  • 36.
    40 Deep Learning Onramp FreeIntroductory Course Available Here
  • 37.