MachineIntelligenceCore:NeuralNets
|
Class representing a convolution layer, with "valid padding" and variable stride. More...
#include <Convolution.hpp>
Public Member Functions | |
Convolution (size_t input_height_, size_t input_width_, size_t input_channels_, size_t number_of_filters_, size_t filter_size_, size_t stride_, std::string name_="Convolution") | |
virtual | ~Convolution () |
virtual std::string | streamLayerParameters () |
void | forward (bool test=false) |
void | backward () |
void | backpropagade_dy_to_dx () |
void | backpropagade_dy_to_dW () |
void | backpropagade_dy_to_db () |
void | resetGrads () |
void | update (eT alpha_, eT decay_=0.0f) |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > & | getWeightActivations () |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > & | getWeightGradientActivations () |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > & | getReceptiveFields () |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > & | getInverseReceptiveFields () |
mic::types::MatrixPtr< eT > | getFilterSimilarityMatrix () |
eT | cosineSimilarity (eT *A, eT *B, size_t length_) |
![]() | |
Layer (size_t input_height_, size_t input_width_, size_t input_depth_, size_t output_height_, size_t output_width_, size_t output_depth_, LayerTypes layer_type_, std::string name_="layer") | |
virtual | ~Layer () |
mic::types::MatrixPtr< eT > | forward (mic::types::MatrixPtr< eT > x_, bool test=false) |
mic::types::MatrixPtr< eT > | backward (mic::types::MatrixPtr< eT > dy_) |
virtual void | resizeBatch (size_t batch_size_) |
template<typename loss > | |
mic::types::MatrixPtr< eT > | calculateNumericalGradient (mic::types::MatrixPtr< eT > x_, mic::types::MatrixPtr< eT > target_y_, mic::types::MatrixPtr< eT > param_, loss loss_, eT delta_) |
size_t | inputSize () |
Returns size (length) of inputs. More... | |
size_t | outputSize () |
Returns size (length) of outputs. More... | |
size_t | batchSize () |
Returns size (length) of (mini)batch. More... | |
const std::string | name () const |
Returns name of the layer. More... | |
mic::types::MatrixPtr< eT > | getParam (std::string name_) |
mic::types::MatrixPtr< eT > | getState (std::string name_) |
mic::types::MatrixPtr< eT > | getGradient (std::string name_) |
void | setState (std::string name_, mic::types::MatrixPtr< eT > mat_ptr_) |
template<typename omT > | |
void | setOptimization () |
const std::string | type () const |
mic::types::MatrixPtr< eT > | lazyReturnSampleFromBatch (mic::types::MatrixPtr< eT > batch_ptr_, mic::types::MatrixArray< eT > &array_, std::string id_, size_t sample_number_, size_t sample_size_) |
mic::types::MatrixPtr< eT > | lazyReturnInputSample (mic::types::MatrixPtr< eT > batch_ptr_, size_t sample_number_) |
mic::types::MatrixPtr< eT > | lazyReturnOutputSample (mic::types::MatrixPtr< eT > batch_ptr_, size_t sample_number_) |
mic::types::MatrixPtr< eT > | lazyReturnChannelFromSample (mic::types::MatrixPtr< eT > sample_ptr_, mic::types::MatrixArray< eT > &array_, std::string id_, size_t sample_number_, size_t channel_number_, size_t height_, size_t width_) |
mic::types::MatrixPtr< eT > | lazyReturnInputChannel (mic::types::MatrixPtr< eT > sample_ptr_, size_t sample_number_, size_t channel_number_) |
mic::types::MatrixPtr< eT > | lazyReturnOutputChannel (mic::types::MatrixPtr< eT > sample_ptr_, size_t sample_number_, size_t channel_number_) |
void | lazyAllocateMatrixVector (std::vector< std::shared_ptr< mic::types::Matrix< eT > > > &vector_, size_t vector_size_, size_t matrix_height_, size_t matrix_width_) |
virtual std::vector < std::shared_ptr < mic::types::Matrix< eT > > > & | getInputActivations () |
virtual std::vector < std::shared_ptr < mic::types::Matrix< eT > > > & | getInputGradientActivations () |
virtual std::vector < std::shared_ptr < mic::types::Matrix< eT > > > & | getOutputActivations () |
virtual std::vector < std::shared_ptr < mic::types::Matrix< eT > > > & | getOutputGradientActivations () |
Protected Attributes | |
size_t | filter_size |
Size of filters (assuming square filters). Filter_size^2 = length of the output vector. More... | |
size_t | stride |
Stride (assuming equal vertical and horizontal strides). More... | |
![]() | |
size_t | input_height |
Height of the input (e.g. 28 for MNIST). More... | |
size_t | input_width |
Width of the input (e.g. 28 for MNIST). More... | |
size_t | input_depth |
Number of channels of the input (e.g. 3 for RGB images). More... | |
size_t | output_height |
Number of receptive fields in a single channel - vertical direction. More... | |
size_t | output_width |
Number of receptive fields in a single channel - horizontal direction. More... | |
size_t | output_depth |
Number of filters = number of output channels. More... | |
size_t | batch_size |
Size (length) of (mini)batch. More... | |
LayerTypes | layer_type |
Type of the layer. More... | |
std::string | layer_name |
Name (identifier of the type) of the layer. More... | |
mic::types::MatrixArray< eT > | s |
States - contains input [x] and output [y] matrices. More... | |
mic::types::MatrixArray< eT > | g |
Gradients - contains input [x] and output [y] matrices. More... | |
mic::types::MatrixArray< eT > | p |
Parameters - parameters of the layer, to be used by the derived classes. More... | |
mic::types::MatrixArray< eT > | m |
Memory - a list of temporal parameters, to be used by the derived classes. More... | |
mic::neural_nets::optimization::OptimizationArray < eT > | opt |
Array of optimization functions. More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | x_activations |
Vector containing activations of input neurons - used in visualization. More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | dx_activations |
Vector containing activations of gradients of inputs (dx) - used in visualization. More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | y_activations |
Vector containing activations of output neurons - used in visualization. More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | dy_activations |
Vector containing activations of gradients of outputs (dy) - used in visualization. More... | |
Private Member Functions | |
Convolution () | |
Private Attributes | |
std::vector < mic::types::MatrixPtr< eT > > | w_activations |
Vector containing activations of weights/filters. More... | |
std::vector < mic::types::MatrixPtr< eT > > | dw_activations |
Vector containing activations of gradients of weights (dW). More... | |
std::vector < mic::types::MatrixPtr< eT > > | xrf_activations |
Vector containing receptive fields. More... | |
std::vector < mic::types::MatrixPtr< eT > > | irf_activations |
Vector containing inverse receptive fields. More... | |
Friends | |
template<typename tmp > | |
class | mic::mlnn::MultiLayerNeuralNetwork |
Additional Inherited Members | |
![]() | |
Layer () | |
Class representing a convolution layer, with "valid padding" and variable stride.
eT | Template parameter denoting precision of variables (float for calculations/double for testing). |
Definition at line 41 of file Convolution.hpp.
|
inline |
Creates a convolutional layer.
input_height_ | Height of the input / rows (e.g. 28 for MNIST). |
input_width_ | Width of the input / columns (e.g. 28 for MNIST). |
input_channels_ | Number of channels of the input (e.g. 3 for RGB images). |
number_of_filters_ | Number of filters = Length of the output vector. |
filter_size_ | Size of filters (assuming square filters). |
stride_ | Stride (assuming equal vertical and horizontal strides). |
name_ | Name of the layer. |
Definition at line 54 of file Convolution.hpp.
|
inlinevirtual |
Virtual destructor - empty.
Definition at line 159 of file Convolution.hpp.
|
inlineprivate |
Private constructor, used only during the serialization.
Definition at line 838 of file Convolution.hpp.
|
inline |
Back-propagates the gradients from dy to dx.
Definition at line 558 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::backward().
|
inline |
Back-propagates the gradients from dy to dW.
Definition at line 449 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::backward().
|
inline |
Back-propagates the gradients from dy to dx.
Definition at line 335 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::backward().
|
inlinevirtual |
Back-propagates the gradients through the layer.
Implements mic::mlnn::Layer< eT >.
Definition at line 296 of file Convolution.hpp.
|
inline |
Calculates the cosine similarity between two vectors/matrices.
A | Pointer to a memory with the first vector. |
B | Pointer to a memory with the second vector. |
length_ | Length of (both) vector(s). |
Definition at line 777 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::getFilterSimilarityMatrix().
|
inlinevirtual |
Performs forward pass through the filters. Can process batches.
Implements mic::mlnn::Layer< eT >.
Definition at line 186 of file Convolution.hpp.
|
inline |
Returns a matrix containing filter similarities. Note: in diagonal zeros.
Definition at line 738 of file Convolution.hpp.
|
inline |
Returns activations of inverse receptive fields. Limitation: displays receptive fields of the last sample from batch!
Definition at line 707 of file Convolution.hpp.
|
inline |
Returns activations of receptive fields. Limitation: displays receptive fields of the last sample from batch!
Definition at line 675 of file Convolution.hpp.
|
inline |
Returns activations of weights.
Definition at line 613 of file Convolution.hpp.
|
inline |
Returns activations of weight gradients (dx).
Definition at line 644 of file Convolution.hpp.
|
inlinevirtual |
Resets all gradients. Warning: including gx and gy!
Reimplemented from mic::mlnn::Layer< eT >.
Definition at line 579 of file Convolution.hpp.
|
inlinevirtual |
Stream layer parameters.
Reimplemented from mic::mlnn::Layer< eT >.
Definition at line 165 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::Convolution().
|
inlinevirtual |
Applies the gradient update, using the selected optimization method.
alpha_ | Learning rate - passed to the optimization functions of all layers. |
decay_ | Weight decay rate (determining that the "unused/unupdated" weights will decay to 0) (DEFAULT=0.0 - no decay). |
Implements mic::mlnn::Layer< eT >.
Definition at line 590 of file Convolution.hpp.
|
friend |
Definition at line 821 of file Convolution.hpp.
|
private |
Vector containing activations of gradients of weights (dW).
Definition at line 827 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::getWeightGradientActivations().
|
protected |
Size of filters (assuming square filters). Filter_size^2 = length of the output vector.
Definition at line 811 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::backpropagade_dy_to_dW(), mic::mlnn::convolution::Convolution< float >::backpropagade_dy_to_dx(), mic::mlnn::convolution::Convolution< float >::Convolution(), mic::mlnn::convolution::Convolution< float >::forward(), mic::mlnn::convolution::Convolution< float >::getFilterSimilarityMatrix(), mic::mlnn::convolution::Convolution< float >::getInverseReceptiveFields(), mic::mlnn::convolution::Convolution< float >::getReceptiveFields(), mic::mlnn::convolution::Convolution< float >::getWeightActivations(), mic::mlnn::convolution::Convolution< float >::getWeightGradientActivations(), and mic::mlnn::convolution::Convolution< float >::streamLayerParameters().
|
private |
Vector containing inverse receptive fields.
Definition at line 833 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::getInverseReceptiveFields().
|
protected |
Stride (assuming equal vertical and horizontal strides).
Definition at line 814 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::backpropagade_dy_to_dW(), mic::mlnn::convolution::Convolution< float >::backpropagade_dy_to_dx(), mic::mlnn::convolution::Convolution< float >::Convolution(), mic::mlnn::convolution::Convolution< float >::forward(), and mic::mlnn::convolution::Convolution< float >::streamLayerParameters().
|
private |
Vector containing activations of weights/filters.
Definition at line 824 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::getWeightActivations().
|
private |
Vector containing receptive fields.
Definition at line 830 of file Convolution.hpp.
Referenced by mic::mlnn::convolution::Convolution< float >::getReceptiveFields().