28
Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

PrácticaIIIntel&MobileODTCervicalCancerScreeningSISTEMASINTELIGENTESPARALAGESTIÓNDELAEMPRESACURSO2016-2017

Page 2: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

Competiciónhttps://www.kaggle.com/c/intel-mobileodt-cervical-cancer-screening

Identificacióndeltipofisionómicodelacérvixfemenina(parteinferiordelútero),conelpropósitodeestablecereltratamientopreventivooinicialmásadecuadoparacurarelcáncerdeútero.

SeutilizanimágenesimágenesobtenidasconelsistemaEVA(Enhanced VisualAssessment) deMobileODT.

Introducción(python):https://www.kaggle.com/philschmidt/intel-mobileodt-cervical-cancer-screening/cervix-eda-model-selection

2

Page 3: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

CompeticiónEvaluación◦ Función𝑙𝑜𝑔𝑙𝑜𝑠𝑠

𝑙𝑜𝑔𝑙𝑜𝑠𝑠 = −1𝑁))𝑦+,log(𝑝+,)

4

,56

7

+56𝑁:Númerodeimágenesenelconjuntodevalidación

𝑀:Númerodecategorías

𝑙𝑜𝑔:Logaritmonatural(base𝑒)

𝑦+,:1silaobservación𝑖 pertenecealaclase𝑗 ;0sino

𝑝+,:probabilidaddequelaobservación𝑖 pertenezcaalaclase𝑗; cumple∀𝑖 = 1,… ,𝑁 ∶ ∑ 𝑦+, = 14,56

◦ Estaformulaciónde𝑙𝑜𝑔𝑙𝑜𝑠𝑠 sólocuentaenelsumatoriolasprobabilidadesasignadasacadainstanciadeperteneceralaclasecorrecta◦ Sepenalizanmuchoasignarvaloresbajosdeprobabilidadalaclasecorrecta(falsosnegativos)

◦ Unclasificadorperfectotendrá𝑙𝑜𝑔𝑙𝑜𝑠𝑠 = 0

3

Page 4: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

Competición

4

Evaluación

𝒑𝒊,𝟏 𝒑𝒊,𝟐 𝒑𝒊,𝟑Imagen 1 0.23 0.52 0.25

Imagen2 0.70 0.15 0.15

Imagen3 0.35 0.25 0.40

= − 67∑ ∑ 𝑦+,log(𝑝+,)4

,567+56

= −13× log 0.23 + log 0.70 + log 0.40

= −13× −1.47 − 0.357 − 0.92

= 0.9156

𝑙𝑜𝑔𝑙𝑜𝑠𝑠

Page 5: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

Aproximacionesalaclasificacióndeimágenes1. Codificacióndirecta

5

0 0 0 0 032

32

0 0 0 0 0…

1024

Multi-clasificador

Lan,Y.,Lean,L.Handwritten digit recognition using perceptron neuralnetworks.URL:http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.27.9135&rep=rep1&type=pdf

Page 6: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

Aproximacionesalaclasificacióndeimágenes2. Pre-procesamientoyextraccióndecaracterísticas

6

Multi-clasificador

Densidaddepíxeles

Alimoglu,F.,Alpaydin,E.Combining multiple representations andclassifiers for pen-based handwrittendigit recognition.URL:http://ieeexplore.ieee.org/document/620583/?reload=true&section=abstract

Detectordebordes

Detectordelíneas

Page 7: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

Aproximacionesalaclasificacióndeimágenes3. Redesneuronalesconvolucionales (convolutional neuralnetworks,CNN)

http://cs231n.github.iohttps://adeshpande3.github.io/adeshpande3.github.io/A-Beginner%27s-Guide-To-Understanding-Convolutional-Neural-Networks/

7

Page 8: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

ArquitecturadeunaCNN

1. INPUT(entrada)

2. CONV(convolución)

3. RELU(activación)

4. POOL(reduccióndedimensionalidad)

5. FC(totalmenteconectada)

8

Page 9: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

EstrategiasSoloCNNs◦ 3.1.ConfigurarCNNdesdeelprincipio◦ 3.2.Utilizarunaredyaentrenada◦ 3.3.Transferlearning /finetuning

CNNs +otrosclasificadores◦ 3.4.Extraccióndecaracterísticasconredyaentrenada◦ 3.5.Extraccióndecaracterísticasconredpropia(desdeelprincipioofinetuning)

>> Aplicarpre-procesamiento:dataaugmentation

>> Creacióndeensembles

>>Multiclasificación:one vsone,one vsall

9

Page 10: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

IntelDeepLearning SDK(3.1,3.2.3.3)https://www.kaggle.com/c/intel-mobileodt-cervical-cancer-screening#Intel-Tutorial◦ IntelDeepLearning SDK1.0

