npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@inevitable/tfjs-mnist

v1.0.0

Published

An implementation of the MNIST neural network for use in backend ML systems.

Readme

TensorFlowJS Minst

An implementation of the MNIST neural network for use in backend ML systems.

Example Usages

Basic

To use this package and run it on the test data provided, the only code that needs to be wrote is:

    let config = {};
    let mnistTester: new mnist(config);
    await mnistTester.setup();
    await mnistTester.train();
    await mnistTester.evaluate();
    console.table(mnistTester.prettyConfusionMatrix());
    console.log("Accuracy: ", mnistTester.accuracy() + "%");

Which will then display a result of:

┌────────────┬────────────────┬────────────────┬────────────────┬────────────────┬────────────────┬────────────────┬────────────────┬────────────────┬────────────────┬────────────────┐
│  (index)   │ "0" Prediction │ "1" Prediction │ "2" Prediction │ "3" Prediction │ "4" Prediction │ "5" Prediction │ "6" Prediction │ "7" Prediction │ "8" Prediction │ "9" Prediction │
├────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┤
│ "0" Actual │       24       │       0        │       0        │       0        │       0        │       0        │       0        │       0        │       0        │       0        │
│ "1" Actual │       0        │       26       │       0        │       0        │       0        │       0        │       0        │       0        │       0        │       0        │
│ "2" Actual │       0        │       0        │       23       │       0        │       0        │       0        │       0        │       1        │       0        │       0        │
│ "3" Actual │       0        │       0        │       0        │       28       │       0        │       0        │       0        │       1        │       0        │       0        │
│ "4" Actual │       0        │       0        │       0        │       0        │       24       │       0        │       0        │       0        │       0        │       1        │
│ "5" Actual │       0        │       0        │       0        │       0        │       0        │       26       │       0        │       0        │       0        │       0        │
│ "6" Actual │       0        │       0        │       0        │       0        │       0        │       1        │       17       │       0        │       0        │       0        │
│ "7" Actual │       0        │       0        │       1        │       0        │       0        │       0        │       0        │       25       │       2        │       1        │
│ "8" Actual │       1        │       0        │       1        │       0        │       0        │       2        │       1        │       0        │       18       │       0        │
│ "9" Actual │       0        │       0        │       0        │       0        │       0        │       1        │       0        │       0        │       0        │       25       │
└────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┘
Accuracy:  94.4%

Use Model to Predict a new Image

Using the trained model from above, the following code can be added to see the prediction of a given image.

    let onePrediction = await mnistTester.predictOne(`${__dirname}/example_dataset/0/img_5.jpg`);
    console.log("Predict One Prediction: ", onePrediction);

Which will then log the following result:

    Predict One Prediction:  0

Source Folder Structure

In the imagesUrl parameter you specify for the source folder, there are two acceptable structure, one where you can manually split the training and testing data, then another where it is randomly determined by the split parameter.

Manual Split

example_dataset
+-- training
|   +-- 0
|   |   +-- img_0.jpg
|   |   +-- img_2.jpg
|   |   +-- img_43.jpg
|   +-- 1
|   |   +-- img_23.jpg
|   |   +-- img_76.jpg
|   |   +-- img_245.jpg
+-- testing
|   +-- 0
|   |   +-- img_69.jpg
|   |   +-- img_66.jpg
|   |   +-- img_56.jpg
|   +-- 1
|   |   +-- img_68.jpg
|   |   +-- img_58.jpg

Auto Split

example_dataset
+-- 0
|   +-- img_67.jpg
|   +-- img_57.jpg
|   +-- img_33.jpg
|   +-- img_13.jpg
+-- 1
|   +-- img_34.jpg
|   +-- img_56.jpg
|   +-- img_23.jpg

Parameters

The imagesUrl has been mentioned to specify the source folder, but below are all of the possible parameters that can be used when instantiating a new mnist Object.

    let config: {
        this.tf = config.tf || require("@tensorflow/tfjs-node"); // Optional: TF, enables the gpu package to be passed in
        this.onlyTesting = config.onlyTesting || false; // Optional: Boolean, true if you want to test via other means and use the "predictOne" function
        this.imageLimiter = config.imageLimiter || false; // Optional: Number, % of images to use, 0.9 turns 100 images to 90 images to use (then being split into training and testing data)
        this.split = config.split || 0.75; // Optional: Float, vary the difference in training and testing data, 0.75 = 75% of the images will be used for training
        this.oldModelImageSize = config.modelImageSize || 28;  // Optional: Number, specify the input width/height of the old model
        this.modelImageShape = [this.oldModelImageSize, this.oldModelImageSize, 1];  // Using the input size to get the shape
        this.imagesUrl = config.imagesUrl || `${__dirname}/example_dataset`;  // Optional: String, specify the location of where the source folder is of the images
        this.lossFunction = config.lossFunction || 'categoricalCrossentropy';  // Optional: String, loss function for the models training phase
        this.optimizer = config.optimizer || 'rmsprop';  // Optional: tf.train / String, optimizer for the models training phase
        this.epochs = config.epochs || 5;  // Optional: Number, specify the amount of epoches to be run during the training phase
        this.batchSize = config.batchSize || 8; // Optional: Number, specify the size of batchs to be run during the training phase
    }