Majid Al-RaimiPadding, stride, receptive field and grouped convolutionالحشو والخطوة وحقل الاستقبال والالتفاف المجمّع

COE 592Lecture 02المحاضرة 02Part 03الجزء 03

Padding, stride, receptive field and grouped convolutionالحشو والخطوة وحقل الاستقبال والالتفاف المجمّع

How padding and stride control the output size, how the receptive field grows with depth, and how grouped and depthwise convolution cut parameters.كيف يتحكم الحشو (padding) والخطوة (stride) في حجم المخرج، وكيف ينمو حقل الاستقبال (receptive field) مع العمق، وكيف يقلل الالتفاف المجمّع (grouped) والعمقي (depthwise) عدد المعاملات.

Conceptsالمفاهيم
4
Slidesالشرائح
16-20
Readingمدة القراءة
24 min24 دقيقة
Understoodما فهمته
0/4 conceptsمفاهيم

Why this part mattersلماذا يهمّ هذا الجزء

Part 02 gave you a convolution that slides one filter over one input. Every embedded CNN you will profile or design in this course, from MobileNet to the TinyML backbones in your project, is built by turning four extra knobs on that layer: padding, stride, depth and grouping.

Those knobs decide the three numbers an embedded engineer lives by. The output size sets how much activation memory a layer needs. The receptive field sets how many layers it takes before one output can see the whole image. The parameter count sets how much flash the weights occupy and, with the output size, how many multiply-accumulates each inference costs. The exam asks for all three directly, and the storage and MAC budgets in your research project come out of the same formulas.

أعطاك الجزء 02 التفافًا (convolution) يمرّر مرشّحًا واحدًا فوق مدخل واحد. كل شبكة CNN مدمجة ستقيس أداءها أو تصممها في هذا المقرر، من MobileNet إلى الشبكات الأساسية (backbones) الخاصة بـ TinyML في مشروعك، تُبنى بتحريك أربعة مفاتيح إضافية في تلك الطبقة: الحشو (padding) والخطوة (stride) والعمق (depth) والتجميع (grouping).

هذه المفاتيح تحدد الأرقام الثلاثة التي يعيش عليها مهندس الأنظمة المدمجة. حجم المخرج يحدد مقدار ذاكرة التنشيطات (activation memory) التي تحتاجها الطبقة. ومجال الاستقبال (receptive field) يحدد كم طبقة نحتاج قبل أن يرى مخرج واحد الصورة كاملة. وعدد المعاملات (parameters) يحدد كم تشغل الأوزان من ذاكرة flash، ومعه حجم المخرج يحدد كم عملية ضرب وتجميع (multiply-accumulate) يكلّف كل استدلال (inference). الامتحان يسأل عن الثلاثة مباشرة، وميزانيات التخزين وعدد MAC في مشروعك البحثي تخرج من الصيغ نفسها.

By the end you canفي نهاية هذا الجزء ستستطيع

  1. Compute the output size of any Conv2D from h_i, k, p and s, including the floor, and pick p for a same-size output.تحسب حجم المخرج لأي طبقة Conv2D من h_i و k و p و s مع دالة floor، وتختار p بحيث يبقى المخرج بنفس حجم المدخل.
  2. Explain what each padding mode puts in the border and why none of them adds a parameter.تشرح ماذا يضع كل نوع من أنواع الحشو (padding) في الإطار، ولماذا لا يضيف أيٌّ منها أي معامل (parameter).
  3. Compute the receptive field after L layers, with and without stride, and explain why networks downsample.تحسب مجال الاستقبال (receptive field) بعد L طبقة مع الخطوة (stride) وبدونها، وتشرح لماذا تقلّص الشبكات الدقة (downsample).
  4. Count weights and multiply-accumulates for standard, grouped and depthwise convolutions, and check that g divides c_i and c_o.تعدّ الأوزان وعمليات الضرب والتجميع (MACs) للالتفاف العادي والمجمّع (grouped) والعمقي (depthwise)، وتتحقق من أن g يقسم c_i و c_o.
  5. Argue when a depthwise separable block is the right trade for an embedded device and what it gives up.تبرهن متى تكون كتلة depthwise separable هي المقايضة الصحيحة على جهاز مدمج (embedded)، وما الذي تتنازل عنه.

Take the 5 x 5 input and 3 x 3 Kernel (filter) from Part 02. The kernel can only sit where it fits entirely inside the image, so it has three horizontal and three vertical positions and the output Feature map is 3 x 3. Stack a second such layer and you get 1 x 1. A third layer cannot run at all. Every layer eats two rows and two columns, and Goodfellow, Bengio and Courville put it plainly: without padding the representation shrinks by one pixel less than the kernel width at every layer.

خذ المدخل 5 x 5 والنواة kernel بحجم 3 x 3 من الجزء 02. لا يمكن للنواة أن تقف إلا حيث تتسع بالكامل داخل الصورة، فلها ثلاثة مواضع أفقية وثلاثة رأسية، ويكون feature map الناتج بحجم 3 x 3. أضف طبقة ثانية مثلها فتحصل على 1 x 1. أما الطبقة الثالثة فلا يمكن تشغيلها أصلًا. كل طبقة تأكل صفّين وعمودين، ويقولها Goodfellow وBengio وCourville بوضوح: بدون حشو يتقلص التمثيل في كل طبقة بمقدار عرض النواة ناقص بكسل واحد.

Padding is the fix. Add a ring of p extra cells around the input before sliding the kernel. With p = 1 the 5 x 5 image becomes 7 x 7, the kernel now has five positions in each direction, and the output is 5 x 5 again. The same 27 weights per filter (3 x 3 over three input channels) do the work; the only thing that changed is where the kernel is allowed to stand.

الحل هو الحشو padding. أضف حلقة من p خلية إضافية حول المدخل قبل تمرير النواة. مع p = 1 تصبح الصورة 5 x 5 بحجم 7 x 7، وتصبح للنواة خمسة مواضع في كل اتجاه، ويعود المخرج إلى 5 x 5. الأوزان نفسها (weights) وعددها 27 لكل مرشّح (3 x 3 على ثلاث قنوات مدخلة) هي التي تقوم بالعمل؛ الشيء الوحيد الذي تغيّر هو المكان المسموح للنواة أن تقف فيه.

ho=hi+2p−kh+1(s=1)h_o = h_i + 2p - k_h + 1 \qquad (s = 1)
Output height with p cells of padding on each side, stride 1ارتفاع المخرج مع حشو بمقدار p خلية على كل جانب، وخطوة 1

Read the formula as a story. The padded input is h_i + 2p rows tall. A window of height k_h can start on any row except the last k_h - 1, which leaves h_i + 2p - k_h + 1 starting rows, one per output row. Set h_o = h_i and the equation solves to p = (k - 1)/2, which is a whole number only for odd kernels. That is why 3 x 3, 5 x 5 and 7 x 7 dominate practice: Zhang et al. note that an odd kernel lets the same amount of padding go on both sides and keeps the output pixel centred on its window. Dumoulin and Visin call this half padding, and the deep learning book calls it same convolution, after the MATLAB option of that name.

