Update index.js
Browse files
index.js
CHANGED
@@ -13,9 +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 |
-
|
17 |
-
// DETR 모델 참고 문서 https://huggingface.co/facebook/detr-resnet-50
|
18 |
-
const detector = await '???';
|
19 |
status.textContent = 'Ready';
|
20 |
|
21 |
example.addEventListener('click', (e) => {
|
@@ -44,11 +42,7 @@ async function detect(img) {
|
|
44 |
imageContainer.style.backgroundImage = `url(${img})`;
|
45 |
|
46 |
status.textContent = 'Analysing...';
|
47 |
-
|
48 |
-
const output = ???(
|
49 |
-
// threshold 값을 지정하고 쉼표를 붙이시오
|
50 |
-
// percentage 지정
|
51 |
-
);
|
52 |
status.textContent = '';
|
53 |
output.forEach(renderBox);
|
54 |
}
|
@@ -58,18 +52,18 @@ function renderBox({ box, label }) {
|
|
58 |
const { xmax, xmin, ymax, ymin } = box;
|
59 |
|
60 |
// Generate a random color for the box
|
61 |
-
const color = '#' + Math.floor(Math.random() * 0xFFFFFF).toString(16).padStart(6, 0);
|
62 |
|
63 |
// Draw the box
|
64 |
const boxElement = document.createElement('div');
|
65 |
boxElement.className = 'bounding-box';
|
66 |
Object.assign(boxElement.style, {
|
67 |
borderColor: color,
|
68 |
-
left: 100 * xmin
|
69 |
-
top: 100 * ymin
|
70 |
-
width: 100 * (xmax - xmin)
|
71 |
-
height: 100 * (ymax - ymin)
|
72 |
-
})
|
73 |
|
74 |
// Draw label
|
75 |
const labelElement = document.createElement('span');
|
|
|
13 |
|
14 |
// Create a new object detection pipeline
|
15 |
status.textContent = 'Loading model...';
|
16 |
+
const detector = await pipeline('object-detection', 'facebook/detr-resnet-50');
|
|
|
|
|
17 |
status.textContent = 'Ready';
|
18 |
|
19 |
example.addEventListener('click', (e) => {
|
|
|
42 |
imageContainer.style.backgroundImage = `url(${img})`;
|
43 |
|
44 |
status.textContent = 'Analysing...';
|
45 |
+
const output = await detector(img, { threshold: 0.5, percentage: true });
|
|
|
|
|
|
|
|
|
46 |
status.textContent = '';
|
47 |
output.forEach(renderBox);
|
48 |
}
|
|
|
52 |
const { xmax, xmin, ymax, ymin } = box;
|
53 |
|
54 |
// Generate a random color for the box
|
55 |
+
const color = '#' + Math.floor(Math.random() * 0xFFFFFF).toString(16).padStart(6, '0');
|
56 |
|
57 |
// Draw the box
|
58 |
const boxElement = document.createElement('div');
|
59 |
boxElement.className = 'bounding-box';
|
60 |
Object.assign(boxElement.style, {
|
61 |
borderColor: color,
|
62 |
+
left: `${100 * xmin}%`,
|
63 |
+
top: `${100 * ymin}%`,
|
64 |
+
width: `${100 * (xmax - xmin)}%`,
|
65 |
+
height: `${100 * (ymax - ymin)}%`,
|
66 |
+
});
|
67 |
|
68 |
// Draw label
|
69 |
const labelElement = document.createElement('span');
|