DaNNet
|
A convolution layer class. More...
#include <dnn_layer_conv.h>
Public Member Functions | |
layer_conv (const arma::uword n_channels, const arma::uword n_kernel, const arma::uword n_pad=0, const arma::uword n_stride=1) | |
Convolution layer constructor. More... | |
void | init (void) |
Initialization of layer. More... | |
void | upd_buf_size (arma::uword nmb) |
Updates the buffer sizes. More... | |
arma::Mat< DNN_Dtype > | rotate_180 (const arma::Mat< DNN_Dtype > &M) |
Rotates a matrix 180 degree. More... | |
arma::Cube< DNN_Dtype > | rotate_180 (const arma::Cube< DNN_Dtype > &C) |
Rotates each matrix in a cube 180 degree. More... | |
template<typename DNN_Dtype > | |
void | im2col_nzp (DNN_Dtype *Dptr, const DNN_Dtype *Xptr, const arma::uword XRows, const arma::uword XCols, const arma::uword XDepth, const arma::uword KRows, const arma::uword KCols, const arma::uword SRows, const arma::uword SCols) |
Im2col without zero padding. More... | |
template<typename DNN_Dtype > | |
void | im2col (DNN_Dtype *Dptr, const DNN_Dtype *Xptr, const arma::uword XRows, const arma::uword XCols, const arma::uword XDepth, const arma::uword KRows, const arma::uword KCols, const arma::uword PRows, const arma::uword PCols, const arma::uword SRows, const arma::uword SCols) |
Im2col with zero padding. More... | |
template<typename DNN_Dtype > | |
void | im2row (DNN_Dtype *Dptr, const DNN_Dtype *Xptr, const unsigned int XRows, const unsigned int XCols, const unsigned int XDepth, const unsigned int KRows, const unsigned int KCols, const unsigned int PRows, const unsigned int PCols, const unsigned int SRows, const unsigned int SCols) |
Im2row with zero padding. More... | |
void | disp (void) |
Display info about layer. More... | |
arma::uword | get_nrof_params (void) |
Get info about number of trainable parameters in layer. More... | |
void | prop (void) |
Forward propagation though layer. More... | |
void | prop_mb (void) |
Forward mini batch propagation though layer. More... | |
void | backprop (void) |
Backpropagation of mini batch propagation though layer. More... | |
void | update (void) |
Updates the trainable parameters. More... | |
arma::Mat< DNN_Dtype > | weights2img (arma::uword IR) |
Generate an image of the weights. More... | |
![]() | |
layer (void) | |
Layer constructor. More... | |
~layer () | |
virtual void | enable_training (void) |
Enable training of layer. More... | |
virtual void | disable_training (void) |
Disable training of layer. More... | |
virtual void | enable_bias (void) |
Enable bias term in layer. More... | |
virtual void | disable_bias (void) |
Disable bias term in layer. More... | |
virtual arma::Mat< DNN_Dtype > | get_B (void) |
Get bias. More... | |
virtual arma::Cube< DNN_Dtype > | get_W (void) |
Get weights. More... | |
virtual void | set_B (arma::Mat< DNN_Dtype > &b) |
Set bias. More... | |
virtual void | set_W (arma::Cube< DNN_Dtype > &w) |
Set weights. More... | |
virtual void | set_phase (PHASE p) |
Set phase/state. More... | |
virtual void | set_left (layer *lptr) |
Set pointer to left layer. More... | |
virtual void | set_right (layer *rptr) |
Set pointer to right layer. More... | |
virtual void | set_id (const std::string str) |
Set layer id string. More... | |
virtual std::string | get_id (void) |
Get layer id string. More... | |
virtual void | set_type (const std::string str) |
Set layer type string. More... | |
virtual std::string | get_type (void) |
Get layer type string. More... | |
virtual void | set_ix (const arma::uword n) |
Set layer index. More... | |
virtual arma::uword | get_ix (void) |
Get layer index. More... | |
virtual void | set_batch_size (const arma::uword n) |
Set mini batch size. More... | |
virtual arma::uword | get_batch_size (void) |
Get mini batch size. More... | |
virtual void | set_Y1 (arma::Mat< DNN_Dtype > &y) |
Set output buffer. More... | |
virtual void | set_Y (arma::Mat< DNN_Dtype > &y) |
Set output buffer - mini batch. More... | |
virtual void | set_Dleft (arma::Mat< DNN_Dtype > &d) |
Set error output buffer - mini batch. More... | |
virtual void | set_rows_in (arma::uword r) |
Set input buffer row size. More... | |
virtual arma::uword | get_nrof_rows (void) |
Get output buffer row size. More... | |
virtual void | set_cols_in (arma::uword c) |
Set input buffer column size. More... | |
virtual arma::uword | get_nrof_cols (void) |
Get output buffer column size. More... | |
virtual void | set_channels_in (arma::uword l) |
Set input buffer channel/layer size. More... | |
virtual arma::uword | get_nrof_channels (void) |
Get output buffer channel/layer size. More... | |
virtual void | set_opt_alg (opt &alg_class) |
Set pointer to optimizer class. More... | |
virtual opt * | get_opt_alg (void) |
Get pointer to optimizer class. More... | |
virtual arma::uword | get_nrof_inputs (void) |
Get total number of layer inputs. More... | |
virtual arma::uword | get_nrof_outputs (void) |
Get total number of layer outputs. More... | |
virtual arma::Mat< DNN_Dtype > | get_Y1 (void) |
Get output buffer. More... | |
virtual arma::Mat< DNN_Dtype > * | get_Y1_ptr (void) |
Get output buffer pointer. More... | |
virtual DNN_Dtype * | get_Y1_memptr (void) |
Get output buffer memory pointer. More... | |
virtual arma::Mat< DNN_Dtype > | get_Y (void) |
Get output buffer - mini batch. More... | |
virtual arma::Mat< DNN_Dtype > * | get_Y_ptr (void) |
Get output buffer pointer - mini batch. More... | |
virtual DNN_Dtype * | get_Y_memptr (void) |
Get output buffer memory pointer - mini batch. More... | |
virtual DNN_Dtype * | get_Y_colptr (const arma::uword n) |
Get output buffer memory column pointer - mini batch. More... | |
virtual arma::Mat< DNN_Dtype > | get_Dleft () |
Get error buffer - mini batch. More... | |
virtual arma::Mat< DNN_Dtype > * | get_Dleft_ptr (void) |
Get error buffer pointer - mini batch. More... | |
virtual DNN_Dtype * | get_Dleft_memptr (void) |
Get error buffer memory pointer - mini batch. More... | |
virtual DNN_Dtype * | get_Dleft_colptr (const arma::uword n) |
Get error buffer memory column pointer - mini batch. More... | |
virtual void | save_layer_param (std::string name, PARAM_FORMAT f=PARAM_FORMAT::ASCII) |
Save layer weight and bias. More... | |
virtual void | load_layer_param (std::string name, PARAM_FORMAT f=PARAM_FORMAT::AUTO) |
Load layer weight and bias. More... | |
template<typename T > | |
void | init_weights (T &w, arma::uword fan_in, arma::uword fan_out, INIT_W_ALG alg, INIT_W_DIST dist) |
Initiate weights. More... | |
DNN_Dtype | sigmoid (const DNN_Dtype x) |
Sigmoid function - scalar. More... | |
arma::Mat< DNN_Dtype > | sigmoid (const arma::Mat< DNN_Dtype > &x) |
Sigmoid function - matrix. More... | |
arma::Mat< DNN_Dtype > | softmax (const arma::Mat< DNN_Dtype > &x) |
Softmax function - matrix. More... | |
Private Attributes | |
arma::uword | N_filter_size |
Conv. filter size. More... | |
arma::uword | N_pad |
Padding. More... | |
arma::uword | N_stride |
Stride. More... | |
arma::Cube< DNN_Dtype > | C |
Input expanded by im2col. More... | |
arma::Mat< DNN_Dtype > | Cbp |
Input expanded by im2col. More... | |
Additional Inherited Members | |
![]() | |
layer * | left |
Pointer to previous layer. More... | |
layer * | right |
Pointer to next layer. More... | |
std::string | id |
Layer id string. More... | |
std::string | type |
Layer type string. More... | |
arma::uword | layer_ix |
Layer index [0..]. More... | |
bool | train_par |
Enable training. More... | |
bool | add_bias |
Enable bias. More... | |
opt * | opt_alg |
Pointer to optimizer. More... | |
PHASE | phase |
Active state/phase. More... | |
arma::uword | N_batch |
Mini batch size. More... | |
arma::uword | N_rows_left |
Input rows. More... | |
arma::uword | N_cols_left |
Input cols. More... | |
arma::uword | N_channels_left |
Input channels, number of filters. More... | |
arma::uword | N_rows_right |
Output rows. More... | |
arma::uword | N_cols_right |
Output cols. More... | |
arma::uword | N_channels_right |
Output channels, number of filters. More... | |
arma::uword | N_left |
Total size left. More... | |
arma::uword | N_right |
Total size right. More... | |
arma::Mat< DNN_Dtype > | Y |
Output buffer mini batch [N_right,N_batch]. More... | |
arma::Mat< DNN_Dtype > | Y1 |
Output buffer [N_right,1]. More... | |
arma::Mat< DNN_Dtype > | Dleft |
Error buffer [N_left,N_batch]. More... | |
arma::Cube< DNN_Dtype > | W |
Weights. More... | |
arma::Mat< DNN_Dtype > | B |
Bias. More... | |
A convolution layer class.
A layer that convolves (actually correlates) the input layers with a stack of kernel filters. If the input has size [Ri,Ci,Li] and the filter kernel har size [K,K,LiLo] then the output will have size [Ro,Co,Lo] depending upon padding and stride parameters during the convolution.
Definition at line 31 of file dnn_layer_conv.h.
|
inline |
Convolution layer constructor.
[in] | n_channels | Nr of output channels/layers |
[in] | n_kernel | Filter kernel size [KxK] |
[in] | n_pad | Input image padding |
[in] | n_stride | Stride (for row AND col) |
Definition at line 49 of file dnn_layer_conv.h.
|
inlinevirtual |
Backpropagation of mini batch propagation though layer.
Performas a error backpropagation mini batch pass through layer
Reimplemented from dnn::layer.
Definition at line 363 of file dnn_layer_conv.h.
|
inlinevirtual |
Display info about layer.
Reimplemented from dnn::layer.
Definition at line 288 of file dnn_layer_conv.h.
|
inlinevirtual |
Get info about number of trainable parameters in layer.
Reimplemented from dnn::layer.
Definition at line 303 of file dnn_layer_conv.h.
|
inline |
Im2col with zero padding.
[in,out] | Dptr,Xptr | Pointers to destination and source data |
[in] | XRows,XCols | Number of rows/cols in source data |
[in] | XDepth | Number of channels in source data |
[in] | KRows,KCols | Number of rows/cols in kernel (filter) |
[in] | PRows,PCols | Padding for row/col (on each side of image) |
[in] | SRows,SCols | Stride for row/col |
im2col generates a matrix of size [XDepth*KRows*KCols,DRow*Dcol] where DCol=(XCol+2PCol-KCol)/SCol+1 and DRow=(XRow+2PRow-KRow)/SRow+1
Definition at line 183 of file dnn_layer_conv.h.
|
inline |
Im2col without zero padding.
[in,out] | Dptr,Xptr | Pointers to destination and source data |
[in] | XRows,XCols | Number of rows/cols in source data |
[in] | XDepth | Number of channels in source data |
[in] | KRows,KCols | Number of rows/cols in kernel (filter) |
[in] | SRows,SCols | Stride for row/col |
im2col_nzp generates a matrix of size [XDepth*KRows*KCols,DRow*Dcol] where DCol=(XCol-KCol)/SCol+1 and DRow=(XRow-KRow)/SRow+1
Definition at line 141 of file dnn_layer_conv.h.
|
inline |
Im2row with zero padding.
[in,out] | Dptr,Xptr | Pointers to destination and source data |
[in] | XRows,XCols | Number of rows/cols in source data |
[in] | XDepth | Number of channels in source data |
[in] | KRows,KCols | Number of rows/cols in kernel (filter) |
[in] | PRows,PCols | Padding for row/col (on each side of image) |
[in] | SRows,SCols | Stride for row/col |
im2row generates a matrix of size [DRow*Dcol,XDepth*KRows*KCols] where DCol=(XCol+2PCol-KCol)/SCol+1 and DRow=(XRow+2PRow-KRow)/SRow+1
Definition at line 246 of file dnn_layer_conv.h.
|
inlinevirtual |
Initialization of layer.
Calculates the output and internal buffer sizes and initializes the parameters
Reimplemented from dnn::layer.
Definition at line 66 of file dnn_layer_conv.h.
|
inlinevirtual |
Forward propagation though layer.
Performas a forward pass through layer
Reimplemented from dnn::layer.
Definition at line 313 of file dnn_layer_conv.h.
|
inlinevirtual |
Forward mini batch propagation though layer.
Performas a forward mini batch pass through layer
Reimplemented from dnn::layer.
Definition at line 337 of file dnn_layer_conv.h.
Rotates a matrix 180 degree.
[in] | M | Input matrix |
Rotates a matrix 180 degree (equals fliplr(flipud(M)) in Matlab)
Definition at line 106 of file dnn_layer_conv.h.
Rotates each matrix in a cube 180 degree.
[in] | C | Input matrix |
Rotates each matrix 180 degree (equals flipud(fliplr(C)) in Matlab)
Definition at line 119 of file dnn_layer_conv.h.
|
inlinevirtual |
Updates the buffer sizes.
[in] | nmb | New mini batch buffer size |
Updates and clears the buffer sizes, called when size of mini batch is changed
Reimplemented from dnn::layer.
Definition at line 93 of file dnn_layer_conv.h.
|
inlinevirtual |
Updates the trainable parameters.
Calculates the gradients and update the trainiable parameters
Reimplemented from dnn::layer.
Definition at line 384 of file dnn_layer_conv.h.
|
inline |
Generate an image of the weights.
[in] | IR | Number of images per row |
Flattens weights from each layer into a concatenated image
Definition at line 423 of file dnn_layer_conv.h.
|
private |
Input expanded by im2col.
Definition at line 38 of file dnn_layer_conv.h.
|
private |
Input expanded by im2col.
Definition at line 39 of file dnn_layer_conv.h.
|
private |
Conv. filter size.
Definition at line 34 of file dnn_layer_conv.h.
|
private |
Padding.
Definition at line 35 of file dnn_layer_conv.h.
|
private |
Stride.
Definition at line 36 of file dnn_layer_conv.h.