اقرأ الصيغة كقصة. المدخل بعد الحشو ارتفاعه h_i + 2p صفًّا. نافذة ارتفاعها k_h يمكن أن تبدأ من أي صف ما عدا آخر k_h - 1 صفوف، فيبقى h_i + 2p - k_h + 1 صف بداية، صف مخرج لكل واحد منها. ضع h_o = h_i فتُحل المعادلة إلى p = (k - 1)/2، وهو عدد صحيح فقط عندما تكون النواة فردية. لهذا تسيطر 3 x 3 و5 x 5 و7 x 7 على الممارسة العملية: يلاحظ Zhang et al. أن النواة الفردية تسمح بوضع مقدار الحشو نفسه على الجانبين وتبقي بكسل المخرج في مركز نافذته. يسمي Dumoulin وVisin هذا بالحشو النصفي (half padding)، ويسميه كتاب التعلم العميق الالتفاف المتساوي (same convolution)، نسبةً إلى خيار MATLAB الذي يحمل هذا الاسم.

Worked exampleمثال محلول

Same, valid and a strided stemحشو same وحشو valid وبداية شبكة بخطوة

  1. CIFAR-10 input, no paddingمدخل CIFAR-10 بدون حشو

    32 x 32 image, k = 5, p = 0: 32 - 5 + 1 = 28. The map shrinks by four.
    صورة 32 x 32، k = 5، p = 0: 32 - 5 + 1 = 28. تتقلص الخريطة بمقدار أربعة.
  2. Same padding for k = 5حشو same عندما k = 5

    p = (5 - 1)/2 = 2: 32 + 4 - 5 + 1 = 32. The map keeps its size.
    p = (5 - 1)/2 = 2: 32 + 4 - 5 + 1 = 32. تحافظ الخريطة على حجمها.
  3. The slide 16 exampleمثال الشريحة 16

    h_i = 5, k = 3, p = 1: 5 + 2 - 3 + 1 = 5.
    h_i = 5، k = 3، p = 1: 5 + 2 - 3 + 1 = 5.
  4. Parameters in every caseالمعاملات في كل الحالات

    Identical. A 3 x 3 filter over three input channels has 27 weights whether p is 0, 1 or 10. Padding changes the output size and therefore the multiply-accumulates, and nothing else.
    متطابقة. مرشّح 3 x 3 على ثلاث قنوات مدخلة له 27 وزنًا سواء كان p يساوي 0 أو 1 أو 10. الحشو يغيّر حجم المخرج وبالتالي عدد عمليات الضرب والتجميع، ولا شيء غير ذلك.

What goes in the ringماذا نضع في الحلقة

The formula does not care what the new cells contain, but the values do affect what the network learns near the border. The slide pads a 3 x 3 image holding 1 to 9 by p = 2 on every side, which is a good specimen because 2 is the largest reflection padding a 3 x 3 image can take. Zero padding writes zeros, and PyTorch uses it unless told otherwise. Reflection padding mirrors the image across its edge without repeating the edge pixel, so the row above 1 2 3 reads 4 5 6 and the row above that reads 7 8 9. Replication padding stretches each edge pixel outward, so the corner 1 fills the whole top-left 3 x 3 block. Constant padding is zero padding with a value of your choice.

الصيغة لا تهتم بما تحتويه الخلايا الجديدة، لكن القيم تؤثر فعلًا على ما تتعلمه الشبكة قرب الإطار. تحشو الشريحة صورة 3 x 3 تحمل القيم من 1 إلى 9 بمقدار p = 2 من كل جانب، وهي عينة جيدة لأن 2 هو أكبر حشو انعكاسي تتحمله صورة 3 x 3. الحشو الصفري zero padding يكتب أصفارًا، وتستخدمه PyTorch ما لم تطلب غيره. الحشو الانعكاسي reflection padding يعكس الصورة عبر حافتها دون تكرار بكسل الحافة نفسه، فالصف فوق 1 2 3 يُقرأ 4 5 6 والصف فوقه يُقرأ 7 8 9. الحشو التكراري replication padding يمدّ كل بكسل حافة إلى الخارج، فالركن 1 يملأ كتلة 3 x 3 العلوية اليسرى كاملة. والحشو الثابت (constant) هو حشو صفري لكن بقيمة تختارها أنت.

The same 3 x 3 image padded by 2. Reflection reaches back into the interior, replication clamps to the edge, zero has no source at all.الصورة نفسها 3 x 3 محشوة بمقدار 2. الانعكاس يمتد عائدًا إلى داخل الصورة، والتكرار يلتصق بالحافة، والصفري ليس له مصدر أصلًا.
ModeالنمطRuleالقاعدةRow 0الصف 0PyTorchPyTorch
Zeroصفري (Zero)Fill the border with 0املأ الإطار بالقيمة 00 0 0 0 0 0 00 0 0 0 0 0 0padding_mode='zeros' (default)padding_mode='zeros' (default)
Reflectionانعكاسي (Reflection)Mirror across the edge; the edge value itself is not repeatedاعكس الصورة عبر الحافة؛ قيمة الحافة نفسها لا تتكرر9 8 7 8 9 8 79 8 7 8 9 8 7ReflectionPad2d, padding_mode='reflect'ReflectionPad2d, padding_mode='reflect'
Replicationتكراري (Replication)Repeat the nearest edge value outwardكرّر أقرب قيمة على الحافة نحو الخارج1 1 1 2 3 3 31 1 1 2 3 3 3ReplicationPad2d, padding_mode='replicate'ReplicationPad2d, padding_mode='replicate'
Constantثابت (Constant)Fill the border with one chosen value vاملأ الإطار بقيمة واحدة تختارها vv v v v v v vv v v v v v vConstantPad2d(padding, value)ConstantPad2d(padding, value)
Padding modes on the slide 16 grid (row 0 of the 7 x 7 result)أنماط الحشو على شبكة الشريحة 16 (الصف 0 من النتيجة 7 x 7)

The index rule behind the visual is short. For a padded coordinate j in 0 to 6, subtract p to get an offset into the original image. Replication clamps that offset into 0 to 2. Reflection folds it: -1 becomes 1, -2 becomes 2, 3 becomes 1 and 4 becomes 0. Fold both the row and the column offset and you have the source pixel. The PyTorch documentation for ReflectionPad2d walks through exactly this example with the values 0 to 8. PyTorch also offers a 'circular' mode that wraps around to the opposite edge; the slide leaves it out.

