33
Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut

Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

Convolutional Neural NetworksDozent: Dr. Zoran Nikolić

Machine Learning Seminar

Julia OdenthalMathematisches Institut

Page 2: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

2/33

Gliederung

▪ Der Convolution Operator

▪ Eigenschaften eines Convolutional Neural Network (CNN)

▪ Aufbau eines CNN

▪ Pooling-Layer

▪ Anwendung in Python

Page 3: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

3/33

Anwendung

▪ Bilderkennung

➢ Autonomes Fahren (Klassifizierung der Verkehrszeichen)

➢ Gesichts- und Objekterkennung

▪ Spracherkennung

➢ Klassifizierung und Modellierung von Sätzen

➢ Maschinelles Übersetzen

Page 4: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

4/33

Motivation

1000

1000

▪ 106 ∗ 105 = 1011 = 100 Milliarden Kanten/Gewichte

▪ Deep Learning: Vielfache

▪ Hoher Trainingsaufwand

Input Bild

1 Mio. Inputs

Input Hidden Layer

⁞⁞

100.000 Neuronen

⁞ ⁞ ⋯

Page 5: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

5/33

Convolution NetworkDefinition

▪ Convolutional Neuronal Network (CNN)

▪ Spezielle Form von neuronalen Netzen für Daten mit Gittertopologie

▪ Lokal verbundenes Netz

▪ Convolution (Faltung) statt Matrixmultiplikation

⋯ ⋯

Page 6: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

6/33

Grober Aufbau

Input Bild

Convolution Layer

Hidden Layer Output

⁞⁞ ⁞⁞ ⋯

Page 7: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

7/33

Convolution NetworkDer Convolution Operator

▪ Faltung auf zwei reellen Funktionen

𝑠 𝑡 = 𝑥 ∗ 𝑤 (𝑡) = න𝑥 𝑎 𝑤 𝑧 − 𝑎 ⅆ𝑎

▪ x = Input, w = Kern, s = Output = Feature Map

▪ In Praxis ist die Zeit meistens diskretisiert

𝑠 𝑡 = 𝑥 ∗ 𝑤 𝑡 =

𝑎=−∞

𝑥 𝑎 𝑤(𝑧 − 𝑎)

Page 8: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

8/33

Convolution NetworkDer Convolution Operator

▪ In Anwendungen mehrdimensionale Arrays als Input und Kern

𝑆 𝑖, 𝑗 = 𝐼 ∗ 𝐾 𝑖, 𝑗 =

𝑚

𝑛

𝐼 𝑚, 𝑛 𝐾(𝑖 − 𝑚, 𝑗 − 𝑛)

▪ Convolution Operator ist kommutativ

𝑆 𝑖, 𝑗 = 𝐾 ∗ 𝐼 𝑖, 𝑗 =

𝑚

𝑛

𝐼 𝑖 − 𝑚, 𝑗 − 𝑛 𝐾(𝑚, 𝑛)

▪ Cross-Correlation

𝑆 𝑖, 𝑗 = 𝐾 ∗ 𝐼 𝑖, 𝑗 =

𝑚

𝑛

𝐼 𝑖 + 𝑚, 𝑗 + 𝑛 𝐾(𝑚, 𝑛)

Page 9: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

10/33

𝑎 𝑏 𝑐 ⅆ

𝑒 𝑓 𝑔 ℎ

𝑖 𝑗 𝑘 𝑙

𝑎𝑤 + 𝑏𝑥+ 𝑒𝑦 + 𝑓𝑧

𝑏𝑤 + 𝑐𝑥+ 𝑓𝑦 + 𝑔𝑧

𝑐𝑤 + ⅆ𝑥+ 𝑔𝑦 + ℎ𝑧

𝑒𝑤 + 𝑓𝑥+ 𝑖𝑦 + 𝑗𝑧

𝑓𝑤 + 𝑔𝑥+ 𝑗𝑦 + 𝑘𝑧

𝑔𝑤 + ℎ𝑥+ 𝑘𝑦 + 𝑙𝑧

Input

𝑤 𝑥

𝑦 𝑧

Kern

Output

Funktionsweise der Convolution

𝐼 ∈ 𝕂𝑚×𝑛, 𝐾 ∈ 𝕂𝑘×𝑘

𝐾 ∗ 𝐼 ∈ 𝕂(𝑚−𝑘+1)×(𝑛−𝑘+1)

𝐼 ∈ 𝕂3×4, 𝐾 ∈ 𝕂2×2

