SlideShare a Scribd company logo
1 of 37
Download to read offline
The	rod	of	Asclepios
Jan	Margeta	|	 |	jan@kardio.me	 @jmargeta
World	full	of
superpowers
Python	as	our
superpower?
Meet	Asclepios
Hi,	I	am	Jan
Pythonista	for	8	years
Founder	of	KardioMe
Maker	of	tools	to	better	understand	our	hearts
Python	3.5+,	numpy,	MxNet,	Keras,	Tensorflow,
scikit-learn,	SimpleITK,	pydicom,	Flask,	Sanic,
Django,	PostgreSQL,	ReactJS,	Docker
This	talk
Peek	into	our	hearts	with	medical	images
What	used	to	be	hard	is	now	magically	simple
Tricks	and	tools	for	machine	learning	in	Python
we've	learned	along	the	way
Imaging	of	our	hearts
X-Ray ultrasound fluoroscopy
computed	tomography magnetic	resonance
	
Kelly	2007
Carmo	et	al.	2010
Arnold	et	al.	2008
Foley	et	al.	2010
Vanezis	et	al.	2011
What	a	human
sees
What	a	human
sees
What	a	computer
sees
Machine	learning
Solving	problems	with	data
prediction	=	model.predict	(data)
Image	recognition
in	6	lines	of	code
from	keras.applications	import	imagenet_utils
from	keras.applications.vgg16	import	VGG16
#	Load	and	prepare	input	images
images_raw	=	load_images()
images	=	imagenet_utils.preprocess_input(images_raw)
#	Load	a	pretrained	image	classification	model
model	=	VGG16(include_top=True,	weights='imagenet')
#	Do	the	prediction
predictions	=	model.predict(images)
Convolutional
neural	networks
By	Aphex34
Finding	the	right	image
representation
Excellent	for	natural	images
Trained	on	Imagenet	large	scale	visual	recognition	challenge	dataset
10	million	images,	1000	categories
Extracting	visual	features
#	Load	a	pretrained	classification	model
source_model	=	VGG16(weights='imagenet')
#	Define	feature	extractor	from	one	layer	of	the	network
feature_layer	=	source_model.get_layer('conv4')
feature_extractor	=	Model(
		input=fix_model.input,
		output=feature_layer.output)
#	Extract	features
features	=	feature_extractor.predict(images)
See	also	"Deep	visualization	toolbox"	on	youtube
Using	the	extracted	features
with	scikit-learn
from	sklearn.svm	import	LinearSVC
def	flatten_features(features):
				return	features.reshape(len(features),	-1)
features_train	=	feature_extractor.predict(images_train)
features_train	=	flatten_features(features_train)
classifier	=	LinearSVC()
classifier.fit(features_train,	labels_train)
#	predict	on	never	seen	images
features_test	=	feature_extractor.predict(images_test)
features_test	=	flatten_features(features_test)
prediction_test	=	classifier.predict(features_test)
Example:	Cardiac	view
recognition
,	Joint	work	with	 	and	Margeta	et	al.	2015 Inria Microsoft	Research	Cambridge
Train	the	model
from	scratch
from	keras.models	import	Sequential
from	keras.layers	import	Conv2D,	Dense,	Flatten
images_train,	labels_train	=	load_data()
shape	=	(64,	64,	1)
model	=	Sequential([
				Conv2D(32,	(3,	3),	activation='relu',	input_shape=shape),
				MaxPooling2D(pool_size=(2,	2))
				Flatten(),
				Dense(4,	activation='softmax'),
])
#	Loss	function	-	task	dependent
#	high	for	bad	parameters,	low	for	good	ones
#	e.g.	for	image	recognition
loss_function	=	'sparse_categorical_crossentropy'
#	Compile	the	model	and	fit
model.compile(loss=loss_function,	optimizer='adam')
model.fit(images_train,	labels_train)
#	Save	the	model	for	reuse
model.save('model.h5')
Let's	save	some	time	for	our
radiologists
,	Joint	work	with	 	and	KardioMe Inria IHU	Liryc
Deploy	as	a	web
service
	
see	also	Tensorflow-serving	and	Kubernetes
Expose	the	model	with	Flask*
*do	not	run	in	production,	it	requires	a	bit	more	love	than	this
import	keras
from	flask	import	Flask,	jsonify,	request
app	=	Flask(__name__)
model	=	keras.models.load_model('model.h5')
@app.route('/predict',	methods=['POST'])
def	predict():
				image_batch	=	request_to_numpy(request)
				y	=	model.predict(image_batch)
				prediction	=	convert_prediction(y)
				return	jsonify(output=prediction)
