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 🙏

© 2025 – Pkg Stats / Ryan Hefner

yolo-ts

v1.0.5

Published

A TypeScript-based YOLO object detection library using TensorFlow.js

Downloads

144

Readme

YOLO-TS

npm version License: MIT

YOLO-TS is a TypeScript-based YOLO object detection library powered by TensorFlow.js. It enables real-time object detection on images, videos, and live webcam streams directly in the browser.

Features

  • Easy Integration: Simple API to quickly add object detection to your projects.
  • Real-Time Detection: Process images, videos, or live webcam feeds in real time.
  • Customizable: Configure labels, detection thresholds, and even a custom color palette.
  • Lightweight & Modular: Written in TypeScript for robust type-checking and maintainability.
  • CDN-Ready: Publish on npm and serve via CDNs like jsDelivr or unpkg.
  • Tested with YOLO Models: Compatible with YOLOv8 and YOLO11.

Live Examples

Check out the following demos to see YOLO-TS in action:

Image Detection Image Detection

Installation

Install via npm:

npm install yolo-ts

Or load directly from a CDN (UMD build):

<script src="https://cdn.jsdelivr.net/npm/yolo-ts@latest/dist/yolo.umd.js"></script>

Note: YOLO-TS has peer dependencies on TensorFlow.js and its WebGL backend. When using the UMD build, load these libraries before your YOLO-TS bundle:

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.22.0/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl@4.22.0/dist/tf-backend-webgl.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/yolo-ts@latest/dist/yolo.umd.js"></script>

Initial Configuration

The setup method in YOLO-TS allows for customization using the following configuration options:

export interface YOLOConfig {
  modelUrl: string;
  labels?: string[]; // Optional, defaulting to COCO categories
  colors?: string[]; // Optional, custom colors for label display
  displayLabels?: Set<string> | null; // Optional, filter specific labels to be displayed
  scoreThreshold?: number;
  boxLineWidth?: number;
  boxLabels?: boolean;
}

API Overview

YOLO-TS exposes a single class, YOLO, with the following primary methods:

setup(options) Configure the model with custom settings (e.g., model URL, labels, colors, display filters, and score thresholds).

yolo.setup({
  modelUrl: "model/model.json",
  labels: ["person", "car", "dog"],
  colors: ["#FF0000", "#00FF00"],
  displayLabels: new Set(["person", "dog"]),
  scoreThreshold: 0.3,
  boxLineWidth: 10,
  boxLabels: true,
});

loadModel() Loads the YOLO model from the specified URL. Returns a promise that resolves to the loaded model.

yolo.loadModel().then((model) => {
    console.log("Model loaded!", model)
  });

detect(source, model, canvasRef, callback) Processes an image, video, or canvas element for object detection using the YOLO model. It performs the following steps:

  • Preprocessing:
    Resizes and pads the source element (using letterboxing) to match the model's input dimensions.

  • Inference:
    Runs the YOLO model on the preprocessed input to generate detection predictions.

  • Postprocessing:
    Applies non-max suppression, adjusts the detection coordinates back to the original image dimensions, and maps numeric class indices to human-readable labels.

  • Rendering:
    Draws bounding boxes (with optional labels and scores) on the provided canvas element.

  • Callback:
    Invokes the supplied callback with a detection object that includes:

    • boxes: A flattened array of bounding box coordinates in the format [y1, x1, y2, x2, ...].
    • scores: An array of confidence scores for each detection.
    • classes: An array of numeric class indices.
    • labels: An array of human-readable label strings corresponding to the detected classes.
yolo.detect(imageElement, model, canvas, (detections) => {
  console.log(detections);
  // Example output:
  // {
  //   boxes: [50, 30, 200, 180, 210, 45, 350, 300],
  //   scores: [0.95, 0.87],
  //   classes: [0, 3],
  //   labels: ["person", "dog"]
  // }
});

detectVideo(videoSource, model, canvasRef) Continuously processes video frames for real-time detection.

yolo.detectVideo(videoElement, model, canvas);

Exporting a YOLO Model for TensorFlow.js

If you have a trained YOLO model and want to use it with YOLO-TS, you need to export it in TensorFlow.js format. Here's how you can do it:

from ultralytics import YOLO

# Load the YOLO model
model = YOLO("yolo11n.pt")

# Export the model to TensorFlow.js format
model.export(format="tfjs")

Contributing

Contributions are welcome! If you’d like to improve YOLO-TS, please fork the repository and submit a pull request.

  • Repository: https://github.com/josueggh/yolo-ts
  • Issues: https://github.com/josueggh/yolo-ts/issues