Xenova HF staff commited on
Commit
b8a9903
1 Parent(s): a76bb3d

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +14 -10
index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.10.1';
2
 
3
  // Since we will download the model from the Hugging Face Hub, we can skip the local model check
4
  env.allowLocalModels = false;
@@ -13,7 +13,10 @@ 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('object-detection', 'Xenova/detr-resnet-50');
 
 
 
17
  status.textContent = 'Ready';
18
 
19
  example.addEventListener('click', (e) => {
@@ -42,18 +45,19 @@ async function detect(img) {
42
  imageContainer.style.backgroundImage = `url(${img})`;
43
 
44
  status.textContent = 'Analysing...';
45
- const output = await detector(img, {
46
- threshold: 0.5,
47
- percentage: true,
48
- });
 
49
  status.textContent = '';
50
- output.forEach(renderBox);
51
  }
52
 
53
  // Render a bounding box and label on the image
54
- function renderBox({ box, label }) {
55
- const { xmax, xmin, ymax, ymin } = box;
56
-
57
  // Generate a random color for the box
58
  const color = '#' + Math.floor(Math.random() * 0xFFFFFF).toString(16).padStart(6, 0);
59
 
 
1
+ import { env, AutoProcessor, AutoModel } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.15.1';
2
 
3
  // Since we will download the model from the Hugging Face Hub, we can skip the local model check
4
  env.allowLocalModels = false;
 
13
 
14
  // Create a new object detection pipeline
15
  status.textContent = 'Loading model...';
16
+ const processor = await AutoProcessor.from_pretrained('Xenova/yolov9-c');
17
+ const model = await AutoModel.from_pretrained('Xenova/yolov9-c', {
18
+ quantized: false,
19
+ });
20
  status.textContent = 'Ready';
21
 
22
  example.addEventListener('click', (e) => {
 
45
  imageContainer.style.backgroundImage = `url(${img})`;
46
 
47
  status.textContent = 'Analysing...';
48
+
49
+ const { pixel_values } = await processor(image);
50
+
51
+ const { outputs } = await model({images: pixel_values});
52
+
53
  status.textContent = '';
54
+ outputs.tolist().forEach(renderBox);
55
  }
56
 
57
  // Render a bounding box and label on the image
58
+ function renderBox([xmin, ymin, xmax, ymax, score, label]) {
59
+ console.log([xmin, ymin, xmax, ymax, score, label])
60
+ return;
61
  // Generate a random color for the box
62
  const color = '#' + Math.floor(Math.random() * 0xFFFFFF).toString(16).padStart(6, 0);
63