◦ Requisitos:OSX=>Docker 1.12+,noVirtualBox < 4.3.30https://software.intel.com/sites/default/files/managed/ef/08/Intel_Deep_Learing_SDK_Training_Tool_Installation_Guide.pdf

◦ Descarga:https://software.intel.com/en-us/deep-learning-sdk/documentation

◦ Instalación:admin /passwordhttp://localhost:8080/#/main/home

10

Page 11: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

IntelDeepLearning SDK(3.1,3.2.3.3)

11

Page 12: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

IntelDeepLearning SDK(3.1,3.2.3.3)

12

Pre-procesamientoRedimensionadoDataaugmentation…

https://consigna.ugr.es/g/QBhkP8vloBl2evp4/all_data_resized.zip

Page 13: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

IntelDeepLearning SDK(3.1,3.2.3.3)

13

TransferlearningTopologíasFinetuning…

Page 14: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

IntelDeepLearning SDK(3.1,3.2.3.3)

14

TransferlearningGrabarmodelo

Page 15: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

IntelDeepLearning SDK(3.1,3.2.3.3)

15

Page 16: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

IntelDeepLearning SDK(3.1,3.2.3.3)

16

docker exec -t -i trainingtool-js /bin/bash

cat /workspace/dlsdk/jobs/caffe/models/<model id>/data_exploration.txt

◦ model.zip◦ caffe.log : Logdeejecucióndelprocesodeaprendizaje◦ deploy.protoxt : Modeloparainferencia◦ solver.protoxt : Configuracióndeaprendizaje◦ train_val.protoxt : Modelo+datosdeentrenamientoyvalidación◦ train_test.protoxt : Modelo+datosdeentrenamientoytest◦ train.txt : Etiquetasconjuntodeentrenamiento◦ val.txt : Etiquetasconjuntodevalidación

Page 17: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

MXNET(3.1,3.2.3.3,¿3.4,3.5?)MXNEThttp://mxnet.io◦ BibliotecaparaDeepLearning conimplementaciónparaC++,Python,R,Scala,etc.◦ Alternativaaotrasbibliotecas:Tensorflow (Google),Caffe (Berkely AILab)

◦ mx.symbol.Variable:Crearcapadeentrada◦ mx.symbol.Convolution:CrearcapaCONV◦ mx.symbol.Activation:CrearcapaRELU◦ mx.symbol.Pooling:CrearcapaPOOL◦ mx.symbol.FullyConnected:CrearcapaFC◦ mx.symbol.SoftmaxOutput:Crearcapadesalida

◦ mx.model.FeedForward.create :Aprendermodelo

17

Page 18: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

MXNET (3.1,3.2.3.3,¿3.4,3.5?)MXNEThttp://mxnet.io/tutorials/index.html#r

◦ MXNETparaMNISTmxnet-MNIST.R

◦ MXNETparaCervix +Pre-procesado:(3.1)◦ Blancoynegro

mxnet-cervix-bn.R

◦ Colormxnet-cervix-color.R

◦ ClasificacióndeimágenesconMXNETutilizandomodelospre-entrenados(3.2)◦ https://github.com/dmlc/mxnet/blob/master/R-package/vignettes/classifyRealImageWithPretrainedModel.Rmd

◦ ClasificacióndeimágenesconMXNETutilizandomodelospre-entrenadosyfinetuning (3.3)◦ https://statist-bhfz.github.io/cats_dogs_finetune (Punto4enadelante)

18

Page 19: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

Otros(3.1,3.2.3.3,3.4,3.5)https://deeplearning4j.org/compare-dl4j-torch7-pylearn

◦ Tensorflow◦ https://www.tensorflow.org

◦ https://www.tensorflow.org/tutorials/image_retraining

◦ Caffe◦ http://caffe.berkeleyvision.org

◦ http://adilmoujahid.com/posts/2016/06/introduction-deep-learning-python-caffe/

◦ Keras◦ https://github.com/fchollet/keras

◦ https://flyyufelix.github.io/2016/10/08/fine-tuning-in-keras-part2.html

19

Page 20: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

Pre-procesamientodeimágenesenREBImagehttps://bioconductor.org/packages/release/bioc/vignettes/EBImage/inst/doc/EBImage-introduction.html◦ Bibliotecaparaprocesamientodeimágenes◦ Orígenesenprocesamientodeimágenesdecélulasobtenidasconmicroscopios

◦ Operaciones◦ Lectura◦ Visualizacióndepropiedades◦ Gestióndeespaciosdecolor◦ Manipulación:negativo,filtradoporumbral◦ Transformaciones:traslación,rotación,redimensión,deformación◦ Filtrados:gaussiano,deteccióndebordes,eliminaciónderuido◦ Operacionesmorfológicas:erosión,dilatación◦ Segmentación◦ Manipulación:borrado,rellenado,iluminación

