Kích thước batch và batch normalization

Nhập môn Deep Learning với Keras

Miguel Esteban

Data Scientist & Founder

Nhập môn Deep Learning với Keras

Nhập môn Deep Learning với Keras

Mini-batches

Ưu điểm

  • Mạng học nhanh hơn (cập nhật trọng số nhiều hơn trong cùng thời gian)
  • Cần ít RAM hơn, huấn luyện được trên tập dữ liệu lớn
  • Nhiễu giúp đạt lỗi thấp hơn, thoát cực tiểu cục bộ

Nhược điểm

  • Cần chạy nhiều vòng lặp hơn
  • Cần điều chỉnh, phải chọn kích thước batch phù hợp
Nhập môn Deep Learning với Keras

1 Stack Exchange
Nhập môn Deep Learning với Keras

Kích thước batch trong Keras

# Huấn luyện mô hình đã xây dựng và biên dịch
model.fit(X_train, y_train, epochs=100, batch_size=128)
                                        ^^^^^^^^^^^^^^

Nhập môn Deep Learning với Keras

Nhập môn Deep Learning với Keras

Nhập môn Deep Learning với Keras

Nhập môn Deep Learning với Keras

Ưu điểm của batch normalization

  • Cải thiện dòng chảy gradient
  • Cho phép learning rate cao hơn
  • Giảm phụ thuộc vào khởi tạo trọng số
  • Tác dụng như một dạng regularization ngoài ý muốn
  • Hạn chế dịch chuyển hiệp phương sai nội bộ
Nhập môn Deep Learning với Keras

Batch normalization trong Keras

# Import BatchNormalization từ keras layers
from tensorflow.keras.layers import BatchNormalization

# Khởi tạo mô hình Sequential model = Sequential()
# Thêm lớp đầu vào model.add(Dense(3, input_shape=(2,), activation = 'relu'))
# Thêm batch normalization cho đầu ra của lớp trên model.add(BatchNormalization())
# Thêm lớp đầu ra model.add(Dense(1, activation='sigmoid'))
Nhập môn Deep Learning với Keras

Ayo berlatih!

Nhập môn Deep Learning với Keras

Preparing Video For Download...