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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@renangeorgio/tfjs-yolo-tiny

v1.1.0

Published

YOLO Object detection right in the browser via Tensorflow.js

Downloads

5

Readme

⚡️ Fast In-Browser Object Detection 👀

Detect objects in images right in your browser using Tensorflow.js! Currently takes ~800ms to analyze each frame on Chrome MBP 13" mid-2014.

Supports Tiny YOLO, as of right now, tfjs does not have support to run any full YOLO models (and your user's computers probably can't handle it either).

Demo

Check out the Live Demo

(You can only get so far with 1 FPS)

yolo person detection

Install

Yarn

yarn add tfjs-yolo-tiny

Or NPM

npm install tfjs-yolo-tiny

Usage Example

import yolo, { downloadModel } from 'tfjs-yolo-tiny';

const model = await downloadModel();
const inputImage = webcam.capture();

const boxes = await yolo(inputImage, model);

// Display detected boxes
boxes.forEach(box => {
  const {
    top, left, bottom, right, classProb, className,
  } = box;

  drawRect(left, top, right-left, bottom-top, `${className} ${classProb}`)
});

API Docs

yolo(input, model, options)

Args

Param | Type | Default | Description -- | -- | -- | -- input | tf.Tensor | - | Expected shape (1, 416, 416, 3) Tensor representing input image (RGB 416x416) model | tf.Model | - | Tiny YOLO tf.Model [options] | Object | See Below | Optional, Additional Configs

If you're using a custom Tiny YOLO model or want to adjust the default filtering cutoffs, you may do so by passing an additional options object.

Example: yolo(inputImage, model, { classProbThreshold: 0.8 });

Option | Type | Default | Description -- | -- | -- | -- | [options.classProbThreshold] | Number | 0.4 | Filter out classes below a certain threshold | | [options.iouThreshold] | Number | 0.4 | Filter out boxes that have an IoU greater than this threadhold (refer to tf.image.nonMaxSuppression) | | [options.filterBoxesThreshold] | Number | 0.01 | Threshold to filter out box confidence * class confidence | | [options.maxBoxes] | Number | 2048 | Number of max boxes to return, refer to tf.image.nonMaxSuppression. Note: The model itself can only return so many boxes. | | [options.yoloAnchors] | tf.Tensor | See src/postprocessing.js | (Advanced) Yolo Anchor Boxes, only needed if retraining on a new dataset | | [options.width] | Number | 416 | (Advanced) If your model's input width is not 416, only if you're using a custom model | | [options.height] | Number | 416 | (Advanced) If your model's input height is not 416, only if you're using a custom model | | [options.numClasses] | Number | 80 | (Advanced) If your model has a different number of classes, only if you're using a custom model | | [options.classNames] | Array.<String> | See src/coco_classes.js | (Advanced) If your model has non-MSCOCO class names, only if you're using a custom model |

Returns

Returns an array of objects.

Property | Type | Description -- | -- | -- top | Number | Pixels from top of image where bounding box starts left | Number | Pixels from left of image where bounding box starts bottom | Number | Pixels from top of image where box ends. right | Number | Pixels from left of image where box ends. classProb | Number | Probability of the class in the bounding box. className | String | Human name of the class.

downloadModel(url)

Args

Param | Type | Default | Description -- | -- | -- | -- url | string | See DEFAULT_MODEL_LOCATION | Tiny YOLO Model config path. See tf.loadModel

Returns

Returns a Promise that can resolve to a tf.Model.

Contributing

PR's are more than welcome! Perf improvement or better test coverage are probably the two biggest areas of immediate need. If you have thoughts on extensibility as well, feel free to open an issue!

Install Dependencies

yarn install

Run Tests

If you're running tests, make sure to yarn add @tensorflow/[email protected] so that you you don't get tfjs package not found errors. If you're developing, make sure to remove tfjs as a dependency, as it'll start using the local version of tfjs intead of the peer version.

Note: Test coverage is poor, definitely don't rely on them to catch your errors.

yarn test

Build

yarn build

Or during development, use watch mode, you can use the demo app to test out changes.

yarn watch