app.run(port=5000,	threaded=False)
Run	with	the	same	conditions	as
when	it	was	built
Define	the	Dockerfile
FROM	python:3.5
RUN	mkdir	-p	/usr/src/app
COPY	server.py	/usr/src/app/
COPY	model.h5	/usr/src/app/
COPY	requirements.txt	/usr/src/app/
WORKDIR	/usr/src/app
RUN	pip	install	-r	requirements.txt
EXPOSE	5000
CMD	python	server.py
Build	the	Docker	container
Run	the	service
Call	the	service
docker	build	-t	kardiome/model-pyparis	.
docker	run	-d	-p	5000:5000	kardiome/model-pycon
curl	-X	POST	-F	'image=@/data/im.png'	localhost:5000/predict
Tips	to	improve
your	machine
learning	today
Iterate	fast
Minimally	viable	model
One	metric	to	rule	them	all
Training	progress	visualisation	in	Tensorboard
Visualize	everything
Built	with	Sanic	backend	(like	Flask)	and	React
Progress	with	confidence	and
repeatable	pipelines
Gitlab's	continuous	integration	is	an	excellent	start	for	simple	pipelines
(see	Airflow,	Luigi,	Joblib,	Flink)
No	glory	in	data
preparation
But	it	must	be	done
Having	a	small	dataset?
Do	something	about	it
https://affinelayer.com/pixsrv/
Got	unlabeled	data?
Don't	be	lazy,	just	annotate	it	if	you	can,	there
are	tools	to	help	you
See	 	in	Scikit-learn
,	Joint	work	with	 	and	Margeta	et	al.	2015 Inria Microsoft	Research	Cambridge
Label	Propagation	example
Be	practical
Have	an	open	mind
Overall	experience
Remarkable	ecosystem
Fantastic	community
Build	things	very	hard	before
★★★★★
Takeaways
Build	something	you	care	about
Poke	your	models	and	learn	from	them
Pick	your	superpower	and	have	fun
#	to	fly
import	antigravity
The	rod	of	Asclepios
Jan	Margeta	|	 |	
Thanks!
Python,	numpy,	MxNet,	Keras,	Tensorflow,	scikit-learn,	SimpleITK,	pydicom,	Flask,
Sanic,	Django,	PostgreSQL,	ReactJS,	Docker
Inria,	IHU	Liryc,	Microsoft	Research
jan@kardio.me	 @jmargeta

More Related Content

Similar to The rod of Asclepios: Machine learning in Python for cardiac image analysis, Jan Margeta

Neural Networks
Neural Networks Neural Networks
Neural Networks
Eric Su
 
II-SDV 2017: The Next Era: Deep Learning for Biomedical Research
II-SDV 2017: The Next Era: Deep Learning for Biomedical ResearchII-SDV 2017: The Next Era: Deep Learning for Biomedical Research
II-SDV 2017: The Next Era: Deep Learning for Biomedical Research
Dr. Haxel Consult
 
Internship - Python - AI ML.pptx
Internship - Python - AI ML.pptxInternship - Python - AI ML.pptx
Internship - Python - AI ML.pptx
Hchethankumar
 
Internship - Python - AI ML.pptx
Internship - Python - AI ML.pptxInternship - Python - AI ML.pptx
Internship - Python - AI ML.pptx
Hchethankumar
 

Similar to The rod of Asclepios: Machine learning in Python for cardiac image analysis, Jan Margeta (20)

Facial expression recognition projc 2 (3) (1)
Facial expression recognition projc 2 (3) (1)Facial expression recognition projc 2 (3) (1)
Facial expression recognition projc 2 (3) (1)
 
Ai for life sciences - are we ready
Ai for life sciences  - are we readyAi for life sciences  - are we ready
Ai for life sciences - are we ready
 
Value chain maps for open source ecosystems
Value chain maps for open source ecosystemsValue chain maps for open source ecosystems
Value chain maps for open source ecosystems
 
machine learning in the age of big data: new approaches and business applicat...
machine learning in the age of big data: new approaches and business applicat...machine learning in the age of big data: new approaches and business applicat...
machine learning in the age of big data: new approaches and business applicat...
 
Introduction to Deep learning
Introduction to Deep learningIntroduction to Deep learning
Introduction to Deep learning
 
Neural Networks
Neural Networks Neural Networks
Neural Networks
 
Designing a neural network architecture for image recognition
Designing a neural network architecture for image recognitionDesigning a neural network architecture for image recognition
Designing a neural network architecture for image recognition
 
Think Machine Learning with Scikit-Learn (Python)
Think Machine Learning with Scikit-Learn (Python)Think Machine Learning with Scikit-Learn (Python)
Think Machine Learning with Scikit-Learn (Python)
 