قاعدة الفهارس وراء الشكل قصيرة. لإحداثي محشو j من 0 إلى 6، اطرح p لتحصل على إزاحة داخل الصورة الأصلية. التكرار يحصر هذه الإزاحة داخل المدى 0 إلى 2. أما الانعكاس فيطويها: -1 تصبح 1، و-2 تصبح 2، و3 تصبح 1، و4 تصبح 0. اطوِ إزاحة الصف وإزاحة العمود معًا فتحصل على البكسل المصدر. توثيق PyTorch الخاص بـ ReflectionPad2d يشرح هذا المثال بالضبط بالقيم من 0 إلى 8. وتوفر PyTorch أيضًا نمط 'circular' الذي يلتف إلى الحافة المقابلة؛ والشريحة لا تذكره.

Recall

Input 5 x 5, kernel 3 x 3, stride 1. What padding keeps the output 5 x 5, and how many parameters does that padding add?مدخل 5 x 5، ونواة 3 x 3، وخطوة 1. ما الحشو الذي يبقي المخرج 5 x 5، وكم معاملًا يضيفه هذا الحشو؟

p = 1, because 5 + 2 - 3 + 1 = 5. It adds zero parameters. The filter still has c_i x 3 x 3 weights.
p = 1، لأن 5 + 2 - 3 + 1 = 5. ولا يضيف أي معامل. يبقى للمرشّح c_i x 3 x 3 وزنًا.

One output pixel of a 3 x 3 Convolution layer is a weighted sum of a 3 x 3 patch of its input. That patch is its Receptive field. Now feed that layer's output into a second 3 x 3 layer. One pixel of the second layer reads a 3 x 3 block of first-layer outputs, and each of those was itself computed from a 3 x 3 patch. The patches of neighbouring pixels overlap and slide by one cell, so the union of all nine is a 5 x 5 region of the original image. A third layer makes it 7 x 7.

بكسل مخرج واحد من طبقة التفاف convolution layer بحجم 3 x 3 هو مجموع موزون لرقعة 3 x 3 من مدخلها. هذه الرقعة هي مجال استقباله receptive field. الآن أدخل مخرج تلك الطبقة إلى طبقة ثانية 3 x 3. بكسل واحد من الطبقة الثانية يقرأ كتلة 3 x 3 من مخرجات الطبقة الأولى، وكل واحد منها حُسب بدوره من رقعة 3 x 3. رقع البكسلات المتجاورة تتداخل وتنزاح بخلية واحدة، فيكون اتحاد الرقع التسع منطقة 5 x 5 من الصورة الأصلية. والطبقة الثالثة تجعلها 7 x 7.

Read the slide 17 figure from right to left: the single output cell traces back to 3 x 3, then 5 x 5, then 7 x 7 of the input.اقرأ شكل الشريحة 17 من اليمين إلى اليسار: خلية المخرج الواحدة ترجع إلى 3 x 3، ثم 5 x 5، ثم 7 x 7 من المدخل.

Each stride-1 layer adds k - 1 to the side of the region, because the outermost cells of the new window reach (k - 1)/2 further in each direction. Start from a single pixel and add k - 1 once per layer.

كل طبقة بخطوة 1 تضيف k - 1 إلى ضلع المنطقة، لأن الخلايا الطرفية في النافذة الجديدة تمتد (k - 1)/2 أبعد في كل اتجاه. ابدأ من بكسل واحد وأضف k - 1 مرة لكل طبقة.

RFL=L (k−1)+1(every stride=1)RF_L = L\,(k - 1) + 1 \qquad (\text{every stride} = 1)
Receptive field after L stride-1 layers of size kالمجال الاستقبالي بعد L طبقة بحجم k وخطوة 1

With k = 3 this gives 3, 5, 7, 9, 11 for L = 1 to 5. The deep learning book's figure 9.4 makes the same point and adds the hint that matters next: the effect increases if the network includes strided convolution or pooling.

مع k = 3 تعطي هذه الصيغة 3, 5, 7, 9, 11 للقيم من L = 1 إلى 5. الشكل 9.4 في كتاب التعلم العميق يوضح النقطة نفسها ويضيف التلميح المهم لما يأتي: يزداد هذا الأثر إذا احتوت الشبكة على التفاف بخطوة (strided convolution) أو تجميع (pooling).

The problem with large imagesمشكلة الصور الكبيرة

A classifier must eventually let one output depend on the whole picture. For a 224 x 224 image and stride-1 3 x 3 layers, solve 2L + 1 >= 224: L = 112 layers before a single output pixel sees everything. Each of those layers works at full resolution, so the activation memory and the multiply-accumulates are enormous. The slide states the problem and the cure in one breath: downsample inside the network.

المصنّف (classifier) يجب في النهاية أن يجعل مخرجًا واحدًا يعتمد على الصورة كلها. لصورة 224 x 224 وطبقات 3 x 3 بخطوة 1، حُلّ 2L + 1 >= 224: L = 112 طبقة قبل أن يرى بكسل مخرج واحد كل شيء. كل طبقة منها تعمل بالدقة الكاملة، فتكون ذاكرة التنشيطات وعمليات الضرب والتجميع هائلة. الشريحة تذكر المشكلة والعلاج في نفس واحد: قلّص الدقة (downsample) داخل الشبكة.

Stride is the cheapest way to do it. Instead of moving the kernel one cell at a time, move it s cells. The number of window positions drops by about a factor of s in each direction, and so does the output size. Goodfellow, Bengio and Courville describe stride s as mathematically equivalent to a stride-1 convolution followed by keeping every s-th output, only without wasting work on the outputs you would throw away.

الخطوة stride هي أرخص طريقة لذلك. بدلًا من تحريك النواة خلية واحدة في كل مرة، حرّكها s خلايا. ينخفض عدد مواضع النافذة بمعامل s تقريبًا في كل اتجاه، وكذلك حجم المخرج. يصف Goodfellow وBengio وCourville الخطوة s بأنها مكافئة رياضيًا لالتفاف بخطوة 1 يتبعه الاحتفاظ بمخرج واحد من كل s مخرجات، لكن دون إهدار حساب على المخرجات التي كنت ستتخلص منها.

ho=⌊hi+2p−khs⌋+1h_o = \left\lfloor \frac{h_i + 2p - k_h}{s} \right\rfloor + 1
Output height with padding p and stride sارتفاع المخرج مع حشو p وخطوة s

The floor is not decoration. The padded input has h_i + 2p - k_h rows on which a window can start after the first, and the kernel visits every s-th of them. If that span is not a multiple of s, the last window would run past the edge and is dropped. Try h_i = 8, k = 3, p = 0, s = 2: the slide's version gives 3.5, which is not a size; the true answer is floor(5/2) + 1 = 3. Dumoulin and Visin state the relationship with the floor, and the PyTorch Conv2d documentation computes the output shape the same way.

