Git Product home page Git Product logo

cml's Introduction

cml

Basic neural network implementation written in C.

build demo

git clone https://github.com/dmaivel/cml
cd cml
make

features

  • CPU only
  • Save/load models (custom implementation)
  • Lightweight

usage

For a complete demo, refer to demo.c.

initialization

struct cml_context ctx = {
    .max_alloc = 1048, /* max amount of bytes program may allocate */ 
    .cur_alloc = 0 /* current allocation (should be 0) */ 
};

creating models

// network becomes root
struct cml_layer *network = NULL;
struct cml_layer *input_layer = cml_new_layer(&ctx, &network, n_inputs, CML_ACT_NONE);
struct cml_layer *hidden_layer = cml_new_layer(&ctx, &network, 12, CML_ACT_PRELU);
...
struct cml_layer *output_layer = cml_new_layer(&ctx, &network, 10, CML_ACT_SIGMOID);

// randomize data inside layer
cml_randomize_layer(hidden_layer, false); // won't randomize bias
cml_randomize_layer(output_layer, true); // will randomize bias

reading & writing inputs/outputs

// single input (network may be substituted w/ `input_layer`)
network->data[...] = ...;

// entire input layer
memcpy(network->data, raw_data, sizeof(float) * network->count);

// single output
float x = output_layer->data[...];

// entire output layer
memcpy(raw_data, output_layer->data, sizeof(float) * output_layer->count);

passes

// forward pass
cml_fwd(network);

// backwards prop (allocates memory, so context needs to be passed)
cml_bwd(&ctx, network, &raw_training_outputs[...], step_size);

loading/saving models

// load model
struct cml_layer *network = NULL;
cml_load_model(&ctx, "model_name.cml", &network);

// save model
cml_save_model("model_name.cml", &network);

free models

cml_free(&ctx, &network);

cml's People

Contributors

dmaivel avatar

Watchers

Kostas Georgiou avatar  avatar

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.