バッチサイズとバッチ正規化

Kerasで学ぶIntroduction to Deep Learning

Miguel Esteban

Data Scientist & Founder

Kerasで学ぶIntroduction to Deep Learning

Kerasで学ぶIntroduction to Deep Learning

ミニバッチの利点・欠点

利点

  • 学習が速い(同時間内の重み更新が増える)
  • 必要メモリが少なく、大規模データでも学習可
  • ノイズが局所最小からの脱出を助け、誤差低減

欠点

  • 反復回数が増える
  • 調整が必要。適切なバッチサイズを探す必要がある
Kerasで学ぶIntroduction to Deep Learning

1 Stack Exchange
Kerasで学ぶIntroduction to Deep Learning

Keras におけるバッチサイズ

# 既に構築・コンパイル済みモデルの学習
model.fit(X_train, y_train, epochs=100, batch_size=128)
                                        ^^^^^^^^^^^^^^

Kerasで学ぶIntroduction to Deep Learning

Kerasで学ぶIntroduction to Deep Learning

Kerasで学ぶIntroduction to Deep Learning

Kerasで学ぶIntroduction to Deep Learning

バッチ正規化の利点

  • 勾配の流れを改善
  • 高い学習率を許容
  • 初期値への依存を低減
  • 予期せぬ正則化として作用
  • 内部共変量シフトを抑制
Kerasで学ぶIntroduction to Deep Learning

Keras のバッチ正規化

# keras.layers から BatchNormalization をインポート
from tensorflow.keras.layers import BatchNormalization

# Sequential モデルを作成 model = Sequential()
# 入力層を追加 model.add(Dense(3, input_shape=(2,), activation = 'relu'))
# 直前の層の出力にバッチ正規化を追加 model.add(BatchNormalization())
# 出力層を追加 model.add(Dense(1, activation='sigmoid'))
Kerasで学ぶIntroduction to Deep Learning

Ayo berlatih!

Kerasで学ぶIntroduction to Deep Learning

Preparing Video For Download...