Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Caffe bindings for node.
To build the npm module first build Caffe and set "CAFFE_ROOT" to the distribute directory inside Caffe (the source directory is not sufficient, we need the compiled proto file "caffe.pb.h"). Make sure you use "make distribute" when building Caffe.
export CAFFE_ROOT=~/workspace/caffe/distribute
Here is an example how to instantiate a network:
var net = new caffe.Net('lenet.prototxt', 'test'); // or 'train'
var data = new Blob([1,1,24,24]);
var label = new Blob([1,1]);
data.data[17] = 42; // mnist data
label.data[0] = 1; // label
net.layers[0].enqueue([data, label]); // will be drained by forward()
net.forward(loss => console.log(loss, net.layers[net.layers.length-1].data));
If Caffee is built with CPU_ONLY (no CUDA support), the node module must be built with CPU_ONLY to prevent a mismatch between Caffe header files and the Caffe library. We try to detect whether CPU_ONLY should be set by checking for the presence of an installed CUDA SDK. This means that if you have CUDA installed, please always compile Caffe WITH CUDA support, or bad things will happen. If you do decide to use Caffe without CUDA, make sure to remove the CUDA SDK or change bindings.gyp.
Blob is the basic data abstraction in Caffe. To construct a Blob object, pass the shape as an array of dimensions to the constructor.
var blob = new caffe.Blob([1,2,3,4])
console.log(blob.shape, blob.data, blob.diff);
Use 'data' and 'diff' to access to underlying data, which is returned as a typed array (Float32Array or Float64Array). Each access to the 'data' and 'diff' getters forces the data to be mapped into CPU memory. Keeping a copy of the typed array can be dangerous since Caffe may drop the mapping, so its best to only access the memory until the next Caffe method is called.
Layers should not be constructed directly. Net constructs them when loading a network description.
The bindings add a custom layer type (BufferedDataLayer) to Caffe which can be used to feed data into networks that is supplied by a JavaScript callback.
'enqueue' and "queueLength" throw if called on any other layer type. Blob arrays added with enqueue() will be drained by each call to net.forward(). Trying to mutate blobs that were passed to enqueue() is a bad idea.
Supply a network description and the phase ('test' or 'train') to the Net constructor to instantiate a network.
var net = new caffe.Net('lenet.prototxt', 'test'); // or 'train'
net.layers.forEach((layer, n) => console.log(net.layer_names[n], layer));
net.blobs.forEach((blob, n) => console.log(net.blob_names[n], blob));
Layers and Blobs can be accessed with 'layers' and 'blobs', both of which are arrays. The name of each Layer and Blob is stored in 'layer_names' and 'blob_names'.
To copy data from a model file, use 'copyTrainedLayersFrom'.
Solver instantiates train and test networks. To access them use 'net' and 'test_nets'. The latter is an array since multiple test nets are supported by Caffe.
Use 'solve' to run the solver.
var solver = new Solver('./tests/lenet_solver.prototxt');
solver.solve(() => console.log('done!'));
The bindings support Float and Double variants of each data type, called "BlobFloat" and "BlobDouble". An alias is set for each type ("Blob"), that defaults to the "Float" variant.
To use multiple GPUs, enable GPU support and make sure to create a solver for each GPU:
caffe.mode = "GPU";
console.log(caffe.deviceQuery);
caffe.solverCount = caffe.gpus.length;
Once this has been done, solve(), step() and stepSync() automatically support training across all available GPUs and weights are synchronized after every iteration.
solver.stepSync();
FAQs
Caffe bindings for node
The npm package node-caffe receives a total of 5 weekly downloads. As such, node-caffe popularity was classified as not popular.
We found that node-caffe demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.