AIfES 2  2.0.0
ailayer_conv2d_default.h File Reference

Default implementation of the Conv2D layer . More...

Go to the source code of this file.

Typedefs

typedef struct ailayer_conv2d ailayer_conv2d_f32_t
 

Functions

ailayer_tailayer_conv2d_f32_default (ailayer_conv2d_f32_t *layer, ailayer_t *input_layer)
 Initializes and connect a Conv2D layer with the F32 default implementation. More...
 
ailayer_tailayer_conv2d_cfirst_f32_default (ailayer_conv2d_f32_t *layer, ailayer_t *input_layer)
 Initializes and connect a Conv2D layer (channels first) with the F32 default implementation. More...
 
ailayer_tailayer_conv2d_chw_f32_default (ailayer_conv2d_f32_t *layer, ailayer_t *input_layer)
 Initializes and connect a Conv2D layer (channels first) with the F32 default implementation. More...
 
ailayer_tailayer_conv2d_clast_f32_default (ailayer_conv2d_f32_t *layer, ailayer_t *input_layer)
 Initializes and connect a Conv2D layer (channels last) with the F32 default implementation. More...
 
ailayer_tailayer_conv2d_hwc_f32_default (ailayer_conv2d_f32_t *layer, ailayer_t *input_layer)
 Initializes and connect a Conv2D layer (channels last) with the F32 default implementation. More...
 
void ailayer_conv2d_init_params_f32_default (ailayer_t *self)
 F32 default implementation of the ailayer.init_params function for the Conv2D layer More...
 

Detailed Description

Default implementation of the Conv2D layer .

Version
2.2.0
Date
18.10.2021

Hardware independent implementations of the Conv2D layer in F32 data-type. For more information about the Conv2D layer refer to ailayer_conv2d.h.

Function Documentation

◆ ailayer_conv2d_cfirst_f32_default()

ailayer_t* ailayer_conv2d_cfirst_f32_default ( ailayer_conv2d_f32_t layer,
ailayer_t input_layer 
)

Initializes and connect a Conv2D layer (channels first) with the F32 default implementation.

Code examples are given in the description of ailayer_conv2d_f32_default().

Parameters
*layerThe layer structure to initialize.
*input_layerThe prior layer.
Returns
The (successfully) initialized layer structure.

◆ ailayer_conv2d_chw_f32_default()

ailayer_t* ailayer_conv2d_chw_f32_default ( ailayer_conv2d_f32_t layer,
ailayer_t input_layer 
)

Initializes and connect a Conv2D layer (channels first) with the F32 default implementation.

Code examples are given in the description of ailayer_conv2d_f32_default().

Parameters
*layerThe layer structure to initialize.
*input_layerThe prior layer.
Returns
The (successfully) initialized layer structure.

◆ ailayer_conv2d_clast_f32_default()

ailayer_t* ailayer_conv2d_clast_f32_default ( ailayer_conv2d_f32_t layer,
ailayer_t input_layer 
)

Initializes and connect a Conv2D layer (channels last) with the F32 default implementation.

Code examples are given in the description of ailayer_conv2d_f32_default().

Parameters
*layerThe layer structure to initialize.
*input_layerThe prior layer.
Returns
The (successfully) initialized layer structure.

◆ ailayer_conv2d_f32_default()

ailayer_t* ailayer_conv2d_f32_default ( ailayer_conv2d_f32_t layer,
ailayer_t input_layer 
)

Initializes and connect a Conv2D layer with the F32 default implementation.

Example: Create the layer structure with pretrained weights:
In C:

// Use constant data only for inference. For training remove the const qualifier!!
const float kernel_data_conv2d[] = {0.0f, -0.1f,
0.1f, 0.2f,
-0.2f, 0.2f,
-0.1f, 0.0f};
const float bias_data_conv2d[] = {0.0f, 0.0f};
ailayer_conv2d_f32_t conv2d_layer = {
.kernel_size = {2, 2},
.stride = {1, 1},
.dilation = {1, 1},
.padding = {0, 0},
.weights.data = kernel_data_conv2d,
.bias.data = bias_data_conv2d
};
General Conv2D layer structure.
Definition: ailayer_conv2d.h:57
uint32_t filter_count
Number of filters ( ).
Definition: ailayer_conv2d.h:67

In C, C++ and on Arduino:

