Xenova HF staff commited on
Commit
1ef8d50
1 Parent(s): aaf4881

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +5 -5
index.js CHANGED
@@ -10,6 +10,7 @@ const imageContainer = document.getElementById('container');
10
  const example = document.getElementById('example');
11
 
12
  const EXAMPLE_URL = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
 
13
 
14
  // Create a new object detection pipeline
15
  status.textContent = 'Loading model...';
@@ -50,7 +51,6 @@ async function detect(img) {
50
  const { pixel_values } = await processor(image);
51
  const { output0 } = await model({ images: pixel_values });
52
  const predictions = output0.tolist()[0];
53
- console.log(predictions);
54
  const threshold = 0.5;
55
  for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
56
  if (score < threshold) continue;
@@ -69,10 +69,10 @@ function renderBox(xmin, ymin, xmax, ymax, score, label) {
69
  boxElement.className = 'bounding-box';
70
  Object.assign(boxElement.style, {
71
  borderColor: color,
72
- left: 100 * xmin + '%',
73
- top: 100 * ymin + '%',
74
- width: 100 * (xmax - xmin) + '%',
75
- height: 100 * (ymax - ymin) + '%',
76
  })
77
 
78
  // Draw label
 
10
  const example = document.getElementById('example');
11
 
12
  const EXAMPLE_URL = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
13
+ const IMAGE_SIZE = 640;
14
 
15
  // Create a new object detection pipeline
16
  status.textContent = 'Loading model...';
 
51
  const { pixel_values } = await processor(image);
52
  const { output0 } = await model({ images: pixel_values });
53
  const predictions = output0.tolist()[0];
 
54
  const threshold = 0.5;
55
  for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
56
  if (score < threshold) continue;
 
69
  boxElement.className = 'bounding-box';
70
  Object.assign(boxElement.style, {
71
  borderColor: color,
72
+ left: 100 * xmin / IMAGE_SIZE + '%',
73
+ top: 100 * ymin / IMAGE_SIZE + '%',
74
+ width: 100 * (xmax - xmin) / IMAGE_SIZE + '%',
75
+ height: 100 * (ymax - ymin) / IMAGE_SIZE + '%',
76
  })
77
 
78
  // Draw label