Batchgrootte en batchnormalisatie

Introductie tot Deep Learning met Keras

Miguel Esteban

Data Scientist & Founder

Introductie tot Deep Learning met Keras

Introductie tot Deep Learning met Keras

Mini-batches

Voordelen

  • Snellere training (meer gewichtsupdates in dezelfde tijd)
  • Minder RAM nodig, trainen op enorme datasets
  • Ruis kan helpen een lagere fout te bereiken, ontsnapt lokale minima

Nadelen

  • Meer iteraties nodig
  • Moet worden afgesteld; geschikte batchgrootte vinden
Introductie tot Deep Learning met Keras

1 Stack Exchange
Introductie tot Deep Learning met Keras

Batchgrootte in Keras

# Een al gebouwd en gecompileerd model trainen
model.fit(X_train, y_train, epochs=100, batch_size=128)
                                        ^^^^^^^^^^^^^^

Introductie tot Deep Learning met Keras

Introductie tot Deep Learning met Keras

Introductie tot Deep Learning met Keras

Introductie tot Deep Learning met Keras

Voordelen van batchnormalisatie

  • Verbetert de gradiëntenstroom
  • Maakt hogere learning rates mogelijk
  • Minder afhankelijk van gewichtsinitialisatie
  • Werkt onbedoeld als regularisatie
  • Beperkt interne covariateshift
Introductie tot Deep Learning met Keras

Batchnormalisatie in Keras

# BatchNormalization importeren uit keras.layers
from tensorflow.keras.layers import BatchNormalization

# Een Sequential-model aanmaken model = Sequential()
# Een invoerlaag toevoegen model.add(Dense(3, input_shape=(2,), activation = 'relu'))
# Batchnormalisatie toevoegen voor de outputs van de bovenstaande laag model.add(BatchNormalization())
# Een uitvoerlaag toevoegen model.add(Dense(1, activation='sigmoid'))
Introductie tot Deep Learning met Keras

Laten we oefenen!

Introductie tot Deep Learning met Keras

Preparing Video For Download...