Object Detection - cocoSsd (Userscript)

Mode Homepage & Docs

coco-ssd tfjs

In Diffgram

Search cocoSsd

Video Example

Code

if (!this.model) {
  this.model = await cocoSsd.load({
  	base: 'mobilenet_v2'
	})
 } else {
	console.log("used cached model")
} 

const warm_up = await this.model.detect(
  diffgram.get_new_canvas())

let canvas = diffgram.get_new_canvas()

const predictions = await this.model.detect(
  canvas)

for (let prediction of predictions){
  console.log(prediction)
  if(prediction.bbox[2] <50) {continue}
  diffgram.create_box(
    prediction.bbox[0],
    prediction.bbox[1],
    prediction.bbox[2] + prediction.bbox[0],
    prediction.bbox[3] + prediction.bbox[1])     
}

NPM Packages

https://cdn.jsdelivr.net/npm/@tensorflow/tfjs
https://docs.opencv.org/master/opencv.js
https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd

Open cv requirement is a workaround due to this issue.

Example Image

This uses mobilenet_v2

1048