فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة Python
أمثلة قصيرة وبسيطة
الكود قصير والنتيجة اتجرّبت فعلاً. عدّل في المحرر واضغط شغّل.
المثال ١: المساحة اللي بتشوفها الفلاتر
Sample output (press Run to produce your own): 1 x 3x3 conv sees 3 x 3 2 x 3x3 conv sees 5 x 5 3 x 3x3 conv sees 7 x 7 weights: two 3x3 = 18 one 5x5 = 25
المثال ٢: Batch norm من الصفر
Sample output (press Run to produce your own): before: mean [5.1 5.1 4.4 5.5] std [2.8 2.7 3.1 3.4] after : mean [0.5 0.5 0.5 0.5] std [2. 2. 2. 2.]
المثال ٣: Batch norm بيخلّي التدريب أسهل
Sample output (press Run to produce your own): without std after 20 layers: 2820000.0 with batch norm std after 20 layers: 1.0
اختبار قصير
اختبر فهمك
1. Two stacked 3x3 convolutions see an area of:
2. Why prefer several 3x3 filters to one 5x5?
3. Batch norm computes mean and variance over:
4. gamma and beta in batch norm are:
5. At test time batch norm uses:
تمارين برمجة
جرّب بإيدك
التمرين 1
احسب المساحة اللي بتشوفها 4 طبقات conv ٣×٣.
Compute the area seen by 4 stacked 3x3 conv layers.
(output appears here)
n_layers, k = 4, 3 print(1 + n_layers * (k - 1))
Output
9
التمرين 2
طبّق batch norm يدوي على عمود [10, 20, 30, 40] مع gamma = 1 و beta = 0 واطبع الناتج.
Apply batch norm by hand to the column [10, 20, 30, 40] with gamma = 1, beta = 0. Print the result.
(output appears here)
import numpy as np x = np.array([10.0, 20.0, 30.0, 40.0]) print(np.round((x - x.mean()) / np.sqrt(x.var() + 1e-5), 2))
Output
[-1.34 -0.45 0.45 1.34]
مشروع صغير في آخر المحاضرة
أثر الـ batch norm على التدريب (من الصفر)
الداتا: Optical Recognition of Handwritten Digits: 1797 images of 8x8 pixels. Source: UCI Machine Learning Repository.
License / source: Ships with scikit-learn. Dataset page
الخطوات
- حمّل digits، اقسم ٨٠/٢٠، واقسم الـ pixels على 16.
- اعمل شبكة 64-64-10 بـ ReLU وأوزان كبيرة نسبياً (std = 0.5).
- درّب ١٠٠ خطوة بـ lr = 0.1 مرة من غير normalization ومرة بـ normalization على الـ hidden قبل الـ ReLU (من غير gamma و beta).
- قارن دقة الـ test. (ملاحظة: على داتا صغيرة وشبكة قصيرة الفرق بسيط، والـ batch norm بتظهر قوتها في الشبكات الأعمق.)
Expected output (press Run to produce your own): without batch norm: 0.85 with batch norm : 0.847
Credits: the topic order follows the book "Dive into Deep Learning" (d2l.ai) by Zhang, Lipton, Li and Smola, whose text is licensed CC BY-SA 4.0. The explanations, diagrams and code in this lecture are our own and are not copied from the book. Reference: d2l.ai, Modern Convolutional Neural Networks.