npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-cntk

v0.0.2

Published

Call CNTK directly from node.js

Downloads

83

Readme

node-cntk : Node.js bindings for CNTK

This node.js module provides node.js native bindings for CNTK, Microsoft's deep learning library.

Currently supports Windows x64. Please note that the module is currently bundled with the required CNTK and CUDA DLL files. (Hence the large package size). The additional DLL files are located under the CNTK/DLL folder.

A working example of a web app hosting a CNTK model for handwritten digit recognition is available here: https://github.com/nadavbar/node-cntk-mnist-sample

What is it good for?

node-cntk is currently meant to only support model evaluation. (e.g. test time).

That is, you need to first train you model using CNTK's python (or Brain-Script) API, and then consume it in node.js using this module.

How to use?

  1. Install by running:
npm install --save node-cntk

Please note that currently the npm package also contains the CNTK windows binaries, which means that the download might take some time.

  1. Require the module and set the default device:
const cntk = require('node-cntk');

try {
    // try to set the default device to GPU with device Id 0
    cntk.setDefaultDeviceSync(cntk.devices.gpu /*, deviceId (default is 0) */);
}
catch(ex) {
    // failed to set device to GPU, try to set to CPU instead
    cntk.setDefaultDeviceSync(cntk.devices.cpu);
}

Note that for now you can set the device globally, in the future this module will support choosing the device per operation.

  1. Load the model using the loadModel async method:
// Load the model 
var modelPath = path.join(__dirname, 'mnist', 'mnist_conv.cmf');

cntk.loadModel(modelPath, (err, model) => {
    if (err) {
        console.info('Got error:', err);
        return;
    }
    console.info('Got model!')

    // do something with the model
    // ...
});
  1. Evaluate a sample (or samples) using the loaded model:
// get the data sample
var dataSample = [...];

// the input data is a batch of data, e.g. array of arrays/buffers, etc:
inputData = [dataSample]

// Alternatively, you can also provide a dictionary where each key is the name of the input variable, and the value is the data. // This is useful in case your model have more than input variables. 
//inputData = {
//    'input' : [ dataSample ]
//}

// In case you are interested in a specific output variable, you can explicitly provide a list if output variable names
// that the eval function will get the evaluation for.
// If you don't provide any, the eval function will just return the default model output variables.

//outputVariables = ['output']
    
model.eval(inputData, /* outputVariables, */ (err, res)=>{
    if (err) {
        console.info(err);
        return;
    }

    // Print the result object.
    // The result object will hold an object with the name of the output variable as key, and for each key 
    // the value will be an array with the evaluation result for each data samples 
    
    console.info('Eval result:', res);

    // For the MNIST example, we will have the following output 
    // (note that "output" is the name of the model's output variable):
    // 
    // Eval result: { output:
    // [ [ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ],
    // [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ] ] }
    //
})

For a full, working sample of evaluating images of hand written digits using a Convolutional Neural Network model trained on the MNIST dataset, please see this sample.

License

MIT. See the LICENSE file for more details.