A simple Convolutional neural network code

27,274

Solution 1

I can recommend tiny-cnn. It is simple, lightweight (e.g. header-only) and CPU only, while providing several layers frequently used within the literature (as for example pooling layers, dropout layers or local response normalization layer). This means, that you can easily explore an efficient implementation of these layers in C++ without requiring knowledge of CUDA and digging through the I/O and framework code as required by framework such as Caffe. The implementation lacks some comments, but the code is still easy to read and understand.

The provided MNIST example is quite easy to use (tried it myself some time ago) and trains efficiently. After training and testing, the weights are written to file. Then you have a simple pre-trained model from which you can start, see the provided examples/mnist/test.cpp and examples/mnist/train.cpp. It can easily be loaded for testing (or recognizing digits) such that you can debug the code while executing a learned model.

If you want to inspect a more complicated network, have a look at the Cifar-10 Example.

Solution 2

This is the simplest implementation I have seen: DNN McCaffrey

Also, the source code for this by Karpathy looks pretty straightforward.

Share:
27,274
bromanous
Author by

bromanous

Updated on April 17, 2020

Comments

  • bromanous
    bromanous about 4 years

    I am interested in convolutional neural networks (CNNs) as a example of computationally extensive application that is suitable for acceleration using reconfigurable hardware (i.e. lets say FPGA)

    In order to do that I need to examine a simple CNN code that I can use to understand how they are implemented, how are the computations in each layer taking place, how the output of each layer is being fed to the input of the next one. I am familiar with the theoretical part (http://cs231n.github.io/convolutional-networks/)

    But, I am not interested in training the CNN, I want a complete, self contained CNN code that is pre-trained and all the weights and biases values are known.

    I know that there are plenty of CNN libraries, i.e. Caffe, but the problem is that there is no trivial example code that is self contained. even for the simplest Caffe example "cpp_classification" many libraries are invoked, the architecture of the CNN is expressed as .prototxt file, other types of inputs such as .caffemodel and .binaryproto are involved. openCV2 libraries is invoked too. there are layers and layers of abstraction and different libraries working together to produce the classification outcome.

    I know that those abstractions are needed to generate a "useable" CNN implementation, but for a hardware person who needs a bare-bone code to study, this is too much of "un-related work".

    My question is: Can anyone guide me into a simple and self-contained CNN implementation that I can start with?

  • bromanous
    bromanous about 8 years
    Thank you! your links are very useful as well both for coding and learning concepts.
  • bromanous
    bromanous about 8 years
    Thank you! tiny-cnn is indeed way more readable for a beginner rather than Caffe and is a good starting point.