#[repr(i32)]pub enum PaddingMode {
kEXPLICIT_ROUND_DOWN = 0,
kEXPLICIT_ROUND_UP = 1,
kSAME_UPPER = 2,
kSAME_LOWER = 3,
}Expand description
! ! \enum PaddingMode ! ! \brief 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. ! ! \code ! 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) ! \endcode ! ! Formulas for Convolution: ! - EXPLICIT_ROUND_DOWN: ! \code ! O = floor((M - DK) / S) + 1 ! \endcode ! - EXPLICIT_ROUND_UP: ! \code ! O = ceil((M - DK) / S) + 1 ! \endcode ! - SAME_UPPER: ! \code ! O = ceil(I / S) ! P = floor((I - 1) / S) * S + DK - I; ! B = floor(P / 2) ! A = P - B ! \endcode ! - SAME_LOWER: ! \code ! O = ceil(I / S) ! P = floor((I - 1) / S) * S + DK - I; ! A = floor(P / 2) ! B = P - A ! \endcode ! ! Formulas for Deconvolution: ! - EXPLICIT_ROUND_DOWN: ! - EXPLICIT_ROUND_UP: ! \code ! O = (I - 1) * S + DK - (B + A) ! \endcode ! - SAME_UPPER: ! \code ! O = min(I * S, (I - 1) * S + DK) ! P = max(DK - S, 0) ! B = floor(P / 2) ! A = P - B ! \endcode ! - SAME_LOWER: ! \code ! O = min(I * S, (I - 1) * S + DK) ! P = max(DK - S, 0) ! A = floor(P / 2) ! B = P - A ! \endcode ! ! Formulas for Pooling: ! - EXPLICIT_ROUND_DOWN: ! \code ! O = floor((M - F) / S) + 1 ! \endcode ! - EXPLICIT_ROUND_UP: ! \code ! O = ceil((M - F) / S) + 1 ! \endcode ! - SAME_UPPER: ! \code ! O = ceil(I / S) ! P = floor((I - 1) / S) * S + F - I; ! B = floor(P / 2) ! A = P - B ! \endcode ! - SAME_LOWER: ! \code ! O = ceil(I / S) ! P = floor((I - 1) / S) * S + F - I; ! A = floor(P / 2) ! B = P - A ! \endcode ! ! Pooling Example 1: ! \code ! 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) ! \endcode ! ! - EXPLICIT_ROUND_DOWN: ! \code ! 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} ! \endcode ! - EXPLICIT_ROUND_UP: ! \code ! 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} ! \endcode ! The sample points are {0, 2, 4, 6, 8} in each dimension. ! ! - SAME_UPPER: ! \code ! 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} ! \endcode ! - SAME_LOWER: ! \code ! 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} ! \endcode ! 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: ! \code ! Given I = {6, 6}, B = {3, 3}, A = {3, 3}, S = {2, 2}, F = {3, 3}. What is O? ! \endcode !
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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more