// Use constant data only for inference. For training remove the const qualifier!!
const float kernel_data_conv2d[] = {0.0f, -0.1f,
0.1f, 0.2f,
-0.2f, 0.2f,
-0.1f, 0.0f};
const float bias_data_conv2d[] = {0.0f, 0.0f};
ailayer_conv2d_t conv2d_layer = AILAYER_CONV2D_F32_M(
/* filters =*/ 2,
/* kernel_size =*/ HW(2, 2),
/* stride =*/ HW(1, 1),
/* dilation =*/ HW(1, 1),
/* padding =*/ HW(0, 0),
/* weights =*/ kernel_data_conv2d,
/* bias =*/ bias_data_conv2d
);

Example: Create the layer structure for automatic parameter distribution:
In C:

ailayer_conv2d_f32_t conv2d_layer = {
.kernel_size = {2, 2},
.stride = {1, 1},
.dilation = {1, 1},
.padding = {0, 0}
};

In C, C++ and on Arduino:

ailayer_conv2d_t conv2d_layer = AILAYER_CONV2D_F32_A(
/* filters =*/ 2,
/* kernel_size =*/ HW(2, 2),
/* stride =*/ HW(1, 1),
/* dilation =*/ HW(1, 1),
/* padding =*/ HW(0, 0)
);

Example: Initialize and connect the layer for data with channels first (all options are equivalent):

conv2d_layer.channel_axis = 1;
x = ailayer_conv2d_f32_default(&conv2d_layer, x);
ailayer_t * ailayer_conv2d_f32_default(ailayer_conv2d_f32_t *layer, ailayer_t *input_layer)
Initializes and connect a Conv2D layer with the F32 default implementation.
int8_t channel_axis
Index of the channel axis (1 for channels first and -1 or 3 for channels last).
Definition: ailayer_conv2d.h:74

or

x = ailayer_conv2d_cfirst_f32_default(&conv2d_layer, x);
ailayer_t * ailayer_conv2d_cfirst_f32_default(ailayer_conv2d_f32_t *layer, ailayer_t *input_layer)
Initializes and connect a Conv2D layer (channels first) with the F32 default implementation.

or

x = ailayer_conv2d_chw_f32_default(&conv2d_layer, x);
ailayer_t * ailayer_conv2d_chw_f32_default(ailayer_conv2d_f32_t *layer, ailayer_t *input_layer)
Initializes and connect a Conv2D layer (channels first) with the F32 default implementation.

Example: Initialize and connect the layer for data with channels last (all options are equivalent):

conv2d_layer.channel_axis = -1;
x = ailayer_conv2d_f32_default(&conv2d_layer, x);

or

x = ailayer_conv2d_clast_f32_default(&conv2d_layer, x);
ailayer_t * ailayer_conv2d_clast_f32_default(ailayer_conv2d_f32_t *layer, ailayer_t *input_layer)
Initializes and connect a Conv2D layer (channels last) with the F32 default implementation.

or

x = ailayer_conv2d_hwc_f32_default(&conv2d_layer, x);
ailayer_t * ailayer_conv2d_hwc_f32_default(ailayer_conv2d_f32_t *layer, ailayer_t *input_layer)
Initializes and connect a Conv2D layer (channels last) with the F32 default implementation.
Parameters
*layerThe layer structure to initialize.
*input_layerThe prior layer.
Returns
The (successfully) initialized layer structure.

◆ ailayer_conv2d_hwc_f32_default()

ailayer_t* ailayer_conv2d_hwc_f32_default ( ailayer_conv2d_f32_t layer,
ailayer_t input_layer 
)

Initializes and connect a Conv2D layer (channels last) with the F32 default implementation.

Code examples are given in the description of ailayer_conv2d_f32_default().

Parameters
*layerThe layer structure to initialize.
*input_layerThe prior layer.
Returns
The (successfully) initialized layer structure.

◆ ailayer_conv2d_init_params_f32_default()

void ailayer_conv2d_init_params_f32_default ( ailayer_t self)

F32 default implementation of the ailayer.init_params function for the Conv2D layer

Implementation of ailayer.init_params.

The function will initialize the weights and bias depending on the following activation function.

Activation function Weights-init Bias-init
None, tanh, logistic, softmax Glorot Zeros
ReLu and variants He Zeros
Parameters
*selfThe layer structure