دالة floor ليست زينة. المدخل المحشو فيه h_i + 2p - k_h صفًّا يمكن أن تبدأ منها النافذة بعد الصف الأول، والنواة تزور واحدًا من كل s منها. إذا لم يكن هذا المدى من مضاعفات s، فإن النافذة الأخيرة ستتجاوز الحافة فتُحذف. جرّب h_i = 8، k = 3، p = 0، s = 2: صيغة الشريحة تعطي 3.5، وهذا ليس حجمًا؛ الجواب الصحيح هو floor(5/2) + 1 = 3. يكتب Dumoulin وVisin العلاقة مع floor، وتوثيق Conv2d في PyTorch يحسب شكل المخرج بالطريقة نفسها.

SimulatorمحاكيConv2D shape and cost calculatorحاسبة أبعاد Conv2D وكلفتها
Output sizeحجم الخرج5 x 5x 8floor((h_i + 2p - k)/s) + 1
Weightsالأوزان216valuesc_o x (c_i/g) x k x k, 864 B at fp32c_o x (c_i/g) x k x k، أي 864 B بدقة fp32
Parametersالمعاملات224valuesweights + 8 biasesالأوزان + 8 انحيازًا
Multiply-accumulatesعمليات الضرب والجمع (MACs)5,400MACsweights x h_o x w_o, one imageالأوزان x h_o x w_o، لصورة واحدة
Per output channelلكل قناة خرج3input channels readevery filter reads all of c_iكل مرشح يقرأ جميع قنوات c_i
Uncovered edgeالحافة غير المغطاة0 + 0rows + colspadded input the floor never readsجزء من الإدخال المبطَّن لا تقرؤه دالة floor أبدًا

Change p or s and watch the output size and the MACs move while the weight count stays still. Only c_i, c_o, k and g touch the parameter count.غيّر p أو s وراقب حجم الإخراج وعدد عمليات MAC يتغيران بينما يبقى عدد الأوزان ثابتًا. وحدها c_i وc_o وk وg تؤثر في عدد المعاملات.

How stride changes the receptive field ruleكيف تغيّر الخطوة قاعدة مجال الاستقبال

Stride does more than shrink maps. Once a layer has stride 2, two neighbouring outputs of that layer sit two input pixels apart, so every layer after it takes steps of two in input coordinates. Its 3 x 3 window no longer adds 2 pixels to the receptive field; it adds 2 x 2 = 4. The slide 18 top row shows the payoff: a stride-2 first layer followed by one stride-1 layer already reaches 7, where stride 1 needed three layers.

الخطوة تفعل أكثر من تصغير الخرائط. بمجرد أن تكون لطبقة خطوة 2، يصبح المخرجان المتجاوران لتلك الطبقة على بعد بكسلين في المدخل، فتمشي كل طبقة بعدها بخطوات من اثنين في إحداثيات المدخل. نافذتها 3 x 3 لم تعد تضيف 2 بكسل إلى مجال الاستقبال؛ بل تضيف 2 x 2 = 4. الصف العلوي في الشريحة 18 يُظهر المكسب: طبقة أولى بخطوة 2 تتبعها طبقة واحدة بخطوة 1 تصل بالفعل إلى 7، بينما احتاجت الخطوة 1 إلى ثلاث طبقات.

Stride 2 in the first layer: the three dashed windows start two cells apart, so two 3 x 3 layers already cover 7 x 7 of the input.خطوة 2 في الطبقة الأولى: النوافذ الثلاث المتقطعة تبدأ على بعد خليتين من بعضها، فتغطي طبقتان 3 x 3 بالفعل 7 x 7 من المدخل.

Araujo, Norris and Sim give the general closed form. Call the product of the strides before layer l the jump (some authors say effective stride). Each layer adds (k_l - 1) times its jump.

يعطي Araujo وNorris وSim الصيغة المغلقة العامة. سمِّ حاصل ضرب الخطوات قبل الطبقة l بالقفزة jump (وبعض المؤلفين يسمونها الخطوة الفعلية effective stride). كل طبقة تضيف (k_l - 1) مضروبًا في قفزتها.

RFL=1+∑l=1L(kl−1)∏i=1l−1siRF_L = 1 + \sum_{l=1}^{L} (k_l - 1) \prod_{i=1}^{l-1} s_i
Receptive field with arbitrary kernels and strides (Araujo, Norris and Sim, 2019)المجال الاستقبالي مع أنوية وخطوات اعتباطية (Araujo, Norris and Sim, 2019)

Worked exampleمثال محلول

Slide 18, top row, and one step furtherالشريحة 18، الصف العلوي، وخطوة أبعد

  1. Layer 1: k = 3, s = 2الطبقة 1: k = 3، s = 2

    Jump before it is 1, so RF = 1 + 2 x 1 = 3. Jump after it is 2.
    القفزة قبلها 1، إذن RF = 1 + 2 x 1 = 3. والقفزة بعدها 2.
  2. Layer 2: k = 3, s = 1الطبقة 2: k = 3، s = 1

    RF = 3 + 2 x 2 = 7. Two layers reach what three stride-1 layers reached.
    RF = 3 + 2 x 2 = 7. طبقتان تصلان إلى ما وصلت إليه ثلاث طبقات بخطوة 1.
  3. Add a third stride-1 layerأضف طبقة ثالثة بخطوة 1

    Jump is still 2: RF = 7 + 2 x 2 = 11.
    القفزة ما زالت 2: RF = 7 + 2 x 2 = 11.
  4. Or make layers 1 and 2 both stride 2أو اجعل الطبقتين 1 و 2 كلتيهما بخطوة 2

    Jumps 1, 2, 4: RF = 1 + 2 + 4 + 8 = 15 after three 3 x 3 layers.
    القفزات 1, 2, 4: RF = 1 + 2 + 4 + 8 = 15 بعد ثلاث طبقات 3 x 3.
  5. The shortcut only holds for stride 1الاختصار يصح فقط مع خطوة 1

    L(k - 1) + 1 would predict 7 for all three-layer cases. The general formula gives 7, 11 or 15 depending on where the strides sit.
    الصيغة L(k - 1) + 1 كانت ستتنبأ بـ 7 في كل حالات الطبقات الثلاث. أما الصيغة العامة فتعطي 7 أو 11 أو 15 بحسب مواضع الخطوات.
Layersعدد الطبقاتAll stride 1كل الخطوات 1First layer stride 2الطبقة الأولى بخطوة 2Every layer stride 2كل طبقة بخطوة 2
11333333
22557777
337711111515
449915153131
Receptive field after L layers of 3 x 3مجال الاستقبال بعد L طبقة بحجم 3 x 3
SimulatorمحاكيReceptive field stackerمكدِّس المجال الاستقبالي
layerkernelstrideRFjump
1
31
2
72
3
112
General receptive fieldالحقل الاستقبالي العام11pixelsRF_l = RF_(l-1) + (k - 1) x jump
Stride-1 shortcutالاختصار عند stride 17pixelssum of (k - 1) plus 1: wrong here because a stride before the last layer exceeds 1مجموع (k - 1) زائد 1: خاطئ هنا لأن خطوة قبل الطبقة الأخيرة تتجاوز 1