𝐾 ∗ 𝐼 ∈ 𝕂2×3

Page 10: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

12/33

10 10 10 0 0 0

10 10 10 0 0 0

10 10 10 0 0 0

10 10 10 0 0 0

10 10 10 0 0 0

10 10 10 0 0 0

1 0 -1

1 0 -1

1 0 -1

0 30 30 0

0 30 30 0

0 30 30 0

0 30 30 0

Input 𝐼

Kern 𝐾

𝐾 ∗ 𝐼

Output S

𝑆 1,1 =

𝑚=−1

1

𝑛=−1

1

𝐼 1 + 𝑚, 1 + 𝑛 𝐾 𝑚, 𝑛

= 10 + 10 + 10 + 0 + 0 + 0 − 10 − 10 − 10 = 0

Kern hat Filterfunktion

Page 11: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

13/33

Page 12: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

14/33

Ermittlung der GewichteBackpropagation

▪ Kern Matrix ist nicht vorgegeben → muss gelernt werden

▪ Weniger Gewichte zu lernen als in einem normalen NN

▪ Mittels Backpropagation mit Nebenbedingung

𝑤1 𝑤4 𝑤7𝑤2 𝑤5 𝑤8

𝑤3 𝑤6 𝑤9𝑤2 = 𝑤5 = 𝑤8

𝑤1 = 𝑤4 = 𝑤7

𝑤3 = 𝑤6 = 𝑤9

Page 13: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

15/33

Erweiterungen

Padding:

▪ Hinzufügen eines Randes aus Nullen

→Beibehalten der Größe

Strided Convolution:

▪ Größere Schritte des Kerns über die Input Matrix

→Kleinerer Output

▪ 𝑠 = Größe der Schritte

0 0 0 0 0

0 0

0 0

0 0

0 0 0 0 0

Page 14: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

16/33

Eigenschaften eines CNN Sparse Interactions

NN:

▪ Matrixmultiplikation

▪ Gewicht beschreibt Interaktion zwischen Output und Input

▪ Jeder Output interagiert mit jeder Input Einheit

CNN:

▪ Kern kleiner als Input

▪ Weniger Operationen zur Berechnung des Outputs

▪ Reduziert Speicherbedarf

▪ Verbesserungen der Effizienz

Page 15: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

17/33

Sparse InteractionsCNN vs. NN

s1 s2 s3 s4 s5

x1 x2 x3 x4 x5

s1 s2 s3 s4 s5

x1 x2 x3 x4 x5Input

Output

Page 16: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

18/33

Sparse InteractionsDeeper Layer

s1 s2 s3 s4 s5

h1 h2 h3 h4 h5

x1 x2 x3 x4 x5

▪ Tiefere Schichten können indirekt mit fast dem ganzen Input Bild verbunden sein

Page 17: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

19/33

Eigenschaften eines CNNGewichts Sharing

NN:

▪ Jedes Element der Gewichtsmatrix wird genau einmal benutzt um den Output der Schicht zu berechnen

▪ Multipliziert ein Element aus dem Input

➢Danach nie wieder benutzt

CNN:

▪ Jeder Eintrag des Kerns wird an jeder Position des Inputs benutzt (außer an den Randpixeln)

▪ Ein Set Gewichte lernen statt ein separates für jede Stelle

Page 18: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

20/33

Gewichts SharingCNN vs. NN

s1 s2 s3 s4 s5

x1 x2 x3 x4 x5

s1 s2 s3 s4 s5

x1 x2 x3 x4 x5Input

Output

Page 19: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

21/33

280

320

280

319

Input Output

Kern: −1 1

▪ 280*320*3 ≈300.000 Operationen ▪ 280*320*280*319 ≈8 Bio. Operationen

Effizienz eines CNN

Page 20: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

22/33

Aufbau eines CNN

3 Layer:

▪ Convolution Layer : Mehrere Convolution-Operatoren um eine Reihe von linearen Aktivierungen zu erzeugen

▪ Detector Layer: Jede lineare Aktivierung geht durch eine nichtlineare Aktivierungs Funktion, zB: ReLu

▪ Pooling Layer

Page 21: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

23/33

28 × 28

24 × 24 (× 32)

12 × 12 (× 32)8 × 8 (× 64)

4 × 4 (× 64)

Convolution+ReLu Pooling Convolution+ReLu Pooling Voll verbunden

6⋱

⋱ ⋱ ⋱

Aufbau

10 × 1

Page 22: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

