#[repr(i32)]pub enum PaddingMode {
kEXPLICIT_ROUND_DOWN = 0,
kEXPLICIT_ROUND_UP = 1,
kSAME_UPPER = 2,
kSAME_LOWER = 3,
}Expand description
PaddingMode
Enumerates the modes of padding to perform in convolution, deconvolution and pooling layer, padding mode takes precedence if setPaddingMode() and setPrePadding() are also used.
There are two padding styles, EXPLICIT and SAME with each style having two variants. The EXPLICIT style determine if the final sampling location is used or not. The SAME style determine if the asymmetry in the padding is on the pre or post padding.
Shorthand: I = dimensions of input image. B = prePadding, before the image data. A = postPadding, after the image data. P = delta between input and output S = stride F = filter O = output D = dilation M = I + B + A ; The image data plus any padding DK = 1 + D * (F - 1)
Formulas for Convolution:
- EXPLICIT_ROUND_DOWN:
O = floor((M - DK) / S) + 1
- EXPLICIT_ROUND_UP:
O = ceil((M - DK) / S) + 1
- SAME_UPPER:
O = ceil(I / S) P = floor((I - 1) / S) * S + DK - I; B = floor(P / 2) A = P - B
- SAME_LOWER:
O = ceil(I / S) P = floor((I - 1) / S) * S + DK - I; A = floor(P / 2) B = P - A
Formulas for Deconvolution:
- EXPLICIT_ROUND_DOWN:
- EXPLICIT_ROUND_UP:
O = (I - 1) * S + DK - (B + A)
- SAME_UPPER:
O = min(I * S, (I - 1) * S + DK) P = max(DK - S, 0) B = floor(P / 2) A = P - B
- SAME_LOWER:
O = min(I * S, (I - 1) * S + DK) P = max(DK - S, 0) A = floor(P / 2) B = P - A
Formulas for Pooling:
- EXPLICIT_ROUND_DOWN:
O = floor((M - F) / S) + 1
- EXPLICIT_ROUND_UP:
O = ceil((M - F) / S) + 1
- SAME_UPPER:
O = ceil(I / S) P = floor((I - 1) / S) * S + F - I; B = floor(P / 2) A = P - B
- SAME_LOWER:
O = ceil(I / S) P = floor((I - 1) / S) * S + F - I; A = floor(P / 2) B = P - A
Pooling Example 1:
Given I = {6, 6}, B = {3, 3}, A = {2, 2}, S = {2, 2}, F = {3, 3}. What is O? (B, A can be calculated for SAME_UPPER and SAME_LOWER mode)
- EXPLICIT_ROUND_DOWN:
Computation: M = {6, 6} + {3, 3} + {2, 2} ==> {11, 11} O ==> floor((M - F) / S) + 1 ==> floor(({11, 11} - {3, 3}) / {2, 2}) + {1, 1} ==> floor({8, 8} / {2, 2}) + {1, 1} ==> {5, 5}
- EXPLICIT_ROUND_UP:
Computation: M = {6, 6} + {3, 3} + {2, 2} ==> {11, 11} O ==> ceil((M - F) / S) + 1 ==> ceil(({11, 11} - {3, 3}) / {2, 2}) + {1, 1} ==> ceil({8, 8} / {2, 2}) + {1, 1} ==> {5, 5}
The sample points are {0, 2, 4, 6, 8} in each dimension.
- SAME_UPPER:
Computation: I = {6, 6} S = {2, 2} O = ceil(I / S) = {3, 3} P = floor((I - 1) / S) * S + F - I ==> floor(({6, 6} - {1, 1}) / {2, 2}) * {2, 2} + {3, 3} - {6, 6} ==> {4, 4} + {3, 3} - {6, 6} ==> {1, 1} B = floor({1, 1} / {2, 2}) ==> {0, 0} A = {1, 1} - {0, 0} ==> {1, 1}
- SAME_LOWER:
Computation: I = {6, 6} S = {2, 2} O = ceil(I / S) = {3, 3} P = floor((I - 1) / S) * S + F - I ==> {1, 1} A = floor({1, 1} / {2, 2}) ==> {0, 0} B = {1, 1} - {0, 0} ==> {1, 1}
The sample pointers are {0, 2, 4} in each dimension. SAMPLE_UPPER has {O0, O1, O2, pad} in output in each dimension. SAMPLE_LOWER has {pad, O0, O1, O2} in output in each dimension.
Pooling Example 2:
Given I = {6, 6}, B = {3, 3}, A = {3, 3}, S = {2, 2}, F = {3, 3}. What is O?
Variants§
kEXPLICIT_ROUND_DOWN = 0
< Use explicit padding, rounding output size down.
kEXPLICIT_ROUND_UP = 1
< Use explicit padding, rounding output size up.
kSAME_UPPER = 2
< Use SAME padding, with prePadding <= postPadding.
kSAME_LOWER = 3
< Use SAME padding, with prePadding >= postPadding.
Trait Implementations§
Source§impl Clone for PaddingMode
impl Clone for PaddingMode
Source§fn clone(&self) -> PaddingMode
fn clone(&self) -> PaddingMode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ExternType for PaddingMode
impl ExternType for PaddingMode
Source§impl From<PaddingMode> for PaddingMode
impl From<PaddingMode> for PaddingMode
Source§fn from(value: PaddingMode) -> Self
fn from(value: PaddingMode) -> Self
Source§impl Hash for PaddingMode
impl Hash for PaddingMode
Source§impl Into<PaddingMode> for PaddingMode
impl Into<PaddingMode> for PaddingMode
Source§fn into(self) -> PaddingMode
fn into(self) -> PaddingMode
Source§impl PartialEq for PaddingMode
impl PartialEq for PaddingMode
Source§fn eq(&self, other: &PaddingMode) -> bool
fn eq(&self, other: &PaddingMode) -> bool
self and other values to be equal, and is used by ==.