YOLO()

YOLO (You only look once) is a state-of-the-art, real-time object detection system.

You only look once (YOLO) is a state-of-the-art, real-time object detection system.

From the creators website:

Prior detection systems repurpose classifiers or localizers to perform detection. They apply the model to an image at multiple locations and scales. High scoring regions of the image are considered detections. We use a totally different approach. We apply a single neural network to the full image. This network divides the image into regions and predicts bounding boxes and probabilities for each region. These bounding boxes are weighted by the predicted probabilities. Source

This implementation is heavily derived from ModelDepot.

Example

const video = document.getElementById("video");

// Create a YOLO method
const yolo = ml5.YOLO(video, modelLoaded);

// When the model is loaded
function modelLoaded() {
  console.log("Model Loaded!");
}

// Detect objects in the video element
yolo.detect(function(err, results) {
  console.log(results); // Will output bounding boxes of detected objects
});

Here is a complete example.

Syntax

ml5.YOLO();
ml5.YOLO(video);
ml5.YOLO(video, ?options, ?callback)
ml5.YOLO(?options, ?callback)

Parameters

  • video - Optional. A HTML video element or a p5 video element.
  • options - Optional. An object describing a model accuracy and performance. For MobileNet this are: { filterBoxesThreshold: 0.01, IOUThreshold: 0.4, classProbThreshold: 0.4 }
  • callback - Optional. A function to run once the model has been loaded. If no callback is provided, it will return a promise that will be resolved once the model has loaded.

Properties

.isPredicting

Boolean to check if the model is currently predicting

.modelReady

Boolean to check if the model has loaded

Methods

.detect(input, ?callback)
.detect(?callback)

Given an image or video, returns an array of objects containing class names, bounding boxes and probabilities.

input - A HTML video or image element or a p5 image or video element. If no input is provided, the default is to use the video given in the constructor.

callback - A function to run once the model has made the prediction. If no callback is provided, it will return a promise that will be resolved once the model has made a prediction.

Source

/src/YOLO