Socket
Socket
Sign inDemoInstall

@tensorflow/tfjs-backend-webgl

Package Overview
Dependencies
Maintainers
10
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tensorflow/tfjs-backend-webgl

GPU accelerated WebGL backend for TensorFlow.js


Version published
Weekly downloads
161K
increased by4.37%
Maintainers
10
Weekly downloads
 
Created

What is @tensorflow/tfjs-backend-webgl?

@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.

What are @tensorflow/tfjs-backend-webgl's main functionalities?

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();

Other packages similar to @tensorflow/tfjs-backend-webgl

FAQs

Package last updated on 30 Apr 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc