17
loading...
This website collects cookies to deliver better user experience
// Note: Require the cpu and webgl backend and add them to package.json as peer dependencies.
import('@tensorflow/tfjs-backend-cpu');
import('@tensorflow/tfjs-backend-webgl');
import { load } from '@tensorflow-models/coco-ssd';
(async () => {
const img = document.querySelector('img');
// Load the model.
const model = await load();
// Classify the image.
const predictions = await model.detect(img);
console.log('Predictions: ', predictions);
})();
// Note: Require the cpu and webgl backend and add them to package.json as peer dependencies.
import('@tensorflow/tfjs-backend-cpu');
import('@tensorflow/tfjs-backend-webgl');
import { load } from '@tensorflow-models/coco-ssd';
(async () => {
const videoEl = document.querySelector('video');
// Load the model.
const model = await load();
// Classify the frame of the video.
// timeupdate is a quick way to run this as the video plays
videoEl.addEventListener('timeupdate', async () => {
const predictions = await model.detect(videoEl);
console.log('Predictions: ', predictions);
})
})();
[{
bbox: [x, y, width, height],
class: "person",
score: 0.8380282521247864
}, {
bbox: [x, y, width, height],
class: "sports ball",
score: 0.74644153267145157
}]
Note : The position (bbox) variables you get back will be based on the original video resolution.