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-transfer-learner

v1.2.8

Published

Retrain the MobileNet model via transfer learning using TensorFlow.js in NodeJS.

Readme

TensorFlowJS Transfer Learner

Retrain the MobileNet model via transfer learning using TensorFlow.js in NodeJS.

Using the popular MobileNet model as a feature extractor, this package allows a user to target a source folder of images, then produce a model to be trained or tested.

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 transferLearnerTester: new transferLearner(config);
    await transferLearnerTester.setup();
    await transferLearnerTester.train();
    await transferLearnerTester.evaluate();
    console.table(transferLearnerTester.prettyConfusionMatrix());
    console.log("Accuracy: ", transferLearnerTester.accuracy() + "%");

Which will then display a result of:

    ┌────────────────┬───────────────────┬────────────────────┬──────────────────┐
    │    (index)     │ "blue" Prediction │ "green" Prediction │ "red" Prediction │
    ├────────────────┼───────────────────┼────────────────────┼──────────────────┤
    │ "blue" Actual  │         1         │         0          │        0         │
    │ "green" Actual │         1         │         2          │        0         │
    │  "red" Actual  │         0         │         0          │        3         │
    └────────────────┴───────────────────┴────────────────────┴──────────────────┘
    Accuracy:  85.71%

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 transferLearnerTester.predictOne(`${__dirname}/example_dataset/green/1.png`);
    console.log("Predict One Prediction: ", onePrediction);

Which will then log the following result:

    Predict One Prediction:  green

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
|   +-- blue
|   |   +-- image_x.jpeg
|   |   +-- image_z.png
|   |   +-- image_l.png
|   +-- green
|   |   +-- image_q.png
|   |   +-- image_a.jpg
|   |   +-- image_d.jpeg
+-- testing
|   +-- blue
|   |   +-- image_er.png
|   |   +-- image_do.jpg
|   |   +-- image_b.jpg
|   +-- green
|   |   +-- ima_0.jpeg
|   |   +-- imatg.jpg

Auto Split

example_dataset
+-- blue
|   +-- image_x.jpeg
|   +-- image_z.png
|   +-- image_do.jpg
|   +-- image_b.jpg
+-- green
|   +-- image_q.png
|   +-- image_a.jpg
|   +-- image_d.jpeg

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 transferLearner Object.

    let config: {
        onlyTesting: false, // Optional: Boolean, true if you want to test via other means and use the "predictOne" function
        split: 0.75, // Optional: Float, vary the difference in training and testing data, 0.75: 75% of the images will be used for training
        oldModel: null,  // Optional: tf.model(), Only pass if you do not wish to download and use the model from the oldModelUrl
        oldModelUrl: 'https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json',  // Optional: URL / String
        oldModelLayer: 'conv_pw_13_relu',  // Optional: String, which layer of the old model to be used as the feature extractor
        oldModelImageSize: 224,  // Optional: Number, specifiy the input width/height of the old model
        oldModelImageShape: [this.oldModelImageSize, this.oldModelImageSize, 3],  // Optional, using the input size to get the shape
        imagesUrl: `${__dirname}/example_dataset`,  // Optional: String, specify the location of where the source folder is of the images
        lossFunction: 'categoricalCrossentropy',  // Optional: String, loss function for the models training phase
        optimizer: tf.train.adam(),  // Optional: tf.train / String, optimizer for the models training phase
        epochs: 5,  // Optional: Number, specify the amount of epoches to be run during the training phase
        batchSize: 8 // Optional: Number, specify the size of batchs to be run during the training phase
    }