資源簡介
深度學習之卷積神經網絡CNN做手寫體識別的VS代碼。支持linux版本和VS2012版本。
tiny-cnn: A C++11 implementation of convolutional neural networks
========
tiny-cnn is a C++11 implementation of convolutional neural networks.
design principle
-----
* fast, without GPU
98.8% accuracy on MNIST in 13 minutes training (@Core i7-3520M)
* header only, policy-based design
supported networks
-----
### layer-types
* fully-connected layer
* convolutional layer
* average pooling layer
### activation functions
* tanh
* sigmoid
* rectified linear
* identity
### loss functions
* cross-entropy
* mean-squared-error
### optimization algorithm
* stochastic gradient descent (with/without L2 normalization)
* stochastic gradient levenberg marquardt
dependencies
-----
* boost C++ library
* Intel TBB
sample code
------
```cpp
#include "tiny_cnn.h"
using namespace tiny_cnn;
// specify loss-function and optimization-algorithm
typedef network CNN;
// tanh, 32x32 input, 5x5 window, 1-6 feature-maps convolution
convolutional_layer C1(32, 32, 5, 1, 6);
// tanh, 28x28 input, 6 feature-maps, 2x2 subsampling
average_pooling_layer S2(28, 28, 6, 2);
// fully-connected layers
fully_connected_layer F3(14*14*6, 120);
fully_connected_layer F4(120, 10);
// connect all
CNN mynet;
mynet.add(&C1); mynet.add(&S2); mynet.add(&F3); mynet.add(&F4);
assert(mynet.in_dim() == 32*32);
assert(mynet.out_dim() == 10);
```
more sample, read main.cpp
build sample program
------
### gcc(4.6~)
without tbb
./waf configure --BOOST_ROOT=your-boost-root
./waf build
with tbb
./waf configure --TBB --TBB_ROOT=your-tbb-root --BOOST_ROOT=your-boost-root
./waf build
with tbb and SSE/AVX
./waf configure --AVX --TBB --TBB_ROOT=your-tbb-root --BOOST_ROOT=your-boost-root
./waf build
./waf configure --SSE --TBB --TBB_ROOT=your-tbb-root --BOOST_ROOT=your-boost-root
./waf build
or edit inlude/co

