├── CNN_05_12 ├── LayerQL.cpp ├── MatrixQL.cpp ├── NetQL.cpp ├── Bias_LayerQL.cpp ├── Inter_LayerQL.cpp ├── Fullconnect_LayerQL.cpp ├── NetQL.h ├── Test.cpp ├── Test.h ├── LayerQL.h ├── LoadCSV.h ├── MatrixQL.h ├── Source.cpp ├── Cifar10_T2.h ├── Conv_Test.h ├── LoadCSV.cpp ├── PooLayerQL.h ├── Pool_Test.h ├── TuLi_Test.h ├── Bias_LayerQL.h ├── Conv_LayerQL.h ├── Inter_LayerQL.h ├── LoadCSV_Test.h ├── Mnist_Conv_T2.h ├── PooLayerQL.cpp ├── Relu_LayerQL.h ├── Sigmoid_Test.h ├── Bias_Conv_Layer.h ├── MSE_Loss_LayerQL.h ├── Mnist_Conv_Test.h ├── Padding_LayerQL.h ├── Sigmoid_LayerQL.h ├── Relu_LayerQL_Test.h ├── Bias_Conv_Layer_Test.h ├── Fullconnect_LayerQL.h ├── Conv_Test.cpp ├── LoadCSV_Test.cpp ├── Relu_LayerQL.cpp ├── Sigmoid_LayerQL.cpp ├── Pool_Test.cpp ├── Bias_Conv_Layer.cpp ├── Dim_Reduce_Test.cpp ├── Mnist_Conv_Test.cpp ├── SoftMax_LayerQL.cpp ├── MSE_Loss_LayerQL.cpp ├── Relu_LayerQL_Test.cpp ├── Dim_ReduceQL.cpp ├── Data_AugmentationQL.cpp ├── Sigmoid_Test.cpp ├── SoftMax_Layer_Test.cpp ├── Bias_Conv_Layer_Test.cpp ├── Data_Augmentation_Test.cpp ├── Conv_LayerQL.cpp ├── SoftMax_LayerQL.h ├── SoftMax_Layer_Test.h ├── Data_AugmentationQL.h ├── Padding_LayerQL.cpp ├── Data_Augmentation_Test.h ├── Dim_ReduceQL.h └── Dim_Reduce_Test.h ├── .gitignore ├── .gitattributes ├── README.md └── LICENSE /CNN_05_12/LayerQL.cpp: -------------------------------------------------------------------------------- 1 | #include "LayerQL.h" -------------------------------------------------------------------------------- /CNN_05_12/MatrixQL.cpp: -------------------------------------------------------------------------------- 1 | #include "MatrixQL.h" -------------------------------------------------------------------------------- /CNN_05_12/NetQL.cpp: -------------------------------------------------------------------------------- 1 | #include "NetQL.h" 2 | 3 | -------------------------------------------------------------------------------- /CNN_05_12/Bias_LayerQL.cpp: -------------------------------------------------------------------------------- 1 | #include "Bias_LayerQL.h" -------------------------------------------------------------------------------- /CNN_05_12/Inter_LayerQL.cpp: -------------------------------------------------------------------------------- 1 | #include "Inter_LayerQL.h" -------------------------------------------------------------------------------- /CNN_05_12/Fullconnect_LayerQL.cpp: -------------------------------------------------------------------------------- 1 | #include "Fullconnect_LayerQL.h" 2 | 3 | -------------------------------------------------------------------------------- /CNN_05_12/NetQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/NetQL.h -------------------------------------------------------------------------------- /CNN_05_12/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Test.cpp -------------------------------------------------------------------------------- /CNN_05_12/Test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Test.h -------------------------------------------------------------------------------- /CNN_05_12/LayerQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/LayerQL.h -------------------------------------------------------------------------------- /CNN_05_12/LoadCSV.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/LoadCSV.h -------------------------------------------------------------------------------- /CNN_05_12/MatrixQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/MatrixQL.h -------------------------------------------------------------------------------- /CNN_05_12/Source.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Source.cpp -------------------------------------------------------------------------------- /CNN_05_12/Cifar10_T2.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Cifar10_T2.h -------------------------------------------------------------------------------- /CNN_05_12/Conv_Test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Conv_Test.h -------------------------------------------------------------------------------- /CNN_05_12/LoadCSV.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/LoadCSV.cpp -------------------------------------------------------------------------------- /CNN_05_12/PooLayerQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/PooLayerQL.h -------------------------------------------------------------------------------- /CNN_05_12/Pool_Test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Pool_Test.h -------------------------------------------------------------------------------- /CNN_05_12/TuLi_Test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/TuLi_Test.h -------------------------------------------------------------------------------- /CNN_05_12/Bias_LayerQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Bias_LayerQL.h -------------------------------------------------------------------------------- /CNN_05_12/Conv_LayerQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Conv_LayerQL.h -------------------------------------------------------------------------------- /CNN_05_12/Inter_LayerQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Inter_LayerQL.h -------------------------------------------------------------------------------- /CNN_05_12/LoadCSV_Test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/LoadCSV_Test.h -------------------------------------------------------------------------------- /CNN_05_12/Mnist_Conv_T2.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Mnist_Conv_T2.h -------------------------------------------------------------------------------- /CNN_05_12/PooLayerQL.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/PooLayerQL.cpp -------------------------------------------------------------------------------- /CNN_05_12/Relu_LayerQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Relu_LayerQL.h -------------------------------------------------------------------------------- /CNN_05_12/Sigmoid_Test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Sigmoid_Test.h -------------------------------------------------------------------------------- /CNN_05_12/Bias_Conv_Layer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Bias_Conv_Layer.h -------------------------------------------------------------------------------- /CNN_05_12/MSE_Loss_LayerQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/MSE_Loss_LayerQL.h -------------------------------------------------------------------------------- /CNN_05_12/Mnist_Conv_Test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Mnist_Conv_Test.h -------------------------------------------------------------------------------- /CNN_05_12/Padding_LayerQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Padding_LayerQL.h -------------------------------------------------------------------------------- /CNN_05_12/Sigmoid_LayerQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Sigmoid_LayerQL.h -------------------------------------------------------------------------------- /CNN_05_12/Relu_LayerQL_Test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Relu_LayerQL_Test.h -------------------------------------------------------------------------------- /CNN_05_12/Bias_Conv_Layer_Test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Bias_Conv_Layer_Test.h -------------------------------------------------------------------------------- /CNN_05_12/Fullconnect_LayerQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LONGMIAOMIAO/Tiny_CNN/HEAD/CNN_05_12/Fullconnect_LayerQL.h -------------------------------------------------------------------------------- /CNN_05_12/Conv_Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Conv_Test.h" 2 | 3 | namespace tinyDNN 4 | { 5 | //Conv_Test::Conv_Test(){} 6 | 7 | //Conv_Test::~Conv_Test(){} 8 | } -------------------------------------------------------------------------------- /CNN_05_12/LoadCSV_Test.cpp: -------------------------------------------------------------------------------- 1 | #include "LoadCSV_Test.h" 2 | 3 | //LoadCSV_Test::LoadCSV_Test() 4 | //{ 5 | //} 6 | // 7 | // 8 | //LoadCSV_Test::~LoadCSV_Test() 9 | //{ 10 | //} 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.suo 2 | *.db 3 | *.vcxproj 4 | *.opendb 5 | *.tlog 6 | *.obj 7 | *.filters 8 | *.exe 9 | *.log 10 | *.pdb 11 | *.ipdb 12 | *.iobj 13 | *.ilk 14 | *.sln 15 | *.user 16 | *.idb -------------------------------------------------------------------------------- /CNN_05_12/Relu_LayerQL.cpp: -------------------------------------------------------------------------------- 1 | #include "Relu_LayerQL.h" 2 | 3 | 4 | 5 | //Relu_LayerQL::Relu_LayerQL() 6 | //{ 7 | //} 8 | // 9 | // 10 | //Relu_LayerQL::~Relu_LayerQL() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /CNN_05_12/Sigmoid_LayerQL.cpp: -------------------------------------------------------------------------------- 1 | #include "Sigmoid_LayerQL.h" 2 | 3 | //Sigmoid_LayerQL::Sigmoid_LayerQL() 4 | //{ 5 | //} 6 | // 7 | // 8 | //Sigmoid_LayerQL::~Sigmoid_LayerQL() 9 | //{ 10 | //} 11 | -------------------------------------------------------------------------------- /CNN_05_12/Pool_Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Pool_Test.h" 2 | 3 | namespace tinyDNN 4 | { 5 | 6 | //Pool_Test::Pool_Test() 7 | //{ 8 | //} 9 | 10 | 11 | //Pool_Test::~Pool_Test() 12 | //{ 13 | //} 14 | 15 | } -------------------------------------------------------------------------------- /CNN_05_12/Bias_Conv_Layer.cpp: -------------------------------------------------------------------------------- 1 | #include "Bias_Conv_Layer.h" 2 | 3 | 4 | // 5 | //Bias_Conv_Layer::Bias_Conv_Layer() 6 | //{ 7 | //} 8 | // 9 | // 10 | //Bias_Conv_Layer::~Bias_Conv_Layer() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /CNN_05_12/Dim_Reduce_Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Dim_Reduce_Test.h" 2 | 3 | 4 | // 5 | //Dim_Reduce_Test::Dim_Reduce_Test() 6 | //{ 7 | //} 8 | // 9 | // 10 | //Dim_Reduce_Test::~Dim_Reduce_Test() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /CNN_05_12/Mnist_Conv_Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Mnist_Conv_Test.h" 2 | 3 | 4 | 5 | //Mnist_Conv_Test::Mnist_Conv_Test() 6 | //{ 7 | //} 8 | // 9 | // 10 | //Mnist_Conv_Test::~Mnist_Conv_Test() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /CNN_05_12/SoftMax_LayerQL.cpp: -------------------------------------------------------------------------------- 1 | #include "SoftMax_LayerQL.h" 2 | 3 | // 4 | // 5 | //SoftMax_LayerQL::SoftMax_LayerQL() 6 | //{ 7 | //} 8 | // 9 | // 10 | //SoftMax_LayerQL::~SoftMax_LayerQL() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /CNN_05_12/MSE_Loss_LayerQL.cpp: -------------------------------------------------------------------------------- 1 | #include "MSE_Loss_LayerQL.h" 2 | 3 | 4 | 5 | //MSE_Loss_LayerQL::MSE_Loss_LayerQL() 6 | //{ 7 | //} 8 | // 9 | // 10 | //MSE_Loss_LayerQL::~MSE_Loss_LayerQL() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /CNN_05_12/Relu_LayerQL_Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Relu_LayerQL_Test.h" 2 | 3 | 4 | 5 | //Relu_LayerQL_Test::Relu_LayerQL_Test() 6 | //{ 7 | //} 8 | // 9 | // 10 | //Relu_LayerQL_Test::~Relu_LayerQL_Test() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /CNN_05_12/Dim_ReduceQL.cpp: -------------------------------------------------------------------------------- 1 | #include "Dim_ReduceQL.h" 2 | 3 | namespace tinyDNN 4 | { 5 | 6 | //Dim_ReduceQL::Dim_ReduceQL() 7 | //{ 8 | //} 9 | // 10 | // 11 | //Dim_ReduceQL::~Dim_ReduceQL() 12 | //{ 13 | //} 14 | } -------------------------------------------------------------------------------- /CNN_05_12/Data_AugmentationQL.cpp: -------------------------------------------------------------------------------- 1 | #include "Data_AugmentationQL.h" 2 | 3 | 4 | 5 | //Data_AugmentationQL::Data_AugmentationQL() 6 | //{ 7 | //} 8 | // 9 | // 10 | //Data_AugmentationQL::~Data_AugmentationQL() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /CNN_05_12/Sigmoid_Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Sigmoid_Test.h" 2 | 3 | namespace tinyDNN 4 | { 5 | 6 | //Sigmoid_Test::Sigmoid_Test() 7 | //{ 8 | //} 9 | // 10 | // 11 | //Sigmoid_Test::~Sigmoid_Test() 12 | //{ 13 | //} 14 | 15 | } -------------------------------------------------------------------------------- /CNN_05_12/SoftMax_Layer_Test.cpp: -------------------------------------------------------------------------------- 1 | #include "SoftMax_Layer_Test.h" 2 | 3 | 4 | // 5 | //SoftMax_Layer_Test::SoftMax_Layer_Test() 6 | //{ 7 | //} 8 | // 9 | // 10 | //SoftMax_Layer_Test::~SoftMax_Layer_Test() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /CNN_05_12/Bias_Conv_Layer_Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Bias_Conv_Layer_Test.h" 2 | 3 | 4 | 5 | //Bias_Conv_Layer_Test::Bias_Conv_Layer_Test() 6 | //{ 7 | //} 8 | // 9 | // 10 | //Bias_Conv_Layer_Test::~Bias_Conv_Layer_Test() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /CNN_05_12/Data_Augmentation_Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Data_Augmentation_Test.h" 2 | 3 | 4 | 5 | //Data_Augmentation_Test::Data_Augmentation_Test() 6 | //{ 7 | //} 8 | // 9 | // 10 | //Data_Augmentation_Test::~Data_Augmentation_Test() 11 | //{ 12 | //} 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tiny_CNN是一个轻型CNN框架,基于C++和C++矩阵运算库Eigen实现,目前仅支持CPU运算。 2 | 3 | 1、 Tiny_CNN自定义实现了Convolution、Pooling、FullConnect、Softmax、CrossEntropy 等Layers 及其FP、BP 和Weight Update,实现了Sigmoid、Tanh、Relu、LRelu等激活函数。通过运算符重载实现了快捷构建基于自定义卷积核数目、自定义Layers 类型和层数的计算模型,可以快速进行模型搭建,快速运算。 4 | 5 | 2、 基于该框架快速计算模型精度如下: 6 | Mnist Accuracy : 99% 7 | Net 结构 : 2 * ( Conv + LRelu + Pool ) + 2 * ( FullConn + LRelu ) + Softmax_Cross_Entropy 8 | Cifar Accuracy : 70% 9 | Net 结构 : 2 * ( Conv + LRelu + Pool ) + 2 * ( FullConn + LRelu ) + Softmax_Cross_Entropy 10 | 11 | 3、 水平有限,代码有不完善的地方请在ISSUE批评指正! -------------------------------------------------------------------------------- /CNN_05_12/Conv_LayerQL.cpp: -------------------------------------------------------------------------------- 1 | #include "Conv_LayerQL.h" 2 | 3 | namespace tinyDNN 4 | { 5 | //template 6 | //Conv_LayerQL::Conv_LayerQL(LayerType type) : LayerQL(type) 7 | //{ 8 | // 9 | //} 10 | 11 | //template 12 | //Conv_LayerQL::~Conv_LayerQL() 13 | //{ 14 | 15 | //} 16 | 17 | //template 18 | //void Conv_LayerQL::calForward() const 19 | //{ 20 | 21 | //} 22 | 23 | //template 24 | //void Conv_LayerQL::calBackward() 25 | //{ 26 | 27 | //} 28 | 29 | //template class Conv_LayerQL; 30 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Qiong 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CNN_05_12/SoftMax_LayerQL.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "LayerQL.h" 3 | 4 | namespace tinyDNN 5 | { 6 | template 7 | class SoftMax_LayerQL : public LayerQL 8 | { 9 | public: 10 | explicit SoftMax_LayerQL(LayerType type) : LayerQL(type) 11 | { 12 | std::cout << "SoftMax_LayerQL Start!" << std::endl; 13 | } 14 | ~SoftMax_LayerQL() 15 | { 16 | std::cout << "SoftMax_LayerQL Over!" << std::endl; 17 | } 18 | 19 | void calForward(int type = 0) const override final 20 | { 21 | //this->outData = inData.array().exp().matrix() / (inData.array().exp()).sum(); 22 | this->right_Layer->forward_Matrix->setMatrixQL() = this->left_Layer->forward_Matrix->getMatrixQL().array().exp().matrix() / (this->left_Layer->forward_Matrix->getMatrixQL().array().exp()).sum(); 23 | } 24 | 25 | void calBackward(int type = 0) override final 26 | { 27 | this->left_Layer->backward_Matrix->setMatrixQL() = this->right_Layer->forward_Matrix->getMatrixQL() - this->right_Layer->backward_Matrix->getMatrixQL(); 28 | } 29 | 30 | void upMatrix() override final {}; 31 | void upMatrix_batch(Dtype upRate) override final {}; 32 | }; 33 | 34 | } -------------------------------------------------------------------------------- /CNN_05_12/SoftMax_Layer_Test.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SoftMax_LayerQL.h" 3 | #include "NetQL.h" 4 | 5 | namespace tinyDNN 6 | { 7 | class SoftMax_Layer_Test 8 | { 9 | public: 10 | SoftMax_Layer_Test() 11 | { 12 | this->softForAndBakcWard(); 13 | } 14 | ~SoftMax_Layer_Test() 15 | { 16 | } 17 | 18 | void softForAndBakcWard() 19 | { 20 | std::shared_ptr> in_01 = std::make_shared>(1, 5); 21 | //std::shared_ptr> in_01 = std::make_shared>(1, 5); 22 | int s = -2; 23 | for ( int i = 0; i < 5; i++ ) 24 | { 25 | in_01->forward_Matrix->setMatrixQL()(0, i) = s; 26 | s++; 27 | } 28 | std::shared_ptr> soft_01 = std::make_shared>(SoftMax_Layer); 29 | 30 | std::shared_ptr> o_01 = in_01 + soft_01; 31 | 32 | soft_01->calForward(); 33 | 34 | std::cout << o_01->forward_Matrix->getMatrixQL() << std::endl; 35 | 36 | o_01->backward_Matrix = std::make_shared>(1,5); 37 | o_01->backward_Matrix->setMatrixQL().setZero(); 38 | o_01->backward_Matrix->setMatrixQL()(0, 0) = 1; 39 | 40 | soft_01->calBackward(); 41 | 42 | std::cout << in_01->backward_Matrix->getMatrixQL() << std::endl; 43 | 44 | // std::shared_ptr> relu_LayerQL_Test = std::make_shared>(Relu_Layer); 45 | } 46 | }; 47 | } -------------------------------------------------------------------------------- /CNN_05_12/Data_AugmentationQL.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "LayerQL.h" 3 | 4 | namespace tinyDNN 5 | { 6 | template 7 | class Data_AugmentationQL : public LayerQL 8 | { 9 | public: 10 | Data_AugmentationQL(LayerType type, int rowNum, int colNum) : LayerQL(type), rowNum(rowNum), colNum(colNum) 11 | { 12 | std::cout << "Data_AugmentationQL Start!" << std::endl; 13 | } 14 | ~Data_AugmentationQL() override final 15 | { 16 | std::cout << "Data_AugmentationQL Over!" << std::endl; 17 | } 18 | void calForward(int type = 0) const override final 19 | { 20 | this->right_Layer->forward_Matrix_Vector.clear(); 21 | int randCase = rand() % 2; 22 | for ( auto i = this->left_Layer->forward_Matrix_Vector.begin(); i != this->left_Layer->forward_Matrix_Vector.end(); i++ ) 23 | { 24 | std::shared_ptr> augMatrix = std::make_shared>(rowNum, colNum); 25 | 26 | switch (randCase) 27 | { 28 | case 0: 29 | augMatrix = *i; 30 | break; 31 | case 1: 32 | augMatrix->setMatrixQL() = (*i)->getMatrixQL().rowwise().reverse(); 33 | break; 34 | } 35 | 36 | this->right_Layer->forward_Matrix_Vector.push_back(augMatrix); 37 | } 38 | 39 | } 40 | void calBackward(int type = 0) override final {}; 41 | 42 | void upMatrix() override final {}; 43 | void upMatrix_batch(Dtype upRate) override final {}; 44 | 45 | private: 46 | int rowNum; 47 | int colNum; 48 | }; 49 | } -------------------------------------------------------------------------------- /CNN_05_12/Padding_LayerQL.cpp: -------------------------------------------------------------------------------- 1 | #include "Padding_LayerQL.h" 2 | 3 | namespace tinyDNN 4 | { 5 | template 6 | Padding_LayerQL::Padding_LayerQL(LayerType type, int rowNum, int colNum, int padSize) : LayerQL(type), rowNum(rowNum), colNum(colNum), padSize(padSize) 7 | { 8 | std::cout << "PooLayerQL Start!" << std::endl; 9 | 10 | } 11 | 12 | template 13 | Padding_LayerQL::~Padding_LayerQL() 14 | { 15 | std::cout << "PooLayerQL End!" << std::endl; 16 | } 17 | 18 | template 19 | void Padding_LayerQL::calForward(int type = 0) const 20 | { 21 | this->calForward_Vector(); 22 | } 23 | 24 | template 25 | void Padding_LayerQL::calForward_Vector() const 26 | { 27 | this->right_Layer->forward_Matrix_Vector.clear(); 28 | std::for_each(this->left_Layer->forward_Matrix_Vector.begin(), this->left_Layer->forward_Matrix_Vector.end(), [&]( std::shared_ptr>& matrixPtr ) 29 | { 30 | std::shared_ptr> paddingMatrix = std::make_shared>( rowNum + 2 * padSize, colNum + 2 * padSize ); 31 | paddingMatrix->setMatrixQL().setZero(); 32 | 33 | paddingMatrix->setMatrixQL().block(padSize, padSize, rowNum, colNum) = matrixPtr->getMatrixQL().block(0, 0, rowNum, colNum); 34 | 35 | this->right_Layer->forward_Matrix_Vector.push_back( paddingMatrix ); 36 | }); 37 | } 38 | 39 | 40 | template 41 | void Padding_LayerQL::calBackward(int type = 0) 42 | { 43 | this->calBackward_Vector(); 44 | } 45 | 46 | 47 | template 48 | void Padding_LayerQL::calBackward_Vector() 49 | { 50 | this->left_Layer->backward_Matrix_Vector.clear(); 51 | 52 | //std::for_each(this->right_Layer->backward_Matrix_Vector.begin(), this->right_Layer->backward_Matrix_Vector.end(), [&](std::shared_ptr>& matrixPtr)) 53 | //{ 54 | 55 | //}); 56 | 57 | } 58 | 59 | 60 | template class Padding_LayerQL; 61 | } -------------------------------------------------------------------------------- /CNN_05_12/Data_Augmentation_Test.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Data_AugmentationQL.h" 3 | #include "NetQL.h" 4 | 5 | namespace tinyDNN 6 | { 7 | class Data_Augmentation_Test 8 | { 9 | public: 10 | Data_Augmentation_Test() 11 | { 12 | this->data_Aug_Forward(); 13 | } 14 | 15 | ~Data_Augmentation_Test(){} 16 | 17 | void data_Aug_Forward() 18 | { 19 | std::shared_ptr> v_01 = std::make_shared>(5, 5); 20 | std::shared_ptr> v_02 = std::make_shared>(5, 5); 21 | std::shared_ptr> v_03 = std::make_shared>(5, 5); 22 | 23 | int coutNum = 0; 24 | for (int i = 0; i < 5; i++) 25 | { 26 | for (int j = 0; j < 5; j++) 27 | { 28 | v_01->setMatrixQL()(i, j) = coutNum; 29 | v_02->setMatrixQL()(i, j) = coutNum; 30 | v_03->setMatrixQL()(i, j) = coutNum; 31 | 32 | coutNum++; 33 | } 34 | } 35 | 36 | std::shared_ptr> in_01 = std::make_shared>(5, 5); 37 | 38 | in_01->forward_Matrix_Vector.push_back(v_01); 39 | in_01->forward_Matrix_Vector.push_back(v_02); 40 | in_01->forward_Matrix_Vector.push_back(v_03); 41 | 42 | std::for_each(in_01->forward_Matrix_Vector.begin(), in_01->forward_Matrix_Vector.end(), [](std::shared_ptr> inMat) { std::cout << inMat->getMatrixQL() << std::endl; 43 | std::cout << "=======================" << std::endl; }); 44 | 45 | std::shared_ptr> dataTest = std::make_shared>(Data_Augmentation_Layer,0,0); 46 | 47 | std::shared_ptr> o_01 = in_01 + dataTest; 48 | 49 | for (int i = 0; i < 10; i++) 50 | { 51 | dataTest->calForward(); 52 | 53 | std::for_each(o_01->forward_Matrix_Vector.begin(), o_01->forward_Matrix_Vector.end(), [&](std::shared_ptr> inMat) { std::cout << inMat->getMatrixQL() << std::endl; 54 | std::cout << i << "=======================" << std::endl; }); 55 | 56 | } 57 | } 58 | }; 59 | } -------------------------------------------------------------------------------- /CNN_05_12/Dim_ReduceQL.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "LayerQL.h" 3 | #include 4 | 5 | namespace tinyDNN 6 | { 7 | template 8 | class Dim_ReduceQL : public LayerQL 9 | { 10 | public: 11 | using MatrixD = Eigen::Matrix; 12 | 13 | Dim_ReduceQL(LayerType type, int kerNum, int rowNum, int colNum) : LayerQL(type), kerNum(kerNum), rowNum(rowNum), colNum(colNum) 14 | { 15 | std::cout << "Dim_ReduceQL Start!" << std::endl; 16 | } 17 | ~Dim_ReduceQL() override final { std::cout << "Dim_ReduceQL Over!" << std::endl; } 18 | 19 | void calForward(int type = 0) const override final 20 | { 21 | std::shared_ptr> rightMatrix = std::make_shared>(1, kerNum*rowNum*colNum); 22 | 23 | int dimNum = 0; 24 | for ( int i = 0 ; i < kerNum; i++ ) 25 | { 26 | for ( int j = 0; j < rowNum; j ++ ) 27 | { 28 | for (int k = 0; k < colNum; k++) 29 | { 30 | rightMatrix->setMatrixQL()(0, dimNum) = this->left_Layer->forward_Matrix_Vector[i]->getMatrixQL()(j,k); 31 | dimNum++; 32 | } 33 | } 34 | } 35 | this->right_Layer->forward_Matrix = rightMatrix; 36 | } 37 | 38 | 39 | void calBackward(int type = 0) override final 40 | { 41 | this->left_Layer->backward_Matrix_Vector.clear(); 42 | 43 | MatrixD trans_01 = static_cast(this->right_Layer->backward_Matrix->getMatrixQL()); 44 | 45 | Eigen::Map mapMatrix( trans_01.data(), rowNum* kerNum , colNum ); 46 | 47 | for ( int i = 0; i < kerNum; i++ ) 48 | { 49 | std::shared_ptr> leftMatrix = std::make_shared>(rowNum,colNum); 50 | leftMatrix->setMatrixQL().block(0, 0, rowNum, colNum) = mapMatrix.block(0 + i * rowNum, 0, rowNum, colNum); 51 | this->left_Layer->backward_Matrix_Vector.push_back(leftMatrix); 52 | } 53 | } 54 | 55 | void upMatrix() override final {}; 56 | void upMatrix_batch(Dtype upRate) override final {}; 57 | 58 | private: 59 | int kerNum; 60 | int rowNum; 61 | int colNum; 62 | }; 63 | } -------------------------------------------------------------------------------- /CNN_05_12/Dim_Reduce_Test.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Dim_ReduceQL.h" 3 | #include "NetQL.h" 4 | namespace tinyDNN 5 | { 6 | class Dim_Reduce_Test 7 | { 8 | public: 9 | Dim_Reduce_Test() 10 | { 11 | this->cal_ForWard_Test(); 12 | this->cal_BackWard_Test(); 13 | } 14 | ~Dim_Reduce_Test(){} 15 | 16 | 17 | void cal_ForWard_Test() 18 | { 19 | std::shared_ptr> in_01 = std::make_shared>(5, 5); 20 | 21 | double matrix_Num = 1.1; 22 | for (int i = 0; i < 3; i++) 23 | { 24 | std::shared_ptr> v_01 = std::make_shared>(5, 5); 25 | for (int j = 0; j < 5; j++) 26 | { 27 | for (int k = 0; k < 5; k++) 28 | { 29 | v_01->setMatrixQL()(j, k) = matrix_Num; 30 | matrix_Num++; 31 | } 32 | } 33 | in_01->forward_Matrix_Vector.push_back(v_01); 34 | } 35 | std::shared_ptr> dim_Test = std::make_shared>(Dim_Reduce_Layer, 3, 5, 5); 36 | 37 | std::shared_ptr> o_01 = in_01 + dim_Test; 38 | 39 | int rec = 3; 40 | while ( rec > 0) 41 | { 42 | dim_Test->calForward(); 43 | std::cout << o_01->forward_Matrix->getMatrixQL() << std::endl; 44 | 45 | std::cout << "*******************************************" << std::endl; 46 | rec--; 47 | } 48 | } 49 | 50 | void cal_BackWard_Test() 51 | { 52 | std::shared_ptr> in_01 = std::make_shared>(5, 5); 53 | std::shared_ptr> dim_Test = std::make_shared>(Dim_Reduce_Layer, 4, 5, 5); 54 | std::shared_ptr> o_01 = in_01 + dim_Test; 55 | 56 | std::shared_ptr> r_Matrix = std::make_shared>(1,100); 57 | 58 | double r_Num = 1.2; 59 | for (int i = 0; i < 100; i++) 60 | { 61 | r_Matrix->setMatrixQL()(0, i) = r_Num; 62 | r_Num++; 63 | } 64 | 65 | o_01->backward_Matrix = r_Matrix; 66 | 67 | int rec = 3; 68 | while (rec > 0) 69 | { 70 | dim_Test->calBackward(); 71 | std::for_each(in_01->backward_Matrix_Vector.begin(), in_01->backward_Matrix_Vector.end(), 72 | [](std::shared_ptr> m_Test) 73 | { 74 | std::cout << m_Test->getMatrixQL() << std::endl; 75 | 76 | std::cout << "********************************************" << std::endl; 77 | } 78 | ); 79 | std::cout << "------------------------------------------------" << std::endl; 80 | rec--; 81 | } 82 | } 83 | }; 84 | } --------------------------------------------------------------------------------