labcom atyscrea - insa lyonsciolla/deeplearning/...labcom atyscrea segmentation d'images...

41
LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno Sciolla CREATIS – INSA Lyon [email protected]

Upload: others

Post on 14-Sep-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

LabCom AtysCrea

Segmentation d'images médicales IRM 3D par deep learning avec tensorflow

Journées scientifiques Python 2017

Bruno SciollaCREATIS – INSA Lyon

[email protected]

Page 2: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

A propos...

● Doctorat en physique théorique– Physique numérique

– Physique statistique

● CREATIS 2014-2017: Postdoc

Traitement d'images - Imagerie médicale:– Segmentation, modélisation et inférence statistique

– Deep learning

Page 3: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Plan

● Introduction à tensorflow et aux réseaux de neurones

● Réseaux de neurones convolutionels et segmentation sous Tensorflow

Page 4: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Librairies pour le deep learning (Python)

● Theano● PyTorch● Tensorflow● Keras (Tensorflow, Theano)● Lasagne (Theano)● …

Page 5: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

http://playground.tensorflow.org/

Démo en ligne : classification

Page 6: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

http://playground.tensorflow.org/

Démo en ligne : classification

Page 7: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Réseau de neurones

● Réseau classique feed-forward

● Fonction de coût – Moindres carrés (ou autres)

Page 8: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Implémentation

● Créer la base d'entrainement (tirage dynamique)● Définir le réseau● Définir la procédure d'entraînement● Entraîner le réseau

Page 9: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Préparatifs : construire une base d'entraînement

Page 10: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Implémentation

● Créer la base d'entrainement (tirage dynamique)● Définir le réseau● Définir la procédure d'entraînement● Entraîner le réseau

Page 11: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Définition du réseau (!)

Page 12: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Variables et placeholders

● Variables et placeholders = “Tenseurs” de taille arbitraire● Un placeholder est un conteneur qui est ensuite “alimenté”● Les autres variables sont initialisées par Tensorflow

Page 13: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Graphe de dépendance :

● Un graphe de dépendance est construit entre les variables :

x

W1

b1

y1

Page 14: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Graphe du problème de classification :

Références

Coût

Page 15: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Implémentation

● Créer la base d'entrainement (tirage dynamique)● Définir le réseau● Définir la procédure d'entraînement● Entraîner le réseau

Page 16: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Entraînement - Implémentation :

● Définition du coût (moindres carrés)● Définition de la méthode d'optimisation

Page 17: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Implémentation :

● Créer la base d'entrainement (tirage dynamique)● Définir le réseau● Définir la procédure d'entraînement● Entraîner le réseau

Page 18: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Entraînement :

Erreur moyenne : 0.021446

Page 19: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Implémentation

● Créer la base d'entrainement (tirage dynamique)● Définir le réseau● Définir la procédure d'entraînement● Entraîner le réseau● Observer les résultats

Page 20: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Résultats :

Page 21: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Résultats :

● Pourquoi on a utilisé Tensorflow ? Pourquoi pas seulement Numpy ?

● Au fait, on n'a jamais calculé de dérivées pour la descente de gradient...

Page 22: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Retour sur le graphe :

Références

Coût

Chaque variable (non placeholder) est optimisée par défaut

Page 23: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Calcul automatique de la dérivée

Seulement deux règles :● Chaque opérateur définit sa dérivée par rapport à ses

arguments :

● Règle de la dérivée en chaîne

Page 24: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Plan

● Introduction à tensorflow et aux réseaux de neurones

● Réseaux de neurones convolutionels et segmentation sous Tensorflow

Page 25: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Réseau de segmentation sémantique

● “Fully convolutional” / Convolutions à trous

(Long 2015)

Convolution à trous

Page 26: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Segmentation par deep learning

● COCO (Common Objects in Context) Challenge

● Réseaux résiduels– Réseaux très profonds (1000 layers)

– Notion de raccourcis

Page 27: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Implémenter un réseau de neurones convolutionnel :

Page 28: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Implémenter un réseau de neurones convolutionnel :

Page 29: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Segmentation de la prostate

● Segmentation de la zone de transition (ZT) et de la zone périphérique (ZP) dans des images IRM (T2) 3D de la prostate

Reférence Segmentation “base”

Page 30: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Segmentation de la prostate

● Réseau résiduel multiéchelle

Sciolla et al. CAp (Conf. Apprentissage automatique) 2017

Page 31: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Segmentation de la prostate

Page 32: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Où est la 3D ?

Yu, Heng 2017

Page 33: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

La difficulté des différentes tâches en apprentissage profond...

Construction de la base de données

Installer les librairies

Implémenter le réseau

Entraînement

● Pré-requis : comprendre les principes !

Page 34: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Aller plus loin avec Tensorflow

● Zoologie de modèles (RNN, LSTM, auto-encoders, GAN, ...)

● Enregistrer/Charger un modèle

● Contrôle de l'apprentissage (Tensorboard)

Page 35: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Aller plus loin avec Tensorflow

● Contrôle de l'apprentissage (Tensorboard)

Page 36: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Aller plus loin avec Tensorflow

● Calculs multi-coeurs et GPU

Page 37: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Conclusions

● Tensorwork est une librairie efficace et à jour● Mécanismes variables/placeholders● Auto-différentiation et apprentissage● Utiliser Keras pour les applications “usuelles”

Page 38: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno
Page 39: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Toy example: segmentation of the dermis

● Problem: Segment the epidermis and dermis layer in the skin● Use an automatic segmentation tools (level-set) to annotate 200 images =

18M labels

Page 40: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Toy example: segmentation of the dermis

● Fully convolutional network ● “Easy” problem: Training: 5 minutes, precision 95%)

n1=8; n2=16; n3 = 32; int1 = conv_layer3(x, [1,n1] , 1)int2 = conv_layer3(int1, [n1,n1] , 1)int3 = conv_layer3(int2, [n1,n1] , 1)int4 = conv_layer3(int3, [n1,n2] , 3)int5 = conv_layer3(int4, [n2,n2] , 3)int6 = conv_layer3(int5, [n2,n3] , 5)int7 = conv_layer3(int6, [n3,n3] , 7)int8 = conv_layer1(int7, [n3,32])int8b = tf.nn.dropout(int8, keep_prob)out_lay = conv_layer1(int8b, [32,3])out_soft = tf.nn.softmax(out_lay)

Page 41: LabCom AtysCrea - INSA Lyonsciolla/deeplearning/...LabCom AtysCrea Segmentation d'images médicales IRM 3D par deep learning avec tensorflow Journées scientifiques Python 2017 Bruno

Toy example: segmentation of the dermis

● Fully convolutional network ● “Easy” problem: Training: 5 minutes, precision 95%)

n1=8; n2=16; n3 = 32; int1 = conv_layer3(x, [1,n1] , 1)int2 = conv_layer3(int1, [n1,n1] , 1)int3 = conv_layer3(int2, [n1,n1] , 1)int4 = conv_layer3(int3, [n1,n2] , 3)int5 = conv_layer3(int4, [n2,n2] , 3)int6 = conv_layer3(int5, [n2,n3] , 5)int7 = conv_layer3(int6, [n3,n3] , 7)int8 = conv_layer1(int7, [n3,32] )int8b = tf.nn.dropout(int8, keep_prob)out_lay = conv_layer1(int8b, [32,3])out_soft = tf.nn.softmax(out_lay)