代碼片段和文件信息
/*
????Copyright?(c)?2013?Taiga?Nomi
????All?rights?reserved.
????
????Redistribution?and?use?in?source?and?binary?forms?with?or?without
????modification?are?permitted?provided?that?the?following?conditions?are?met:
????*?Redistributions?of?source?code?must?retain?the?above?copyright
????notice?this?list?of?conditions?and?the?following?disclaimer.
????*?Redistributions?in?binary?form?must?reproduce?the?above?copyright
????notice?this?list?of?conditions?and?the?following?disclaimer?in?the
????documentation?and/or?other?materials?provided?with?the?distribution.
????*?Neither?the?name?of?the??nor?the
????names?of?its?contributors?may?be?used?to?endorse?or?promote?products
????derived?from?this?software?without?specific?prior?written?permission.
????THIS?SOFTWARE?IS?PROVIDED?BY?THE?COPYRIGHT?HOLDERS?AND?CONTRIBUTORS?“AS?IS“?AND?ANY?
????EXPRESS?OR?IMPLIED?WARRANTIES?INCLUDING?BUT?NOT?LIMITED?TO?THE?IMPLIED?
????WARRANTIES?OF?MERCHANTABILITY?AND?FITNESS?FOR?A?PARTICULAR?PURPOSE?ARE?
????DISCLAIMED.?IN?NO?EVENT?SHALL?THE?COPYRIGHT?HOLDER?OR?CONTRIBUTORS?BE?LIABLE?FOR?ANY?
????DIRECT?INDIRECT?INCIDENTAL?SPECIAL?EXEMPLARY?OR?CONSEQUENTIAL?DAMAGES?
????(INCLUDING?BUT?NOT?LIMITED?TO?PROCUREMENT?OF?SUBSTITUTE?GOODS?OR?SERVICES;?
????LOSS?OF?USE?DATA?OR?PROFITS;?OR?BUSINESS?INTERRUPTION)?HOWEVER?CAUSED?AND?
????ON?ANY?THEORY?OF?LIABILITY?WHETHER?IN?CONTRACT?STRICT?LIABILITY?OR?TORT?
????(INCLUDING?NEGLIGENCE?OR?OTHERWISE)?ARISING?IN?ANY?WAY?OUT?OF?THE?USE?OF?THIS?
????SOFTWARE?EVEN?IF?ADVISED?OF?THE?POSSIBILITY?OF?SUCH?DAMAGE.
*/
#include?
#include?
#include?
#include?“tiny_cnn.h“
//#define?NOMINMAX
//#include?“imdebug.h“
void?sample1_3layerNN();
using?namespace?tiny_cnn;
int?main(void)?{
????//?construct?LeNet-5?architecture
????typedef?network?CNN;
????CNN?nn;
????convolutional_layer?C1(32?32?5?1?6);
????average_pooling_layer?S2(28?28?6?2);
????//?connection?table?[Y.Lecun?1998?Table.1]
#define?O?true
#define?X?false
????static?const?bool?connection[]?=?{
????????O?X?X?X?O?O?O?X?X?O?O?O?O?X?O?O
????????O?O?X?X?X?O?O?O?X?X?O?O?O?O?X?O
????????O?O?O?X?X?X?O?O?O?X?X?O?X?O?O?O
????????X?O?O?O?X?X?O?O?O?O?X?X?O?X?O?O
????????X?X?O?O?O?X?X?O?O?O?O?X?O?O?X?O
????????X?X?X?O?O?O?X?X?O?O?O?O?X?O?O?O
????};
#undef?O
#undef?X
????convolutional_layer?C3(14?14?5?6?16?connection_table(connection?6?16));
????average_pooling_layer?S4(10?10?16?2);
????convolutional_layer?C5(5?5?5?16?120);
????fully_connected_layer?F6(120?10);
????assert(C1.param_size()?==?156?&&?C1.connection_size()?==?122304);
????assert(S2.param_size()?==?12?&&?S2.connection_size()?==?5880);
????assert(C3.param_size()?==?1516?&&?C
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????.......???????483??2014-02-11?06:00??cnn_vs2012\.gitattributes
????.......??????2107??2014-02-11?06:00??cnn_vs2012\.gitignore
????.......??????2053??2014-02-11?06:00??cnn_vs2012\README.md
????.......??????3628??2014-02-11?06:00??cnn_vs2012\include\activation_function.h
????.......??????3501??2014-02-11?06:00??cnn_vs2012\include\average_pooling_la
????.......??????1920??2014-02-11?06:00??cnn_vs2012\include\config.h
????.......??????6262??2014-02-11?06:00??cnn_vs2012\include\convolutional_la
????.......??????1966??2014-02-11?06:00??cnn_vs2012\include\deform.h
????.......??????5793??2014-02-11?06:00??cnn_vs2012\include\fixed_point.h
????.......??????5041??2014-02-11?06:00??cnn_vs2012\include\fully_connected_la
????.......??????4636??2014-02-11?06:00??cnn_vs2012\include\image.h
????.......?????10225??2014-02-11?06:00??cnn_vs2012\include\la
????.......??????2097??2014-02-11?06:00??cnn_vs2012\include\loss_function.h
????.......??????4612??2014-02-11?06:00??cnn_vs2012\include\mnist_parser.h
????.......?????13429??2014-02-11?06:00??cnn_vs2012\include\network.h
????.......??????2731??2014-02-11?06:00??cnn_vs2012\include\optimizer.h
????.......??????8703??2014-02-11?06:00??cnn_vs2012\include\partial_connected_la
????.......?????23363??2014-02-11?06:00??cnn_vs2012\include\picotest.h
????.......?????12527??2014-02-11?06:00??cnn_vs2012\include\product.h
????.......??????1910??2014-02-11?06:00??cnn_vs2012\include\tiny_cnn.h
????.......??????5446??2014-02-11?06:00??cnn_vs2012\include\util.h
????.......??????6757??2014-02-11?06:00??cnn_vs2012\src\main.cpp
????.......?????15168??2014-02-11?06:00??cnn_vs2012\src\test.cpp
????.......???????352??2014-02-11?06:00??cnn_vs2012\src\wsc
????.......??????2039??2014-02-11?06:00??cnn_vs2012\vc\cnn.vcxproj.filters
????.......???7840016??2014-02-11?06:00??cnn_vs2012\vc\t10k-images.idx3-ubyte
????.......?????10008??2014-02-11?06:00??cnn_vs2012\vc\t10k-labels.idx1-ubyte
????.......??????1936??2014-02-11?06:00??cnn_vs2012\vc\test.vcxproj.filters
????.......??????1320??2014-02-11?06:00??cnn_vs2012\vc\tiny_cnn.sln
????.......??????5856??2014-02-11?06:00??cnn_vs2012\vc\tiny_cnn.vcxproj
............此處省略12個文件信息
評論
共有 條評論