An introduction to AI (artificial intelligence)
An introduction to AI (artificial intelligence)An introduction to AI (artificial intelligence)
An introduction to AI (artificial intelligence)
 
"From IA to AI in Healthcare" - Walter De Brouwer (CEO/Founder, doc.ai/Scanadu)
"From IA to AI in Healthcare" - Walter De Brouwer (CEO/Founder, doc.ai/Scanadu)"From IA to AI in Healthcare" - Walter De Brouwer (CEO/Founder, doc.ai/Scanadu)
"From IA to AI in Healthcare" - Walter De Brouwer (CEO/Founder, doc.ai/Scanadu)
 
CIS AIML Beginners Series Part 1
CIS AIML Beginners Series Part 1CIS AIML Beginners Series Part 1
CIS AIML Beginners Series Part 1
 
II-SDV 2017: The Next Era: Deep Learning for Biomedical Research
II-SDV 2017: The Next Era: Deep Learning for Biomedical ResearchII-SDV 2017: The Next Era: Deep Learning for Biomedical Research
II-SDV 2017: The Next Era: Deep Learning for Biomedical Research
 
Data Science.pptx
Data Science.pptxData Science.pptx
Data Science.pptx
 
Internship - Python - AI ML.pptx
Internship - Python - AI ML.pptxInternship - Python - AI ML.pptx
Internship - Python - AI ML.pptx
 
Internship - Python - AI ML.pptx
Internship - Python - AI ML.pptxInternship - Python - AI ML.pptx
Internship - Python - AI ML.pptx
 
Transfer Leaning Using Pytorch synopsis Minor project pptx
Transfer Leaning Using Pytorch  synopsis Minor project pptxTransfer Leaning Using Pytorch  synopsis Minor project pptx
Transfer Leaning Using Pytorch synopsis Minor project pptx
 
Python for Data Science with Anaconda
Python for Data Science with AnacondaPython for Data Science with Anaconda
Python for Data Science with Anaconda
 
Introduction to Deep Learning
Introduction to Deep LearningIntroduction to Deep Learning
Introduction to Deep Learning
 
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Python for Science and Engineering: a presentation to A*STAR and the Singapor...Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 

More from Pôle Systematic Paris-Region

More from Pôle Systematic Paris-Region (20)

OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
 
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...
 
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...
 
OSIS19_Cloud : Performance and power management in virtualized data centers, ...
OSIS19_Cloud : Performance and power management in virtualized data centers, ...OSIS19_Cloud : Performance and power management in virtualized data centers, ...
OSIS19_Cloud : Performance and power management in virtualized data centers, ...
 
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
 
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...
 
OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...
OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...
OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...
 
Osis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick Moy
Osis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick MoyOsis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick Moy
Osis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick Moy
 
Osis18_Cloud : Pas de commun sans communauté ?
Osis18_Cloud : Pas de commun sans communauté ?Osis18_Cloud : Pas de commun sans communauté ?
Osis18_Cloud : Pas de commun sans communauté ?
 
Osis18_Cloud : Projet Wolphin
Osis18_Cloud : Projet Wolphin Osis18_Cloud : Projet Wolphin
Osis18_Cloud : Projet Wolphin
 
Osis18_Cloud : Virtualisation efficace d’architectures NUMA
Osis18_Cloud : Virtualisation efficace d’architectures NUMAOsis18_Cloud : Virtualisation efficace d’architectures NUMA
Osis18_Cloud : Virtualisation efficace d’architectures NUMA
 
Osis18_Cloud : DeepTorrent Stockage distribué perenne basé sur Bittorrent
Osis18_Cloud : DeepTorrent Stockage distribué perenne basé sur BittorrentOsis18_Cloud : DeepTorrent Stockage distribué perenne basé sur Bittorrent
Osis18_Cloud : DeepTorrent Stockage distribué perenne basé sur Bittorrent
 
Osis18_Cloud : Software-heritage
Osis18_Cloud : Software-heritageOsis18_Cloud : Software-heritage
Osis18_Cloud : Software-heritage
 
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
 
OSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riot
OSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riotOSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riot
OSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riot
 
OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...
OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...
OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...
 
OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...
OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...
OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...
 
OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...
OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...
OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...
 
OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)
OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)
OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)
 
PyParis 2017 / Un mooc python, by thierry parmentelat
PyParis 2017 / Un mooc python, by thierry parmentelatPyParis 2017 / Un mooc python, by thierry parmentelat
PyParis 2017 / Un mooc python, by thierry parmentelat
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 

The rod of Asclepios: Machine learning in Python for cardiac image analysis, Jan Margeta