Nasal Piercings Manipulator
    Wondering what’s next for npm?Check out our public roadmap! »

    tensorflow2

    2.0.0 • Public • Published

    TensorFlow for Node.js

    NPM Dependency Build Coverage
    NPM version Dependency Status Build Status Coverage

    This library wraps Tensorflow Python for Node.js developers, it's powered by @pipcook/boa.

    Notice: This project is still under active development and not guaranteed to have a stable API. This is especially true because the underlying TensorFlow C API has not yet been stabilized as well.

    Installation

    $ npm install tensorflow2 --save

    Usage

    const tf = require('tensorflow2');
     
    // load mnist dataset.
    const dataset = tf.keras.dataset.mnist();
    // {
    //   train: { x: [Getter], y: [Getter] },
    //   test: { x: [Getter], y: [Getter] }
    // }
     
    // create model.
    const model = tf.keras.models.Sequential([
      tf.keras.layers.Flatten({
        input_shape: [28, 28]
      }),
      tf.keras.layers.Dense(128, {
        activation: 'relu'
      }),
      tf.keras.layers.Dropout(0.2),
      tf.keras.layers.Dense(10)
    ]);
    model.summary();
     
    // compile the model.
    const loss_fn = tf.keras.losses.SparseCategoricalCrossentropy({ from_logits: true });
    model.compile({
      optimizer: 'adam',
      loss: loss_fn,
      metrics: [ 'accuracy' ],
    });
     
    // train the model.
    model.fit(dataset.train.x, dataset.train.y, { epochs: 5 });
     
    // save the model
    model.save('your-model.h5');

    See example/mnist.js for complete example.

    Tests

    $ npm test

    License

    MIT licensed @ 2020

    Keywords

    Install

    npm i tensorflow2

    DownloadsWeekly Downloads

    4

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    9.84 kB

    Total Files

    9

    Last publish

    Collaborators

    • avatar