Views
No views yet
npm i @huggingface/transformersXenova/owlvit-base-patch32.1import { pipeline } from '@huggingface/transformers';
2
3const detector = await pipeline('zero-shot-object-detection', 'Xenova/owlvit-base-patch32');
4
5const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/astronaut.png';
6const candidate_labels = ['human face', 'rocket', 'helmet', 'american flag'];
7const output = await detector(url, candidate_labels);
8// [
9// { score: 0.24392342567443848, label: 'human face', box: { xmin: 180, ymin: 67, xmax: 274, ymax: 175 } },
10// { score: 0.15129457414150238, label: 'american flag', box: { xmin: 0, ymin: 4, xmax: 106, ymax: 513 } },
11// { score: 0.13649864494800568, label: 'helmet', box: { xmin: 277, ymin: 337, xmax: 511, ymax: 511 } },
12// { score: 0.10262022167444229, label: 'rocket', box: { xmin: 352, ymin: -1, xmax: 463, ymax: 287 } }
13// ]Xenova/owlvit-base-patch32 (additional parameters).1import { pipeline } from '@huggingface/transformers';
2
3const detector = await pipeline('zero-shot-object-detection', 'Xenova/owlvit-base-patch32');
4
5const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/beach.png';
6const candidate_labels = ['hat', 'book', 'sunglasses', 'camera'];
7const output = await detector(url, candidate_labels, { top_k: 4, threshold: 0.05 });
8// [
9// { score: 0.1606510728597641, label: 'sunglasses', box: { xmin: 347, ymin: 229, xmax: 429, ymax: 264 } },
10// { score: 0.08935828506946564, label: 'hat', box: { xmin: 38, ymin: 174, xmax: 258, ymax: 364 } },
11// { score: 0.08530698716640472, label: 'camera', box: { xmin: 187, ymin: 350, xmax: 260, ymax: 411 } },
12// { score: 0.08349756896495819, label: 'book', box: { xmin: 261, ymin: 280, xmax: 494, ymax: 425 } }
13// ]onnx).