Skip to main content

ConvolutionLayerParams

Struct ConvolutionLayerParams 

Source
pub struct ConvolutionLayerParams {
    pub output_channels: u64,
    pub kernel_channels: u64,
    pub n_groups: u64,
    pub kernel_size: Vec<u64>,
    pub stride: Vec<u64>,
    pub dilation_factor: Vec<u64>,
    pub is_deconvolution: bool,
    pub has_bias: bool,
    pub weights: Option<WeightParams>,
    pub bias: Option<WeightParams>,
    pub output_shape: Vec<u64>,
    pub convolution_padding_type: Option<ConvolutionPaddingType>,
}
Expand description

A layer that performs spatial convolution or deconvolution.

.. code::

  y = ConvolutionLayer(x)

Requires 1 or 2 inputs and produces 1 output.

Input First Input: A blob with rank greater than or equal to 4. Rank 4 blob represents [Batch, channels, height, width]. For ranks greater than 4, the leading dimensions, starting from 0 to -4 (inclusive), are all treated as batch.

 From Core ML specification version 4 onwards (iOS >= 13, macOS >= 10.15).
 convolution layer can have 2 inputs, in which case the second input is
 the blob representing the weights. This is allowed when "isDeconvolution" = False.
 The weight blob should have shape
 ``\[outputChannels, kernelChannels, kernelHeight, kernelWidth\]``,
 where kernelChannels == inputChannels / nGroups.

Output Rank is same as the input. e.g.: for rank 4 input, output shape is [B, C_out, H_out, W_out]

If dilationFactor is not 1, effective kernel size is modified as follows:

.. code::

  KernelSize\[0\] <-- (kernelSize\[0\]-1) * dilationFactor\[0\] + 1
  KernelSize\[1\] <-- (kernelSize\[1\]-1) * dilationFactor\[1\] + 1

Type of padding can be valid or same. Output spatial dimensions depend on the the type of padding. For details, refer to the descriptions of the messages “ValidPadding” and “SamePadding”. Padded values are all zeros.

For Deconvolution, ConvolutionPaddingType (valid or same) is ignored when outputShape is set.

Fields§

§output_channels: u64

The number of kernels. Same as C_out used in the layer description.

§kernel_channels: u64

Channel dimension of the kernels. Must be equal to inputChannels / nGroups, if isDeconvolution == False Must be equal to inputChannels, if isDeconvolution == True

§n_groups: u64

Group convolution, i.e. weight reuse along channel axis. Input and kernels are divided into g groups and convolution / deconvolution is applied within the groups independently. If not set or 0, it is set to the default value 1.

§kernel_size: Vec<u64>

Must be length 2 in the order \[H, W\]. If not set, default value \[3, 3\] is used.

§stride: Vec<u64>

Must be length 2 in the order \[H, W\]. If not set, default value \[1, 1\] is used.

§dilation_factor: Vec<u64>

Must be length 2 in order \[H, W\]. If not set, default value \[1, 1\] is used. It is ignored if isDeconvolution == true.

§is_deconvolution: bool

Flag to specify whether it is a deconvolution layer.

§has_bias: bool

Flag to specify whether a bias is to be added or not.

§weights: Option<WeightParams>

Weights associated with this layer. If convolution (isDeconvolution == false), weights have the shape \[outputChannels, kernelChannels, kernelHeight, kernelWidth\], where kernelChannels == inputChannels / nGroups If deconvolution (isDeconvolution == true) weights have the shape \[kernelChannels, outputChannels / nGroups, kernelHeight, kernelWidth\], where kernelChannels == inputChannels

§bias: Option<WeightParams>

Must be of size [outputChannels].

§output_shape: Vec<u64>

The output shape, which has length 2 \[H_out, W_out\]. This is used only for deconvolution (isDeconvolution == true). If not set, the deconvolution output shape is calculated based on ConvolutionPaddingType.

§convolution_padding_type: Option<ConvolutionPaddingType>

The type of padding.

Trait Implementations§

Source§

impl Clone for ConvolutionLayerParams

Source§

fn clone(&self) -> ConvolutionLayerParams

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConvolutionLayerParams

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConvolutionLayerParams

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Message for ConvolutionLayerParams

Source§

fn encoded_len(&self) -> usize

Returns the encoded length of the message without a length delimiter.
Source§

fn clear(&mut self)

Clears the message, resetting all fields to their default.
Source§

fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>
where Self: Sized,

Encodes the message to a buffer. Read more
Source§

fn encode_to_vec(&self) -> Vec<u8>
where Self: Sized,

Encodes the message to a newly allocated buffer.
Source§

fn encode_length_delimited( &self, buf: &mut impl BufMut, ) -> Result<(), EncodeError>
where Self: Sized,

Encodes the message with a length-delimiter to a buffer. Read more
Source§

fn encode_length_delimited_to_vec(&self) -> Vec<u8>
where Self: Sized,

Encodes the message with a length-delimiter to a newly allocated buffer.
Source§

fn decode(buf: impl Buf) -> Result<Self, DecodeError>
where Self: Default,

Decodes an instance of the message from a buffer. Read more
Source§

fn decode_length_delimited(buf: impl Buf) -> Result<Self, DecodeError>
where Self: Default,

Decodes a length-delimited instance of the message from the buffer.
Source§

fn merge(&mut self, buf: impl Buf) -> Result<(), DecodeError>
where Self: Sized,

Decodes an instance of the message from a buffer, and merges it into self. Read more
Source§

fn merge_length_delimited(&mut self, buf: impl Buf) -> Result<(), DecodeError>
where Self: Sized,

Decodes a length-delimited instance of the message from buffer, and merges it into self.
Source§

impl PartialEq for ConvolutionLayerParams

Source§

fn eq(&self, other: &ConvolutionLayerParams) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ConvolutionLayerParams

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.