项目作者: heshanera

项目描述 :
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.
高级语言: C++
项目地址: git://github.com/heshanera/CNNet.git
创建时间: 2018-06-06T16:19:24Z
项目社区:https://github.com/heshanera/CNNet

开源协议:GNU General Public License v3.0

下载


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
  1. int width = 20;
  2. int height = 20;
  3. std::tuple<int, int, int> dimensions = std::make_tuple(1,height,width);
  4. struct::ConvLayStruct CL1;
  5. CL1.filterSize = 5; // filter size: N x N
  6. CL1.filters = 3; // No of filters
  7. CL1.stride = 1;
  8. struct::ConvLayStruct CL2;
  9. CL2.filterSize = 4; // filter size: N x N
  10. CL2.filters = 2; // No of filters
  11. CL2.stride = 1;
  12. struct::PoolLayStruct PL1; // pool size: N x M
  13. PL1.poolH = 2; // N
  14. PL1.poolW = 2; // M
  15. struct::PoolLayStruct PL2; // pool size: N x M
  16. PL2.poolH = 2; // N
  17. PL2.poolW = 2; // M
  18. struct::FCLayStruct FCL1;
  19. FCL1.outputs = 30; // neurons in the layer
  20. struct::FCLayStruct FCL2;
  21. FCL2.outputs = 15; // neurons in the layer
  22. struct::FCLayStruct FCL3;
  23. FCL3.outputs = 5; // neurons in the layer
  24. char layerOrder[] = {'C','P','C','P','F','F','F'};
  25. struct::ConvLayStruct CLs[] = {CL1,CL2};
  26. struct::PoolLayStruct PLs[] = {PL1,PL2};
  27. struct::FCLayStruct FCLs[] = {FCL1,FCL2,FCL3};
  28. struct::NetStruct netStruct;
  29. netStruct.layers = 7;
  30. netStruct.layerOrder = layerOrder;
  31. netStruct.CL = CLs;
  32. netStruct.PL = PLs;
  33. netStruct.FCL = FCLs;
Initializing the network
  1. CNN cnn(dimensions, netStruct);
Training
  1. Eigen::MatrixXd ** inImgArr;
  2. Eigen::MatrixXd * inLblArr;
  3. int iterations = 20;
  4. int inputSize = 1;
  5. double learningRate = 0.00001;
  6. cnn.train(inImgArr, inLblArr, inputSize, iterations, learningRate);
Testing
  1. double result;
  2. Eigen::MatrixXd input[1];
  3. result = cnn.predict(input);