Alternativas:imager

20

Page 21: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

ExtraccióndecaracterísticasCNN+otrosclasificadoresutilizandofeature mapsLasfeature maps puedenvenirdeunmodelopre-entrenado(porejemplo,conImageNET)[3.4]odeunmodelopropio(idealmente,confinetuning)[3.5]

21

Multi-clasificador

Featuremap

s

Page 22: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

MicrosoftR(3.4)(previamenteRevolution R)https://blogs.msdn.microsoft.com/rserver

◦ ExtensióndeR◦ IntegraciónconplataformaMicrosoft

◦ RToolsfor VisualStudio(https://www.visualstudio.com/es/vs/rtvs/)◦ MicrosoftML (https://msdn.microsoft.com/en-us/microsoft-r/microsoftml-introduction)◦ Azure MachineLearning (https://docs.microsoft.com/es-es/azure/machine-learning/)◦ Alteryx (https://www.r-bloggers.com/using-microsoft-r-with-alteryx/)

◦ Herramientasgratuitas◦ MicrosoftROpen(https://msdn.microsoft.com/en-us/microsoft-r/r-open)◦ MicrosoftRClient (https://msdn.microsoft.com/en-us/microsoft-r/r-client-get-started) [Windows64-bits,Linux]◦ MicrosoftRServer(https://msdn.microsoft.com/en-us/microsoft-r/rserver)

◦ UsoconRStudio◦ MicrosoftRClient +RStudio (https://msdn.microsoft.com/en-us/microsoft-r/r-client-get-started>Step 2:ConfigureYour IDE)

22

Page 23: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

MicrosoftR (3.4)MicrosoftML (https://msdn.microsoft.com/en-us/microsoft-r/microsoftml/microsoftml)◦ Algoritmosdeaprendizajeautomático

◦ rxFastTrees◦ rxFastForest◦ rxNeuralNet◦ rxLogisticRegression◦ rxEnsemble

◦ Transformacionesdedatos:◦ Crearpipeline contransformacionesdelosdatos

◦ concat◦ loadImage◦ resizeImage◦ extractPixels◦ Extracciónautomáticadecaracterísticas

◦ featurizeImage

◦ Predicción:◦ rxPredict

23

Page 24: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

24

Page 25: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

MicrosoftR (3.4)

Extraccióndecaracterísticasconmodelopre-entrenado(nofinetuning)https://blogs.msdn.microsoft.com/rserver/2017/04/12/image-featurization-with-a-pre-trained-deep-neural-network-model/

rxFeaturize (https://msdn.microsoft.com/en-us/microsoft-r/microsoftml/packagehelp/rxfeaturize)◦ data◦ outData◦ overwrite◦ mlTransforms

◦ loadImage◦ resizeImage◦ extractPixels◦ featurizeImage (https://msdn.microsoft.com/en-us/microsoft-r/microsoftml/packagehelp/featurizeimage)

◦ dnnModel {resnet18,resnet50,resnet101,alexnet}

25

Page 26: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

MicrosoftR (3.4)

Algunastopologías+pre-entrenamientoconImageNetResNet (Microsoft)K.He,X.Zhang,S.Ren,J.Sun (2015)DeepResidualLearning for Image Recognition.URL:https://arxiv.org/abs/1512.03385

◦ ResNet-18(input:224x224,features:512)◦ ResNet-50(input:224x224,features:2048)[link]◦ ResNet-101(input:224x224,features:2048)[link]

AlexNet (University ofToronto)A.Krizhevsky,I.Sutskever,G.E.Hinton (2012)ImageNet Classification with DeepConvolutional NeuralNetworks.URL:http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks

◦ AlexNet (input:227x227,features:4096)

Más:https://adeshpande3.github.io/adeshpande3.github.io/The-9-Deep-Learning-Papers-You-Need-To-Know-About.html

26

Page 27: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

MicrosoftR (3.4)

Resultado

27

Multi-clasificador

Featuremap

s

Featurize-Cervix.R DeepLearning-Cervix_Classification.R

Page 28: Clasificacion de imagenes en R - sci2s.ugr.es · Práctica II Intel & Mobile ODT Cervical Cancer Screening SISTEMAS INTELIGENTES PARA LA GESTIÓN DE LA EMPRESA CURSO 2016-2017

MXNET (3.1,3.2.3.3,3.4,3.5)

MXNEThttp://mxnet.io/tutorials/index.html#rmodel$symbol$get.internals():Obtenerfeatures (https://github.com/dmlc/mxnet/issues/2785)

EjemploenPython:

◦ https://github.com/dmlc/mxnet-notebooks/blob/master/python/how_to/predict.ipynb (Extract features)

28