All Projects → gosha20777 → Keras2cpp

gosha20777 / Keras2cpp

Licence: mit
it's a small library for running trained Keras 2 models from a native C++ code.

Programming Languages

python
139335 projects - #7 most used programming language
cpp
1120 projects

Projects that are alternatives of or similar to Keras2cpp

Xaynet
Xaynet represents an agnostic Federated Machine Learning framework to build privacy-preserving AI applications.
Stars: ✭ 111 (-10.48%)
Mutual labels:  neural-networks
Growing Neural Cellular Automata
A reproduction of growing neural cellular automata using PyTorch.
Stars: ✭ 116 (-6.45%)
Mutual labels:  neural-networks
Nlp Pretrained Model
A collection of Natural language processing pre-trained models.
Stars: ✭ 122 (-1.61%)
Mutual labels:  neural-networks
A Nice Mc
Code for "A-NICE-MC: Adversarial Training for MCMC"
Stars: ✭ 115 (-7.26%)
Mutual labels:  neural-networks
Learn Machine Learning
Learn to Build a Machine Learning Application from Top Articles
Stars: ✭ 116 (-6.45%)
Mutual labels:  neural-networks
Nnpack
Acceleration package for neural networks on multi-core CPUs
Stars: ✭ 1,538 (+1140.32%)
Mutual labels:  neural-networks
Elephas
Distributed Deep learning with Keras & Spark
Stars: ✭ 1,521 (+1126.61%)
Mutual labels:  neural-networks
Autoencoders
Implementation of simple autoencoders networks with Keras
Stars: ✭ 123 (-0.81%)
Mutual labels:  neural-networks
Openann
An open source library for artificial neural networks.
Stars: ✭ 117 (-5.65%)
Mutual labels:  neural-networks
Neuroner
Named-entity recognition using neural networks. Easy-to-use and state-of-the-art results.
Stars: ✭ 1,579 (+1173.39%)
Mutual labels:  neural-networks
Josef
A robot who learns how to draw
Stars: ✭ 115 (-7.26%)
Mutual labels:  neural-networks
Lightwood
Lightwood is Legos for Machine Learning.
Stars: ✭ 115 (-7.26%)
Mutual labels:  neural-networks
Amla
AutoML frAmework for Neural Networks
Stars: ✭ 119 (-4.03%)
Mutual labels:  neural-networks
Pygat
Pytorch implementation of the Graph Attention Network model by Veličković et. al (2017, https://arxiv.org/abs/1710.10903)
Stars: ✭ 1,853 (+1394.35%)
Mutual labels:  neural-networks
Aizynthfinder
A tool for retrosynthetic planning
Stars: ✭ 122 (-1.61%)
Mutual labels:  neural-networks
Safe
SAFE: Self-Attentive Function Embeddings for binary similarity
Stars: ✭ 112 (-9.68%)
Mutual labels:  neural-networks
Deephyper
DeepHyper: Scalable Asynchronous Neural Architecture and Hyperparameter Search for Deep Neural Networks
Stars: ✭ 117 (-5.65%)
Mutual labels:  neural-networks
Hyperdensenet
This repository contains the code of HyperDenseNet, a hyper-densely connected CNN to segment medical images in multi-modal image scenarios.
Stars: ✭ 124 (+0%)
Mutual labels:  neural-networks
Clicr
Machine reading comprehension on clinical case reports
Stars: ✭ 123 (-0.81%)
Mutual labels:  neural-networks
Nn
A tiny neural network 🧠
Stars: ✭ 119 (-4.03%)
Mutual labels:  neural-networks

Keras2cpp release lisense Build Status

keras2cpp

Keras2cpp is a small library for running trained Keras models from a C++ application without any dependences.

Design goals:

  • Compatibility with networks generated by Keras using TensorFlow backend.
  • CPU only, no GPU.
  • No external dependencies, standard library, C++17.
  • Model stored on disk in binary format and can be quickly read.
  • Model stored in memory in contiguous block for better cache performance.

Not not layer and activation types are supported yet. Work in progress

Supported Keras layers:

  • [x] Dense
  • [x] Convolution1D
  • [x] Convolution2D
  • [ ] Convolution3D
  • [x] Flatten
  • [x] ELU
  • [x] Activation
  • [x] MaxPooling2D
  • [x] Embedding
  • [x] LocallyConnected1D
  • [x] LocallyConnected2D
  • [x] LSTM
  • [ ] GRU
  • [ ] CNN
  • [X] BatchNormalization

Supported activation:

  • [x] linear
  • [x] relu
  • [x] softplus
  • [x] tanh
  • [x] sigmoid
  • [x] hard_sigmoid
  • [x] elu
  • [x] softsign
  • [x] softmax

Other tasks:

  • [x] Create unit tests
  • [x] Create Makefile
  • [x] Code refactoring (in progress)

The project is compatible with Keras 2.x (all versions) and Python 3.x

Example

python_model.py:

import numpy as np
from keras import Sequential
from keras.layers import Dense

#create random data
test_x = np.random.rand(10, 10).astype('f')
test_y = np.random.rand(10).astype('f')
model = Sequential([
    Dense(1, input_dim=10)
])
model.compile(loss='mse', optimizer='adam')

#train model by 1 iteration
model.fit(test_x, test_y, epochs=1, verbose=False)

#predict
data = np.array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])
prediction = model.predict(data)
print(prediction)

#save model
from keras2cpp import export_model
export_model(model, 'example.model')

cpp_model.cc:

#include "src/model.h"

using keras2cpp::Model;
using keras2cpp::Tensor;

int main() {
    // Initialize model.
    auto model = Model::load("example.model");

    // Create a 1D Tensor on length 10 for input data.
    Tensor in{10};
    in.data_ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    // Run prediction.
    Tensor out = model(in);
    out.print();
    return 0;
}

How to build and run

Tested with Keras 2.2.1, Python 3.6

$ git clone https://github.com/gosha20777/keras2cpp.git
$ cd keras2cpp
$ mkdir build && cd build
$ python3 ../python_model.py
[[-1.85735667]]

$ cmake ..
$ cmake --build .
$ ./keras2cpp
[ -1.857357 ]

License

MIT

Similar projects

I found another similar projects on Github:

But It works only with Keras 1 and didn’t work for me. That's why I wrote my own implementation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].