Tobias Cornille commited on
Commit
5c804a1
1 Parent(s): 4424728

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +4 -10
index.js CHANGED
@@ -13,7 +13,7 @@ const EXAMPLE_URL = 'https://huggingface.co/datasets/Xenova/transformers.js-docs
13
 
14
  // Create a new object detection pipeline
15
  status.textContent = 'Loading model...';
16
- const detector = await pipeline('zero-shot-object-detection', 'Xenova/owlvit-base-patch32');
17
  status.textContent = 'Ready';
18
 
19
  example.addEventListener('click', (e) => {
@@ -42,17 +42,11 @@ async function detect(img) {
42
  imageContainer.style.backgroundImage = `url(${img})`;
43
 
44
  status.textContent = 'Analysing...';
45
-
46
- const image = new Image();
47
- image.src = img;
48
 
49
  const candidate_labels = ['human face', 'rocket', 'helmet', 'american flag'];
50
- image.onload = async function () {
51
- const output = await detector(img, candidate_labels);
52
- const relativeOutput = output.map(({box, label}) => ({box: {xmax: box.xmax / image.width, xmin: box.xmin / image.width, ymax: box.ymax / image.height, ymin: box.ymin / image.height}, label}));
53
- status.textContent = '';
54
- relativeOutput.forEach(renderBox);
55
- };
56
 
57
  }
58
 
 
13
 
14
  // Create a new object detection pipeline
15
  status.textContent = 'Loading model...';
16
+ const detector = await pipeline('zero-shot-object-detection', 'Xenova/owlvit-base-patch32', {percentage: true});
17
  status.textContent = 'Ready';
18
 
19
  example.addEventListener('click', (e) => {
 
42
  imageContainer.style.backgroundImage = `url(${img})`;
43
 
44
  status.textContent = 'Analysing...';
 
 
 
45
 
46
  const candidate_labels = ['human face', 'rocket', 'helmet', 'american flag'];
47
+ const output = await detector(img, candidate_labels);
48
+ status.textContent = '';
49
+ relativeOutput.forEach(renderBox);
 
 
 
50
 
51
  }
52