Coder Social home page Coder Social logo

rugleb / neural-network Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 153 KB

High-level neural networks API for C++

Home Page: https://github.com/rugleb/neural-network

License: MIT License

CMake 8.85% Shell 0.44% C++ 90.71%
neural-network neural cpp

neural-network's Introduction

Build Status Language License: MIT

Preview

This repository is created for educational purposes only and is not ready for use in production.

The developed interface for working with neural networks is largely inspired by the Keras framework.

Getting started

The central data structure of this library is the model. It defines the structure of the layers and the relationship between them.

At the moment, only a Sequential network model is implemented.

Now create an instance of the new network model:

#include "src/network.h"

Model model;

Then add two hidden layers with different activation functions and neurons number:

model.add(Layer(20, relu));         // 20 neurons and ReLU activation
model.add(Layer(10, sigmoid));      // 10 neurons and Sigmoid activation

Note that the model automatically selects the number of neurons on the input layer of the network.

Now the structure of the neural network is ready.

The next step is to train the neural network. But before you train a model, you must set the training parameters.
This is done quite simply:

TrainParams params;
params.dataset = dataset;           // train dataset
params.epochs = 5;                  // number of training epochs
params.error = 1e-10;               // acceptable learning error
params.teach = 0.05;                // learning rate

Under dataset should be understood as a set (vector) of data in the format: vector of input values of the network and a vector of output values of the network. More detailed: Dataset structure.

Now that we are ready to train the network, we can start the learning process:

model.fit(params);

During the training program will inform you:

Training started
---- Epoch: 1, average error: 5.74e-04
---- Epoch: 2, average error: 1.62e-05
---- Epoch: 3, average error: 8.75e-07
---- Epoch: 4, average error: 6.41e-08
---- Epoch: 5, average error: 2.32e-09
Training finished

After training the model, we can test the quality on the test data:

Dataset testing = makeTesting(3);    // creates 3 test datasets
model.testing(testingSet);           // starts testing

The output of the program:

Testing started
---- Testing set: 1, error: 1.12e-02
---- Testing set: 2, error: 1.65e-03
---- Testing set: 3, error: 4.36e-04
Testing finished. Average error: 4.43e-03

Now the model is trained and tested. Then it can be saved and used for other tasks.

Full example

You can see a complete example of a program that uses a neural network (autoencoder) to compress a PNG image into a vector and then restores the image from the compressed vector to the original image: main.cpp file.

Build from sources:

./compile.sh

Run application:

./build/nn example.png output.png

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.