0.0.0 • Published 17 days ago

yolo-tfjs v0.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
17 days ago

⚡️ Load your YOLO v5 or v8 model in browser

Run object detection models trained with YOLOv5 YOLOv8 in browser using tensorflow.js

Demo

check out a demo of Aquarium Dataset object detection

Install

Yarn

yarn add yolo-tfjs

Or NPM

npm install yolo-tfjs

Usage Example

import YOLOTf from "yolo-tfjs";

const CLASSES = ["fish", "jellyfish"]
const COLORS = ["#00C2FF", "#FF9D97"]
const imageRef = useRef<HTMLImageElement>(null)

// load model files
const yoloTf = await YOLOTf.loadYoloModel(`model_path/model.json`, CLASSES, {
    yoloVersion: 'v8', onProgress(fraction: number){
        console.log('loading model...')
    }})

// return dection results with detected boxes
const results = await yoloTf.predict(imageRef.current)

// draw boxes in the canvas element
yoloTf.renderBox(canvasRef.current, {
    ...results, ratio: [results["xRatio"],results["yRatio"]]
}, COLORS)

API Docs

loadYoloModel(model, classes, config): YOLOTf

Args

ParamTypeDescription
modelstringpath to model.json file
classesstring[]classes of the trained model
configObjectsee below model configuration
ConfigTypeDefaultDescription
options.scoreThresholdNumber0.5
options.iouThresholdNumber0.45
options.maxOutputSizeNumber500
options.onProgressCallback(fraction: number) => void
options.yoloVersionYoloVersion_selected version v5 or v8

YOLOTf

PredictionData: {boxes, classes, scores, xRatio, yRatio}

predict(image, preprocessImage): PredictionData

ParamTypeDescription
imageHTMLImageElement
preprocessImage(image: HTMLImageElement) => PreprocessResultthis optional param to use custom image preprocessing

renderBox(canvas, predictionData, colors): {boxes, classes, scores, xRatio, yRatio}