The jump column is the jump before each layer: the product of the strides of the layers above it. The layer adds (k - 1) times that jump. A stride of 2 in layer 1 doubles how much every later layer adds, which is why the general value pulls away from L(k - 1) + 1.عمود jump هو القفزة قبل كل طبقة: حاصل ضرب خطوات الطبقات التي تسبقها. تضيف الطبقة (k - 1) مضروبًا في تلك القفزة. الخطوة 2 في الطبقة 1 تضاعف ما تضيفه كل طبقة بعدها، ولهذا تبتعد القيمة العامة عن L(k - 1) + 1.

Real networks live at the strided end of that table. Araujo, Norris and Sim compute receptive fields of 195 for AlexNet, 212 for VGG-16, 483 for ResNet-50 and 1,311 for Inception-v3, all with a total downsampling of 32, and remark that the receptive field usually covers the entire input image. The stride in the ResNet stem you computed in the calculator is the first of those doublings: 224 to 112 in one layer.

الشبكات الحقيقية تعيش في طرف الخطوات من ذلك الجدول. يحسب Araujo وNorris وSim مجالات استقبال قدرها 195 لـ AlexNet، و212 لـ VGG-16، و483 لـ ResNet-50، و1,311 لـ Inception-v3، وكلها بتقليص كلي للدقة قدره 32، ويلاحظون أن مجال الاستقبال يغطي عادةً صورة المدخل بأكملها. الخطوة في بداية ResNet (stem) التي حسبتها في الحاسبة هي أول هذه المضاعفات: من 224 إلى 112 في طبقة واحدة.

Quick checkاختبار سريع

A 32 x 32 input passes through a 5 x 5 kernel with padding 2 and stride 2. What is the output height?يمر مدخل 32 x 32 عبر نواة 5 x 5 بحشو 2 وخطوة 2. ما ارتفاع المخرج؟

Quick checkاختبار سريع

Three 3 x 3 convolutions have strides 2, 1 and 1 in that order. What is the receptive field of one output pixel?ثلاثة التفافات 3 x 3 خطواتها 2 ثم 1 ثم 1 بهذا الترتيب. ما مجال الاستقبال لبكسل مخرج واحد؟

Recall

Write the output size formula with stride and say why the floor is needed.اكتب صيغة حجم المخرج مع الخطوة، وقل لماذا نحتاج floor.

h_o = floor((h_i + 2p - k_h)/s) + 1. When the span h_i + 2p - k_h is not a multiple of s, the last window would overrun the edge and is dropped: 8 rows, k = 3, s = 2 gives 3, not 3.5.
h_o = floor((h_i + 2p - k_h)/s) + 1. عندما لا يكون المدى h_i + 2p - k_h من مضاعفات s، فإن النافذة الأخيرة ستتجاوز الحافة فتُحذف: 8 صفوف، k = 3، s = 2 تعطي 3، لا 3.5.

Recall

Three 3 x 3 layers with strides 2, 2, 1: what is the receptive field?ثلاث طبقات 3 x 3 بخطوات 2, 2, 1: ما مجال الاستقبال؟

Jumps 1, 2, 4, so 1 + 2 x 1 + 2 x 2 + 2 x 4 = 15.
القفزات 1, 2, 4، إذن 1 + 2 x 1 + 2 x 2 + 2 x 4 = 15.

Padding and stride change the shape of the computation. The last two concepts change its wiring. Take a layer with c_i = c_o = 64 channels and 3 x 3 kernels. Each of the 64 filters reads all 64 input channels, so the layer holds 64 x 64 x 9 = 36,864 weights. Now split the channels into two halves and run two separate convolutions, each mapping 32 inputs to 32 outputs. Each half holds 32 x 32 x 9 = 9,216 weights, so the pair holds 18,432: the same output shape at half the cost.

الحشو والخطوة يغيّران شكل الحساب. أما المفهومان الأخيران فيغيّران توصيلاته. خذ طبقة فيها c_i = c_o = 64 قناة (channels) ونوى 3 x 3. كل مرشّح من المرشّحات الـ 64 يقرأ كل القنوات المدخلة الـ 64، فتحمل الطبقة 64 x 64 x 9 = 36,864 وزنًا. الآن قسّم القنوات إلى نصفين وشغّل التفافين منفصلين، كل واحد يحوّل 32 مدخلًا إلى 32 مخرجًا. كل نصف يحمل 32 x 32 x 9 = 9,216 وزنًا، فيحمل الزوج 18,432: شكل المخرج نفسه بنصف التكلفة.

That is a Grouped convolution with g = 2, or in the slide's words a group of narrower convolutions. In general, split c_i into g blocks of c_i/g channels and c_o into g blocks of c_o/g. Output block j reads only input block j. The slide writes the new Weight shape as (g · c_o/g, c_i/g, k_h, k_w), and the first factor simplifies to c_o: there are still c_o filters, each just reads c_i/g channels instead of all c_i. The Bias stays one per output channel.

هذا التفاف مجمّع grouped convolution مع g = 2، أو بتعبير الشريحة: مجموعة من الالتفافات الأضيق. بشكل عام، قسّم c_i إلى g كتل كل منها c_i/g قناة، وقسّم c_o إلى g كتل كل منها c_o/g. كتلة المخرج j تقرأ كتلة المدخل j فقط. تكتب الشريحة الشكل الجديد لموتّر الأوزان weight هكذا: (g · c_o/g, c_i/g, k_h, k_w)، والعامل الأول يُختصر إلى c_o: ما زال هناك c_o مرشّحًا، لكن كل واحد يقرأ c_i/g قناة بدل كل القنوات c_i. ويبقى الانحياز bias واحدًا لكل قناة مخرجة.

W:(co,  cig,  kh,  kw),#weights=co⋅cig⋅khkw,MACs=#weights⋅howo\mathbf{W} : \left(c_o,\; \tfrac{c_i}{g},\; k_h,\; k_w\right), \qquad \#\text{weights} = c_o \cdot \tfrac{c_i}{g} \cdot k_h k_w, \qquad \text{MACs} = \#\text{weights} \cdot h_o w_o
Grouped convolution: g times fewer weights and MACs, same output shapeالالتفاف المجمَّع (grouped convolution): أوزان وMACs أقل بمقدار g مرة، وبأبعاد المخرج نفسها
Slide 19 redrawn: with g = 2 the full block of crossing lines splits into two half-width blocks, and the faint grey lines are the connections that no longer exist.الشريحة 19 بإعادة رسم: مع g = 2 تنقسم الكتلة الكاملة من الخطوط المتقاطعة إلى كتلتين بنصف العرض، والخطوط الرمادية الباهتة هي الوصلات التي لم تعد موجودة.
Groupsالمجموعاتc_o x (c_i/g) x k x kc_o x (c_i/g) x k x kWeightsالأوزانSavingالتوفير
g = 1g = 164 x 64 x 964 x 64 x 936,86436,8641x1x
g = 2g = 264 x 32 x 964 x 32 x 918,43218,4322x2x
g = 4g = 464 x 16 x 964 x 16 x 99,2169,2164x4x
g = 8g = 864 x 8 x 964 x 8 x 94,6084,6088x8x
g = 64g = 6464 x 1 x 964 x 1 x 957657664x64x
c_i = c_o = 64, k = 3, weights only (add 64 biases to every row)c_i = c_o = 64، k = 3، الأوزان فقط (أضف 64 انحيازًا إلى كل صف)
SimulatorمحاكيGrouped to depthwise, 64 channels in and outمن المجمَّع إلى العمقي، 64 قناة دخل وخرج

