
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
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
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.
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.
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.
// 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
// ...
});
// 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.
MIT. See the LICENSE file for more details.
FAQs
Call CNTK directly from node.js
The npm package node-cntk receives a total of 28 weekly downloads. As such, node-cntk popularity was classified as not popular.
We found that node-cntk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.