New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tensorflow/tfjs-layers

Package Overview
Dependencies
Maintainers
13
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tensorflow/tfjs-layers

TensorFlow layers API in JavaScript

  • 2.8.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
145K
increased by5.06%
Maintainers
13
Weekly downloads
 
Created

What is @tensorflow/tfjs-layers?

@tensorflow/tfjs-layers is a high-level API for building and training machine learning models in JavaScript. It is part of the TensorFlow.js ecosystem and provides a way to create neural networks using layers, which are the building blocks of deep learning models. This package allows you to define, train, and evaluate models directly in the browser or in Node.js.

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

Creating a Sequential Model

This feature allows you to create a sequential model, which is a linear stack of layers. The code sample demonstrates how to add dense layers to the model.

const tf = require('@tensorflow/tfjs-layers');
const model = tf.sequential();
model.add(tf.layers.dense({units: 32, inputShape: [50]}));
model.add(tf.layers.dense({units: 10, activation: 'softmax'}));

Compiling a Model

This feature allows you to compile the model, specifying the optimizer, loss function, and metrics to be used during training. The code sample shows how to compile a model with stochastic gradient descent (SGD) optimizer and categorical cross-entropy loss.

model.compile({
  optimizer: 'sgd',
  loss: 'categoricalCrossentropy',
  metrics: ['accuracy']
});

Training a Model

This feature allows you to train the model using the fit method. The code sample demonstrates how to train the model with random data for 10 epochs and a batch size of 32.

const xs = tf.randomNormal([100, 50]);
const ys = tf.randomUniform([100, 10]);
model.fit(xs, ys, {
  epochs: 10,
  batchSize: 32
}).then(history => {
  console.log(history.history);
});

Evaluating a Model

This feature allows you to evaluate the model's performance on test data. The code sample shows how to evaluate the model using random test data.

const testXs = tf.randomNormal([20, 50]);
const testYs = tf.randomUniform([20, 10]);
model.evaluate(testXs, testYs).print();

Making Predictions

This feature allows you to make predictions using the trained model. The code sample demonstrates how to make a prediction with a single input sample.

const input = tf.randomNormal([1, 50]);
const prediction = model.predict(input);
prediction.print();

Other packages similar to @tensorflow/tfjs-layers

FAQs

Package last updated on 17 Feb 2021

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