Each drawn lane stands for 8 real channels. 32 of 64 lane pairs stay connected.كل مسار مرسوم يمثل 8 قناة حقيقية. يبقى 32 من أصل 64 زوجًا من المسارات متصلًا.

0full bar = standard 36,864 weights
Grouped 3 x 318,432weights64 x (64/2) x 9, 32 channels per group64 x (64/2) x 9، 32 قناة في كل مجموعة
Pointwise 1 x 1Pointwise 1 x 10weightsoff, no cross-channel mixingمتوقف، لا مزج بين القنوات
Weights vs standardالأوزان مقارنة بالالتفاف العادي2.0xfewer18,432 of 36,864 weights18,432 من أصل 36,864 وزنًا

The divisibility ruleقاعدة قابلية القسمة

The split only works if both channel counts divide evenly. PyTorch says so directly: in_channels and out_channels must both be divisible by groups. With c_i = 64 and c_o = 96, g = 4 is fine (16 inputs and 24 outputs per group) but g = 5 is not, because 64/5 is not an integer. Output channel j belongs to group floor(j / (c_o/g)) and reads only the input channels of that group. The calculator earlier in this part flags any pair that fails the rule.

التقسيم لا ينجح إلا إذا انقسم عددا القنوات كلاهما بالتساوي. توثيق PyTorch يقولها صراحة: يجب أن يقبل كلٌّ من in_channels وout_channels القسمة على groups. مع c_i = 64 وc_o = 96، القيمة g = 4 مقبولة (16 مدخلًا و24 مخرجًا لكل مجموعة) لكن g = 5 غير مقبولة، لأن 64/5 ليس عددًا صحيحًا. قناة المخرج j تنتمي إلى المجموعة floor(j / (c_o/g)) ولا تقرأ إلا قنوات المدخل في تلك المجموعة. الحاسبة السابقة في هذا الجزء تنبّه على أي زوج يخالف القاعدة.

The idea is older than its name. Krizhevsky, Sutskever and Hinton trained AlexNet on two GTX 580 GPUs with 3 GB each, so they put half of the kernels on each GPU and let the kernels of layer 4 take input only from the kernel maps of layer 3 that lived on the same GPU. That is g = 2, chosen for memory rather than elegance. ResNeXt (Xie et al., 2017) turned the group count into a design axis they named cardinality and found that raising it was more effective than going deeper or wider at the same parameter budget.

الفكرة أقدم من اسمها. درّب Krizhevsky وSutskever وHinton شبكة AlexNet على معالجَي رسوميات GTX 580 في كلٍّ منهما 3 GB، فوضعوا نصف النوى على كل معالج، وجعلوا نوى الطبقة 4 تأخذ مدخلها فقط من خرائط الطبقة 3 الموجودة على المعالج نفسه. هذا هو g = 2، واختير بسبب الذاكرة لا بسبب الأناقة. ثم حوّلت ResNeXt (Xie et al., 2017) عدد المجموعات إلى محور تصميم سمّوه cardinality، ووجدوا أن زيادته أكثر فاعلية من زيادة العمق أو العرض بنفس ميزانية المعاملات.

That last clause is the cost. Inside a grouped layer, no information crosses a group boundary; the faint grey lines in the visual are exactly the missing connections. Networks that use grouped layers alternate them with something that mixes channels again, most often a 1 x 1 convolution. The next concept pushes g to its limit and meets that need head on.

هذه الجملة الأخيرة هي التكلفة. داخل الطبقة المجمّعة لا تعبر أي معلومة حدود المجموعة؛ والخطوط الرمادية الباهتة في الشكل هي بالضبط الوصلات المفقودة. الشبكات التي تستخدم طبقات مجمّعة تبادل بينها وبين شيء يخلط القنوات من جديد، وغالبًا ما يكون التفافًا 1 x 1. المفهوم التالي يدفع g إلى أقصى حد ويواجه هذه الحاجة مباشرة.

Quick checkاختبار سريع

A layer has c_i = c_o = 128, k = 3, g = 8 and no bias. How many weights does it hold?طبقة فيها c_i = c_o = 128 و k = 3 و g = 8 وبدون انحياز. كم وزنًا تحمل؟

Recall

c_i = c_o = 64, k = 3. How many weights for g = 1, g = 4 and depthwise (g = 64)?c_i = c_o = 64، k = 3. كم وزنًا عندما g = 1، و g = 4، وفي الحالة العمقية (g = 64)؟

36,864; 9,216; 576. Each is 64 x (64/g) x 9.
36,864؛ 9,216؛ 576. كل منها يساوي 64 x (64/g) x 9.

Push the group count as far as it goes: g = c_i = c_o. Every group is now one Channel in and one channel out, so each channel gets its own k x k filter and nothing else. For 64 channels and 3 x 3 kernels that is 64 x 9 = 576 weights, 64 times fewer than the 36,864 of the standard layer. The slide 20 diagram says it in one picture: eight straight arrows from input strip to output strip, and not one of them crosses.

ادفع عدد المجموعات إلى أقصى ما يمكن: g = c_i = c_o. كل مجموعة الآن قناة channel واحدة تدخل وقناة واحدة تخرج، فتحصل كل قناة على مرشّح k x k خاص بها ولا شيء غيره. لـ 64 قناة ونوى 3 x 3 يكون ذلك 64 x 9 = 576 وزنًا، أي أقل بـ 64 مرة من 36,864 في الطبقة العادية. مخطط الشريحة 20 يقولها في صورة واحدة: ثمانية أسهم مستقيمة من شريط المدخل إلى شريط المخرج، ولا يتقاطع أيٌّ منها.

This is a Depthwise convolution. The slide writes its Weight tensor as (c, k_h, k_w), one k_h x k_w filter per channel. Frameworks keep the four-dimensional layout: PyTorch stores (out_channels, in_channels/groups, kH, kW), which with groups = in_channels is (c, 1, k_h, k_w), the same numbers with a singleton axis. PyTorch also allows out_channels = K · in_channels with groups = in_channels, a depthwise layer with depth multiplier K; the slide's g = c_i = c_o is the case K = 1.

