Skip to content

Convolutional Neural Network implemented in C++. Eigen library is used for matrix manipulations. Convolution layers, Activation layers, Pooling layers and Fully connected layers are available in the network.

License

Notifications You must be signed in to change notification settings

Anomaly-Detection-Research/CNNet

 
 

Repository files navigation

CNNet

License: GPL v3   language   

Convolutional Neural Network

CNN is implemented in C++. Eigen library is used for matrix manipulations. Convolution layers, Activation layers, Pooling layers and Fully connected layers are available in the network. The number of Convolution layers, and Pooling layers and number of layers in the fully connected MLP can be adjusted accordingly. sigmoid function is used as the activation. and non overlapping max pooling is used in the pooling layers. Network is trained using gradient decent method. weights and the bias values for the filter matrices and the fully connected layers are initialized randomly.

Network Architecture

structure

Creating A Network

initializing the layers
int width = 20;
int height = 20;

std::tuple<int, int, int> dimensions = std::make_tuple(1,height,width);

struct::ConvLayStruct CL1;
CL1.filterSize = 5; // filter size: N x N
CL1.filters = 3; // No of filters
CL1.stride = 1;
struct::ConvLayStruct CL2;
CL2.filterSize = 4; // filter size: N x N
CL2.filters = 2; // No of filters
CL2.stride = 1;

struct::PoolLayStruct PL1; // pool size: N x M
PL1.poolH = 2; // N
PL1.poolW = 2; // M
struct::PoolLayStruct PL2; // pool size: N x M
PL2.poolH = 2; // N
PL2.poolW = 2; // M

struct::FCLayStruct FCL1;
FCL1.outputs = 30; // neurons in the layer
struct::FCLayStruct FCL2;
FCL2.outputs = 15; // neurons in the layer
struct::FCLayStruct FCL3;
FCL3.outputs = 5; // neurons in the layer

char layerOrder[] = {'C','P','C','P','F','F','F'};
struct::ConvLayStruct CLs[] = {CL1,CL2};
struct::PoolLayStruct PLs[] = {PL1,PL2};
struct::FCLayStruct FCLs[] = {FCL1,FCL2,FCL3};

struct::NetStruct netStruct;
netStruct.layers = 7;
netStruct.layerOrder = layerOrder;
netStruct.CL = CLs;
netStruct.PL = PLs;
netStruct.FCL = FCLs;
Initializing the network
CNN cnn(dimensions, netStruct);
Training
Eigen::MatrixXd ** inImgArr;
Eigen::MatrixXd * inLblArr;
int iterations = 20;
int inputSize = 1;
double learningRate = 0.00001;
cnn.train(inImgArr, inLblArr, inputSize, iterations, learningRate);
Testing
double result;
Eigen::MatrixXd input[1];
result = cnn.predict(input);

About

Convolutional Neural Network implemented in C++. Eigen library is used for matrix manipulations. Convolution layers, Activation layers, Pooling layers and Fully connected layers are available in the network.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 98.6%
  • Other 1.4%