• Stars
    star
    374
  • Rank 110,148 (Top 3 %)
  • Language
    C++
  • Created over 6 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A header-only C++ library for deep neural networks

MiniDNN

MiniDNN is a C++ library that implements a number of popular deep neural network (DNN) models. It has a mini codebase but is fully functional to construct different types of feed-forward neural networks. MiniDNN is built on top of Eigen.

MiniDNN is a header-only library implemented purely in C++98, whose only dependency, Eigen, is also header-only. These features make it easy to embed MiniDNN into larger projects with a broad range of compiler support.

This project was largely inspired by the tiny-dnn library, a header-only C++14 implementation of deep learning models. What makes MiniDNN different is that MiniDNN is based on the high-performance Eigen library for numerical computing, and it has better compiler support.

MiniDNN is still quite experimental for now. Originally I wrote it with the aim of studying deep learning and practicing model implementation, but I also find it useful in my own statistical and machine learning research projects.

Features

  • Able to build feed-forward neural networks with a few lines of code
  • Header-only, highly portable
  • Fast on CPU
  • Modularized and extensible
  • Provides detailed documentation that is a resource for learning
  • Helps understanding how DNN works
  • A wonderful opportunity to learn and practice both the nice and dirty parts of DNN

Quick Start

The self-explanatory code below is a minimal example to fit a DNN model:

#include <MiniDNN.h>

using namespace MiniDNN;

typedef Eigen::MatrixXd Matrix;
typedef Eigen::VectorXd Vector;

int main()
{
    // Set random seed and generate some data
    std::srand(123);
    // Predictors -- each column is an observation
    Matrix x = Matrix::Random(400, 100);
    // Response variables -- each column is an observation
    Matrix y = Matrix::Random(2, 100);

    // Construct a network object
    Network net;

    // Create three layers
    // Layer 1 -- convolutional, input size 20x20x1, 3 output channels, filter size 5x5
    Layer* layer1 = new Convolutional<ReLU>(20, 20, 1, 3, 5, 5);
    // Layer 2 -- max pooling, input size 16x16x3, pooling window size 3x3
    Layer* layer2 = new MaxPooling<ReLU>(16, 16, 3, 3, 3);
    // Layer 3 -- fully connected, input size 5x5x3, output size 2
    Layer* layer3 = new FullyConnected<Identity>(5 * 5 * 3, 2);

    // Add layers to the network object
    net.add_layer(layer1);
    net.add_layer(layer2);
    net.add_layer(layer3);

    // Set output layer
    net.set_output(new RegressionMSE());

    // Create optimizer object
    RMSProp opt;
    opt.m_lrate = 0.001;

    // (Optional) set callback function object
    VerboseCallback callback;
    net.set_callback(callback);

    // Initialize parameters with N(0, 0.01^2) using random seed 123
    net.init(0, 0.01, 123);

    // Fit the model with a batch size of 100, running 10 epochs with random seed 123
    net.fit(opt, x, y, 100, 10, 123);

    // Obtain prediction -- each column is an observation
    Matrix pred = net.predict(x);

    // Layer objects will be freed by the network object,
    // so do not manually delete them

    return 0;
}

To compile and run this example, simply download the source code of MiniDNN and Eigen, and let the compiler know about their paths. For example:

g++ -O2 -I/path/to/eigen -I/path/to/MiniDNN/include example.cpp

Documentation

The API reference page contains the documentation of MiniDNN generated by Doxygen, including all the class APIs.

License

MiniDNN is an open source project licensed under MPL2.

More Repositories

1

spectra

A header-only C++ library for large scale eigenvalue problems
C++
704
star
2

LBFGSpp

A header-only C++ library for L-BFGS and L-BFGS-B algorithms
C++
493
star
3

showtext

Using Fonts More Easily in R Graphs
C
466
star
4

prettydoc

Creating Pretty HTML From R Markdown
SCSS
459
star
5

recosystem

Recommender System Using Parallel Matrix Factorization
C++
85
star
6

RSpectra

R Interface to the Spectra Library for Large Scale Eigenvalue and SVD Problems
C++
77
star
7

ADMM

Solving Statistical Optimization Problems Using the ADMM Algorithm
C++
74
star
8

RcppNumerical

Rcpp Integration for Numerical Computing Libraries
C++
55
star
9

rARPACK

Solvers for Large Scale Eigenvalue and SVD Problems
R
45
star
10

tinydnn

Tiny yet Powerful Deep Neural Networks
C++
42
star
11

conan-danmu

ć€Šåä¾¦ęŽ¢ęŸÆå—ć€‹Bē«™å¼¹å¹•ęµč§ˆå™Ø
R
38
star
12

ADMM-Spark

Implementation of ADMM algorithm on Apache Spark
Scala
24
star
13

fontr

Extracting Glyphs From Font Files
C++
23
star
14

sysfonts

Loading Fonts into R
R
22
star
15

arpack-eigen

A header-only C++ redesign of ARPACK using the Eigen library
C++
21
star
16

fastncdf

Fast Computation of Normal CDF
C
18
star
17

almond

ALMOND: Adaptive Latent Modeling and Optimization via Neural Networks and Langevin Diffusion
Python
12
star
18

COS-article

ē»Ÿč®”之都äø»ē«™ (http://cos.name/) ꖇē« ē›ø关代ē 
HTML
10
star
19

parallel-translation

Chinese translation of the vignette of "parallel" package
10
star
20

hugo-blog-en

My English blog built with Hugo
HTML
10
star
21

arpack-arma

A header-only C++ redesign of ARPACK using the Armadillo library
C++
9
star
22

temperflow

Efficient Multimodal Sampling via Tempered Distribution Flow
Python
9
star
23

rcpp-note

Rcpp API reference
HTML
8
star
24

cdtau

Unbiased Contrastive Divergence Algorithm
C++
8
star
25

Rmath-Java

Java wrapper of Rmath library for statistical distribution functions
C
7
star
26

miniGPU

A Minimal Example of Using OpenCL in R Packages
C
5
star
27

markerpen

Marker Gene Detection via Penalized Principal Component Analysis
C++
5
star
28

fontemoji

Plotting Emojis in R Graphs
R
5
star
29

Science

Master of Science
4
star
30

clplite

High Performance Linear Programming Solver Based on Clp
C++
3
star
31

Layer

An R Graphics Device with Layer Support
Shell
3
star
32

R2SWF

Convert R Graphics to SWF (Flash)
C
3
star
33

cutest-lbfgs

Testing and benchmarking L-BFGS/L-BFGS-B solvers with CUTEst
C++
3
star
34

R2SWF-archive

Convert R Graphics to SWF (Flash)
C
3
star
35

cleveland-r-meetup

Slides and code for the presentation given at the Greater Cleveland R Group
R
2
star
36

fdaplus

Enhancement of the 'fda' package for functional data analysis
C
2
star
37

en

My (old) English blog. New one at https://github.com/yixuan/hugo-blog-en
HTML
2
star
38

gradfps

Gradient-based Fantope projection and selection algorithm for sparse PCA
C
2
star
39

bigspline

Smoothing Spline on Spark
Scala
1
star
40

test

R
1
star
41

cn

My Chinese Blog
CSS
1
star
42

Algorithms

A place to hold code snippets of algorithms
C++
1
star
43

yixuan.github.com

My homepage
HTML
1
star
44

rationalfun

An R package to manipulate rational functions
R
1
star