هذا التفاف عمقي depthwise convolution. تكتب الشريحة موتّر أوزانه weight بالشكل (c, k_h, k_w)، أي مرشّح k_h x k_w واحد لكل قناة. لكن أطر العمل تحتفظ بالتخطيط رباعي الأبعاد: PyTorch تخزّن (out_channels, in_channels/groups, kH, kW)، وهو مع groups = in_channels يصبح (c, 1, k_h, k_w)، الأرقام نفسها مع محور طوله واحد. وتسمح PyTorch أيضًا بـ out_channels = K · in_channels مع groups = in_channels، وهي طبقة عمقية بمضاعِف عمق (depth multiplier) قدره K؛ وحالة الشريحة g = c_i = c_o هي الحالة K = 1.

g=ci=co=c:W:(c,1,kh,kw),#weights=c⋅khkwg = c_i = c_o = c: \quad \mathbf{W} : (c, 1, k_h, k_w), \qquad \#\text{weights} = c \cdot k_h k_w
Depthwise convolution: one filter per channelالالتفاف العمقي (depthwise convolution): مرشح واحد لكل قناة

Is this reduction in the number of weights really good?هل هذا التخفيض في عدد الأوزان جيد فعلًا؟

The slide asks the question in red and leaves it open. The honest answer has two halves. For storage and arithmetic, yes: 576 weights fit in 2.3 KB of fp32 flash, and the multiply-accumulates fall by the same factor of 64. For what the layer can learn, no. A depthwise layer filters each channel in isolation. Sandler et al. describe it as lightweight filtering that applies a single convolutional filter per input channel, and Howard et al. point out that it does not combine input channels, so it cannot build a feature that depends on two channels at once. A standard layer does that at every position; a depthwise layer never does.

تطرح الشريحة السؤال باللون الأحمر وتتركه مفتوحًا. الجواب الصادق له نصفان. من ناحية التخزين والحساب، نعم: 576 وزنًا تتسع في 2.3 KB من ذاكرة flash بصيغة fp32، وعمليات الضرب والتجميع تنخفض بالمعامل نفسه 64. أما من ناحية ما تستطيع الطبقة تعلّمه، فلا. الطبقة العمقية ترشّح كل قناة بمعزل عن غيرها. يصفها Sandler et al. بأنها ترشيح خفيف يطبّق مرشّحًا التفافيًا واحدًا لكل قناة مدخلة، ويشير Howard et al. إلى أنها لا تدمج القنوات المدخلة، فلا تستطيع بناء ميزة (feature) تعتمد على قناتين معًا. الطبقة العادية تفعل ذلك في كل موضع؛ والطبقة العمقية لا تفعله أبدًا.

The repair is a 1 x 1 convolution, called a pointwise convolution, placed right after it. With k = 1 it looks at one position and mixes all c_i channels into c_o outputs: W of shape (c_o, c_i, 1, 1), c_o · c_i weights, and in Sandler et al.'s words it is responsible for building new features through computing linear combinations of the input channels. The depthwise layer handles space, the pointwise layer handles channels, and the pair is called a depthwise separable convolution. It is the building block of MobileNet and, wrapped in an expand and project pair of 1 x 1 layers, of MobileNetV2.

الإصلاح هو التفاف 1 x 1، يسمى الالتفاف النقطي (pointwise convolution)، يوضع بعدها مباشرة. مع k = 1 ينظر إلى موضع واحد ويخلط كل القنوات c_i في c_o مخرجًا: W بالشكل (c_o, c_i, 1, 1)، وc_o · c_i وزنًا، وبتعبير Sandler et al. هو المسؤول عن بناء ميزات جديدة بحساب تراكيب خطية من القنوات المدخلة. الطبقة العمقية تتولى المكان، والطبقة النقطية تتولى القنوات، ويسمى الزوج التفافًا عمقيًا قابلًا للفصل depthwise separable convolution. وهو حجر البناء في MobileNet، وفي MobileNetV2 بعد إحاطته بزوج من طبقات 1 x 1 للتوسيع والإسقاط (expand وproject).

Phase one: eight straight lanes, one 3 x 3 filter each, no crossing. Phase two: the 1 x 1 pointwise fan reconnects every channel to every output.المرحلة الأولى: ثمانية مسارات مستقيمة، في كل منها مرشّح 3 x 3 واحد، بلا تقاطع. المرحلة الثانية: مروحة pointwise بحجم 1 x 1 تعيد وصل كل قناة بكل مخرج.
LayerالطبقةWeightsالأوزانBiasesالانحيازاتWeights + biasesالأوزان + الانحيازاتFewer weights than standardعدد أوزان أقل من الطبقة العادية بـ
Standard 3 x 3 (g = 1)عادية 3 x 3 (g = 1)36,86436,864646436,92836,9281x1x
Grouped, g = 2مجمّعة، g = 218,43218,432646418,49618,4962x2x
Grouped, g = 4مجمّعة، g = 49,2169,21664649,2809,2804x4x
Depthwise, g = 64عمقية، g = 64576576646464064064x64x
Depthwise + 1 x 1 pointwiseعمقية + نقطية 1 x 1576 + 4,096 = 4,672576 + 4,096 = 4,6721281284,8004,8007.9x7.9x
c_i = c_o = 64, k = 3, one layer versus the alternativesc_i = c_o = 64، k = 3، طبقة واحدة مقابل البدائل

The last row is the one to remember. Howard et al. derive the cost ratio of a separable block to a standard layer as 1/N + 1/D_K², where N is the output channel count and D_K the kernel size. With N = 64 and D_K = 3 that is 1/64 + 1/9 ≈ 0.127, so the block is about 7.9 times cheaper, matching the table. For wide layers the 1/N term fades and the saving approaches D_K² = 9; Howard et al. report 8 to 9 times less computation for 3 x 3 kernels at a small accuracy cost.

الصف الأخير هو الذي يجب أن تتذكره. يشتق Howard et al. نسبة تكلفة الكتلة القابلة للفصل إلى الطبقة العادية بأنها 1/N + 1/D_K²، حيث N عدد قنوات المخرج وD_K حجم النواة. مع N = 64 وD_K = 3 تكون 1/64 + 1/9 ≈ 0.127، فالكتلة أرخص بنحو 7.9 مرة، وهذا يطابق الجدول. في الطبقات العريضة يتلاشى الحد 1/N ويقترب التوفير من D_K² = 9؛ ويذكر Howard et al. حسابًا أقل بـ 8 إلى 9 مرات لنوى 3 x 3 مقابل خسارة صغيرة في الدقة.

Multiply-accumulates on a 56 x 56 map (h_o · w_o = 3,136)عمليات الضرب والتجميع على خريطة 56 x 56 (h_o · w_o = 3,136)

