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?
- 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.
- Require the module and set the default device:
const cntk = ; try // try to set the default device to GPU with device Id 0 cntk;catchex // failed to set device to GPU, try to set to CPU instead cntk;
Note that for now you can set the device globally, in the future this module will support choosing the device per operation.
- Load the model using the loadModel async method:
// Load the model var modelPath = path; cntk;
- Evaluate a sample (or samples) using the loaded model:
// get the data samplevar 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
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.