24/33

Convolution Layer

▪ Anwendung des ConvolutionOperators

▪ Mehrere Convolution Operatoren um eine Reihe von linearen Aktivierungen zu erzeugen

▪ Output dreidimensional

28 × 28

24 × 24 (× 32)

Convolution+ReLu

Page 23: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

25/33

Mehrdimensionale Convolution

Input Tiefe

k

k

# Filter

Input

Höhe

Input

Convolution Output

Page 24: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

26/33

Detector Layer

35 5 70 -10

1 -2 90 23

4 48 -44 87

-30 51 15 3

ReLu

35 5 70 0

1 0 90 23

4 48 0 87

0 51 15 3

▪ Verwendet als Aktivierungsfunktion häufig ReLu mit f x = max(0, 𝑥)

Page 25: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

27/33

▪ Häufig: Max Pooling (Maximum in Umgebung), 𝐿2 Norm

Pooling Layer

1 4

9 3

6 5

1 0

6 2

4 7

8 4

0 1

9 6

7 8

Max-Pooling (2×2)

▪ Ersetzt den Output des Netzes an einer bestimmten Stelle durch eine zusammenfassende Statistik der benachbarten Outputs

▪ Reduziert die Dimension

▪ Reduziert auf wesentliche Informationen

Page 26: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

28/33

Pooling Layer

▪ Erhöht Rechenleistung

▪ Meistens: 2 × 2 Pooling ohne Überlappung → Bei größerem Pooling gehen häufig zu viele Informationen verloren

▪ Es müssen keine Gewichte gelernt werden

▪ Kontrolle von Overfitting

28 × 28

24 × 24 (× 32)

12 × 12 (× 32)

Convolution+ReLu Pooling

⋱⋱

Page 27: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

29/33

Invarianz der Pooling LayerAm Beispiel Max Pooling

1 1 1 0.2

0.1 1 0.2 0.1

0.3 1 1 1

0.3 0.1 1 0.2Input

Output

▪ Invariant gegenüber kleinen Verschiebungen im Input

Page 28: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

30/33

Aufbau ProgrammCNN in Python

▪ MNIST Datensatz

▪ Keras in Python

Page 29: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

31/33

Auswertung ProgrammCNN in Python

Trainingsgenauigkeit: 99,78% Testgenauigkeit: 99,18%

Page 30: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

32/33

Auswertung ProgrammCNN in Python

Modell Trainingsgenauigkeit Testgenauigkeit

CNN: 1 CNN Layer 99,92% 98,98%

CNN: 2 CNN Layer 99,78% 99,18%

CNN: 3 CNN Layer 99,71% 97,61%

NN: 1 Hidden Layer 99,72% 98,18%

NN: 2 Hidden Layer 99,23% 97,35%

NN: 6 Hidden Layer 99,41% 97,75%

Page 31: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

33/33

Zusatz: RGB Bild

▪ Bisher: Input Bild der Größe Höhenpixel × Breitenpixel

▪ Damit können nur Schwarz weiß Bilder dargestellt werden

▪ Buntes Bild hat pro Pixel 3 Werte:

R G B Farb-Beispiel

255 165 000

164 211 238

154 205 050

164

211

238

Größe Input = Höhe × Breite × 3

Kern hat Dimension 𝑘 × 𝑘 × 3

R

G

B

Page 32: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

34/33

Fazit

▪ State-of-the-art in Bild- und Audioverarbeitung

▪ Fehlerraten: Teilweise besser als Mensch

▪ Mit Grafikprozessoren lassen sich CNN sehr effizient trainieren

▪ Vorteile CNN:

➢ Robustheit

➢ Weniger Speicherplatzbedarf

➢ Einfacheres und besseres Training

Page 33: Convolutional Neural Networks€¦ · Convolutional Neural Networks Dozent: Dr. Zoran Nikolić Machine Learning Seminar Julia Odenthal Mathematisches Institut. 2/33 Gliederung Der

35/33

Literatur

▪ [AH] H. Aghdam, E. Heravi. Guide to Convolutional Neural Networks, Springer, 2017

▪ [GBC] I. Goodfellow, Y. Bengio, A. Courville. Deep Learning, MIT Press, 2016, http://www.deeplearningbook.org

▪ [QV] Quoc V Le et al. A tutorial on deep learning part 2: Autoencoder, convolutionalneural networks and recurrent neural networks, Google Brain, 2015, http://https://cs.stanford.edu/~quocle/tutorial2.pdf