Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
@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.
This package implements a GPU accelerated WebGL backend for TensorFlow.js.
Note: this backend is included by default in @tensorflow/tfjs
.
// Import @tensorflow/tfjs-core
import * as tf from '@tensorflow/tfjs-core';
// Adds the WebGL backend to the global backend registry.
import '@tensorflow/tfjs-backend-webgl';
<!-- Import @tensorflow/tfjs-core -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script>
<!-- Adds the WebGL backend to the global backend registry -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl"></script>
You can also get ES2017 code using the following links
<!-- Import @tensorflow/tfjs-core -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core@2.0.0-rc.4/dist/tf-core.es2017.js"></script>
<!-- Adds the WebGL backend to the global backend registry -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl@2.0.0-rc.4/dist/tf-backend-webgl.es2017.js"></script>
FAQs
GPU accelerated WebGL backend for TensorFlow.js
The npm package @tensorflow/tfjs-backend-webgl receives a total of 134,006 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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.