Standard 3 x 3, 64 to 64عادية 3 x 3، من 64 إلى 64
36,864 x 3,136 = 115,605,504 (about 115.6 M)36,864 x 3,136 = 115,605,504 (نحو 115.6 M)
Depthwise 3 x 3 plus 1 x 1 pointwiseعمقية 3 x 3 مع نقطية 1 x 1
4,672 x 3,136 = 14,651,392 (about 14.7 M)4,672 x 3,136 = 14,651,392 (نحو 14.7 M)
Ratioالنسبة
about 7.9xنحو 7.9x

What this means on an embedded deviceماذا يعني هذا على جهاز مدمج

  • Fewer weights means less flash and less weight traffic from memory, which on a microcontroller is often the whole budget.أوزان أقل تعني ذاكرة flash أقل ونقلًا أقل للأوزان من الذاكرة، وهذا على المتحكم الدقيق (microcontroller) يكون غالبًا هو الميزانية كلها.
  • Fewer multiply-accumulates means lower latency and lower energy per inference on the same core.عمليات ضرب وتجميع أقل تعني زمن تأخير (latency) أقل وطاقة أقل لكل استدلال على النواة الحسابية نفسها.
  • The depthwise layer does only k² multiply-accumulates per output value, against c_i · k² for a standard layer, yet still reads a k x k window per output, so it moves a lot of activation data for little arithmetic and on many accelerators is bound by memory bandwidth rather than compute. Treat the parameter saving as an upper bound on the speedup, not a promise.الطبقة العمقية لا تنفّذ إلا k² عملية ضرب وتجميع لكل قيمة مخرجة، مقابل c_i · k² في الطبقة العادية، ومع ذلك ما زالت تقرأ نافذة k x k لكل مخرج، فهي تنقل الكثير من بيانات التنشيطات مقابل حساب قليل، وعلى كثير من المسرّعات يكون أداؤها محدودًا بعرض نطاق الذاكرة (memory bandwidth) لا بالحساب. اعتبر توفير المعاملات حدًّا أعلى للتسريع، لا وعدًا به.
  • Accuracy drops a little relative to a standard layer of the same shape, which is the price of removing the cross-channel terms.تنخفض الدقة (accuracy) قليلًا مقارنة بطبقة عادية بالشكل نفسه، وهذا هو ثمن إزالة الحدود التي تربط القنوات ببعضها.

Quick checkاختبار سريع

Why does MobileNet follow each depthwise convolution with a 1 x 1 pointwise convolution?لماذا تُتبع MobileNet كل التفاف عمقي (depthwise) بالتفاف نقطي (pointwise) بحجم 1 x 1؟

Recall

Why is a depthwise convolution alone a weak layer on an embedded device, and what fixes it?لماذا يكون الالتفاف العمقي وحده طبقة ضعيفة على جهاز مدمج، وما الذي يصلحه؟

It never mixes information across channels, so it cannot form features that combine channels. A 1 x 1 pointwise convolution after it mixes the channels at c_o · c_i weights, giving the depthwise separable block that MobileNets use.
لأنه لا يخلط المعلومات بين القنوات أبدًا، فلا يستطيع تكوين ميزات تجمع بين القنوات. التفاف نقطي 1 x 1 بعده يخلط القنوات بتكلفة c_o · c_i وزنًا، فنحصل على الكتلة العمقية القابلة للفصل (depthwise separable) التي تستخدمها شبكات MobileNet.

Recall

c_i = c_o = 64, k = 3. How many weights does a depthwise 3 x 3 plus 1 x 1 pointwise block hold, and how does it compare with the standard layer?c_i = c_o = 64، k = 3. كم وزنًا تحمل كتلة depthwise بحجم 3 x 3 مع pointwise بحجم 1 x 1، وكيف تقارن بالطبقة العادية؟

64 x 9 = 576 depthwise plus 64 x 64 = 4,096 pointwise gives 4,672, about 7.9 times fewer than the 36,864 of the standard layer.
64 x 9 = 576 للطبقة العمقية زائد 64 x 64 = 4,096 للطبقة النقطية يعطي 4,672، أي أقل بنحو 7.9 مرة من 36,864 في الطبقة العادية.

Recapالخلاصة

If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا

  • h_o = floor((h_i + 2p - k_h)/s) + 1. With s = 1 and p = (k - 1)/2 the output keeps the input size.h_o = floor((h_i + 2p - k_h)/s) + 1. عندما s = 1 و p = (k - 1)/2 يحافظ المخرج على حجم المدخل.
  • Zero, reflection, replication and constant padding change only the border cells. W is unchanged.الحشو الصفري والانعكاسي والتكراري والثابت (zero و reflection و replication و constant) يغيّر خلايا الإطار فقط. أما W فلا يتغير.
  • One 3 x 3 layer sees 3 x 3. Each stride-1 layer adds k - 1, so L layers give L(k - 1) + 1.طبقة 3 x 3 واحدة ترى 3 x 3. كل طبقة بخطوة 1 تضيف k - 1، لذلك L طبقة تعطي L(k - 1) + 1.
  • With stride, RF_L = RF_(L-1) + (k - 1) times the product of the earlier strides. Stride 2 in layer 1 gives 7 after two 3 x 3 layers.مع الخطوة: RF_L = RF_(L-1) + (k - 1) مضروبًا في حاصل ضرب خطوات الطبقات السابقة. خطوة 2 في الطبقة الأولى تعطي 7 بعد طبقتين 3 x 3.
  • Stride and padding change activations and MACs, never the parameter count.الخطوة والحشو يغيّران التنشيطات (activations) وعدد MACs، ولا يغيّران عدد المعاملات أبدًا.
  • Grouped convolution: W is (c_o, c_i/g, k_h, k_w), g times fewer weights, and c_i and c_o must both be divisible by g.الالتفاف المجمّع (grouped): شكل W هو (c_o, c_i/g, k_h, k_w)، أي أوزان أقل بـ g مرة، ويجب أن يقبل كلٌّ من c_i و c_o القسمة على g.
  • Depthwise convolution is g = c_i = c_o: one k x k filter per channel and no mixing across channels.الالتفاف العمقي (depthwise) هو الحالة g = c_i = c_o: مرشّح k x k واحد لكل قناة ولا خلط بين القنوات.
  • 64 to 64 channels, 3 x 3: 36,864 weights standard, 576 depthwise, 4,672 depthwise plus 1 x 1, about 7.9x fewer.من 64 إلى 64 قناة بنواة 3 x 3: الطبقة العادية 36,864 وزنًا، والعمقية 576، والعمقية مع 1 x 1 تساوي 4,672، أي أقل بنحو 7.9 مرة.
  • The 1 x 1 pointwise convolution restores cross-channel mixing. MobileNets are built on this pair.الالتفاف النقطي (pointwise) 1 x 1 يعيد الخلط بين القنوات. شبكات MobileNet مبنية على هذا الزوج.

Sourcesالمصادر