Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@tensorflow/tfjs-backend-webgl
Advanced tools
@tensorflow/tfjs-backend-webgl is a WebGL-accelerated backend for TensorFlow.js, enabling high-performance machine learning computations in the browser. It leverages the power of the GPU to perform operations faster than the CPU backend.
Tensor Operations
This feature allows you to perform tensor operations such as addition, multiplication, etc., using the WebGL backend for accelerated performance.
const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-backend-webgl');
async function run() {
await tf.setBackend('webgl');
const a = tf.tensor([1, 2, 3, 4]);
const b = tf.tensor([5, 6, 7, 8]);
const c = a.add(b);
c.print(); // Output: [6, 8, 10, 12]
}
run();
Model Training
This feature allows you to train machine learning models directly in the browser using the WebGL backend for faster computations.
const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-backend-webgl');
async function run() {
await tf.setBackend('webgl');
const model = tf.sequential();
model.add(tf.layers.dense({units: 100, activation: 'relu', inputShape: [10]}));
model.add(tf.layers.dense({units: 1}));
model.compile({optimizer: 'sgd', loss: 'meanSquaredError'});
const xs = tf.randomNormal([100, 10]);
const ys = tf.randomNormal([100, 1]);
await model.fit(xs, ys, {epochs: 10});
console.log('Model training complete');
}
run();
Model Inference
This feature allows you to perform model inference, i.e., making predictions using a pre-trained model, with the WebGL backend for improved performance.
const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-backend-webgl');
async function run() {
await tf.setBackend('webgl');
const model = await tf.loadLayersModel('https://example.com/model.json');
const input = tf.tensor([1, 2, 3, 4], [1, 4]);
const output = model.predict(input);
output.print();
}
run();
@tensorflow/tfjs-backend-cpu is a CPU-based backend for TensorFlow.js. It is generally slower than the WebGL backend but can be used in environments where WebGL is not available or desired.
@tensorflow/tfjs-node is a Node.js backend for TensorFlow.js, providing high-performance machine learning computations on the server-side. It leverages the TensorFlow C library for accelerated performance.
gpu.js is a JavaScript library for GPU-accelerated computations. While it is not specifically designed for machine learning, it can be used to perform general-purpose computations on the GPU, similar to the WebGL backend of TensorFlow.js.
FAQs
GPU accelerated WebGL backend for TensorFlow.js
The npm package @tensorflow/tfjs-backend-webgl receives a total of 144,603 weekly downloads. As such, @tensorflow/tfjs-backend-webgl popularity was classified as popular.
We found that @tensorflow/tfjs-backend-webgl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.