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 = require('node-cntk');
try {
cntk.setDefaultDeviceSync(cntk.devices.gpu );
}
catch(ex) {
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.
- Load the model using the loadModel async method:
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!')
});
- Evaluate a sample (or samples) using the loaded model:
var dataSample = [...];
inputData = [dataSample]
model.eval(inputData, (err, res)=>{
if (err) {
console.info(err);
return;
}
console.info('Eval result:', res);
})
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.