Factory functions for building the layer specifications of a CNN network.
CNNLayers
00 Remarks
The function names correspond one to one with the MLkit of R# (studio\Rsharp_kit\MLkit\MachineLearning\CNN.vb), so a network definition written in an R# script can be translated line by line into VB. Taking tutorials\..\CNN_image\auto_encoder.R as an example:
' R#:
let cnn = cnn()
+ input_layer([28, 28], 1)
+ conv_layer(5, 32, 1, 2)
+ pool_layer(2, 2, 0)
+ leaky_relu_layer()
+ softmax_layer();
' VB:
Dim cnn = New LayerBuilder() +
input_layer({28, 28}, 1) +
conv_layer(5, 32, 1, 2) +
pool_layer(2, 2, 0) +
leaky_relu_layer() +
softmax_layer()
The only difference is that VB requires the binary operator at the end of the previous line for an implicit line continuation, whereas R# allows it at the start of the next line.
These functions all return CNNLayerArguments objects (layers that have not been created yet). The LayerBuilder + operator instantiates them from left to right, so the resulting layer sequence is identical to calling buildXxxLayer for every layer individually.
01 Syntax
02 Methods
| Name | Overloads | Summary |
|---|---|---|
| spec | 1 | 构造规格对象;name 只用于 CNNLayerArguments.ToString() 的可读输出 |
| input_layer | 2 | Input layer variant that takes the image size directly as a Dimension. |
| conv_layer | 1 | Convolution layer: extracts local features (edges, textures and so on) with a bank of filters. |
| conv_transpose_layer | 1 | Transposed convolution layer: upsamples a feature map back to a larger spatial size (decoder side of an auto encoder, semantic segmentation, and similar scenarios). |
| pool_layer | 1 | Pooling layer: downsamples the feature map inside a sliding window. |
| full_connected_layer | 1 | Fully connected layer: every neuron is connected to the complete output of the previous layer. |
| relu_layer | 1 | ReLU activation: f(x) = max(0, x). |
| leaky_relu_layer | 1 | LeakyReLU activation: keeps a small slope on the negative half axis so neurons do not "die". |
| sigmoid_layer | 1 | Sigmoid activation: f(x) = 1 / (1 + exp(-x)), with output in (0, 1). |
| tanh_layer | 1 | Tanh activation: output in (-1, 1). |
| maxout_layer | 1 | Maxout activation: takes the maximum value inside each group. |
| gaussian_layer | 1 | Gaussian activation layer. |
| lrn_layer | 1 | Local response normalization (LRN): lateral inhibition around strongly responding neurons increases the contrast of high frequency features. |
| dropout_layer | 1 | Dropout layer: randomly drops a fraction of the activations during training to reduce overfitting. |
| softmax_layer | 1 | Softmax: turns the activations into a probability distribution in [0, 1] (multi-class output layer). |
| regression_layer | 1 | Regression loss layer: the loss used for continuous outputs (auto encoders, variational auto encoders). |
03 Members
String, Func(Of LayerBuilder, LayerBuilder))构造规格对象;name 只用于 CNNLayerArguments.ToString() 的可读输出
Int32(), Int32)Input layer: passes the data into the network and declares the image size and channel count.
| Name | Type | Description |
|---|---|---|
size | Int32() | The image size, given as |
depth | Int32 | Number of channels; 1 for grayscale images. |
The input layer specification.
Int32)Input layer variant that takes the image size directly as a Dimension.
| Name | Type | Description |
|---|---|---|
dims | Dimension | The image size. |
depth | Int32 | Number of channels; 1 for grayscale images. |
The input layer specification.
Int32, Int32, Int32, Int32)Convolution layer: extracts local features (edges, textures and so on) with a bank of filters.
| Name | Type | Description |
|---|---|---|
sx | Int32 | Side length of the (square) filter window. |
filters | Int32 | Number of filters, i.e. the number of output channels. |
stride | Int32 | Sliding step of the filter window. |
padding | Int32 | Width of the zero padding applied to the input. |
The convolution layer specification.
Int32(), Int32(), Int32, Int32)Transposed convolution layer: upsamples a feature map back to a larger spatial size (decoder side of an auto encoder, semantic segmentation, and similar scenarios).
| Name | Type | Description |
|---|---|---|
dims | Int32() | Target output size |
filter | Int32() | Filter window |
filters | Int32 | Number of filters. |
stride | Int32 | Stride. |
The transposed convolution layer specification.
Int32, Int32, Int32)Pooling layer: downsamples the feature map inside a sliding window.
| Name | Type | Description |
|---|---|---|
sx | Int32 | Side length of the (square) pooling window. |
stride | Int32 | Stride of the pooling window. |
padding | Int32 | Width of the zero padding applied to the input. |
The pooling layer specification.
Int32)Fully connected layer: every neuron is connected to the complete output of the previous layer.
| Name | Type | Description |
|---|---|---|
size | Int32 | Number of neurons. |
The fully connected layer specification.
ReLU activation: f(x) = max(0, x).
The ReLU layer specification.
LeakyReLU activation: keeps a small slope on the negative half axis so neurons do not "die".
The LeakyReLU layer specification.
Sigmoid activation: f(x) = 1 / (1 + exp(-x)), with output in (0, 1).
The sigmoid layer specification.
Tanh activation: output in (-1, 1).
The tanh layer specification.
Maxout activation: takes the maximum value inside each group.
The maxout layer specification.
Gaussian activation layer.
The Gaussian layer specification.
Int32)Local response normalization (LRN): lateral inhibition around strongly responding neurons increases the contrast of high frequency features.
| Name | Type | Description |
|---|---|---|
n | Int32 | Size of the neighborhood involved in the normalization. |
The LRN layer specification.
Double)Dropout layer: randomly drops a fraction of the activations during training to reduce overfitting.
| Name | Type | Description |
|---|---|---|
drop_prob | Double | Probability of dropping an activation. |
The dropout layer specification.
Softmax: turns the activations into a probability distribution in [0, 1] (multi-class output layer).
The softmax layer specification.
Regression loss layer: the loss used for continuous outputs (auto encoders, variational auto encoders).
The regression layer specification.