Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -13,6 +13,34 @@ 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 |
// To-Do #1 pipeline API๋ฅผ ์ฌ์ฉํ์ฌ detr-resnet-50 object detection ๋ชจ๋ธ์ instance๋ฅผ detector๋ผ๋ ์ด๋ฆ์ ๋ถ์ฌ ์์ฑํ์ญ์์ค.
|
17 |
// DETR ๋ชจ๋ธ ์ฐธ๊ณ ๋ฌธ์ https://huggingface.co/facebook/detr-resnet-50
|
18 |
const detector = await '???';
|
@@ -44,15 +72,13 @@ 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 |
}
|
55 |
|
|
|
56 |
// Render a bounding box and label on the image
|
57 |
function renderBox({ box, label }) {
|
58 |
const { xmax, xmin, ymax, ymin } = box;
|
|
|
13 |
|
14 |
// Create a new object detection pipeline
|
15 |
status.textContent = 'Loading model...';
|
16 |
+
|
17 |
+
์๋ ์ฝ๋๋ ์ฃผ์ด์ง ์ฃผ์์ ๊ธฐ๋ฐ์ผ๋ก detr-resnet-50 Object Detection ๋ชจ๋ธ์ ์ธ์คํด์ค๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค. ์ด๋ฅผ ์ํด Hugging Face์ Transformers ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๊ฒ ์ต๋๋ค.
|
18 |
+
|
19 |
+
javascript
|
20 |
+
Copy code
|
21 |
+
// ํ์ํ ๋ชจ๋์ ๋ถ๋ฌ์ต๋๋ค.
|
22 |
+
const { pipeline } = require('@huggingface/node-fetch');
|
23 |
+
const { detr } = require('@transformers/detr-resnet-50');
|
24 |
+
|
25 |
+
// ์ํ ํ
์คํธ๋ฅผ ์
๋ฐ์ดํธํฉ๋๋ค.
|
26 |
+
status.textContent = 'Loading model...';
|
27 |
+
|
28 |
+
// DETR ๋ชจ๋ธ์ ๋ก๋ํฉ๋๋ค.
|
29 |
+
(async () => {
|
30 |
+
try {
|
31 |
+
// Object Detection ๋ชจ๋ธ์ ๋ก๋ํฉ๋๋ค.
|
32 |
+
const detector = await pipeline(detr, { model: 'facebook/detr-resnet-50' });
|
33 |
+
|
34 |
+
// ๋ชจ๋ธ ๋ก๋ฉ์ด ์๋ฃ๋๋ฉด ์ํ๋ฅผ ์
๋ฐ์ดํธํฉ๋๋ค.
|
35 |
+
status.textContent = 'Model loaded successfully.';
|
36 |
+
|
37 |
+
// ์์ฑ๋ detector๋ฅผ ์ฌ์ฉํ์ฌ Object Detection์ ์ํํ ์ ์์ต๋๋ค.
|
38 |
+
// ์์: const result = await detector('input image');
|
39 |
+
} catch (error) {
|
40 |
+
// ๋ชจ๋ธ ๋ก๋ฉ ์ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ฉด ์ํ๋ฅผ ์
๋ฐ์ดํธํฉ๋๋ค.
|
41 |
+
status.textContent = 'Error loading model: ' + error.message;
|
42 |
+
}
|
43 |
+
})();
|
44 |
// To-Do #1 pipeline API๋ฅผ ์ฌ์ฉํ์ฌ detr-resnet-50 object detection ๋ชจ๋ธ์ instance๋ฅผ detector๋ผ๋ ์ด๋ฆ์ ๋ถ์ฌ ์์ฑํ์ญ์์ค.
|
45 |
// DETR ๋ชจ๋ธ ์ฐธ๊ณ ๋ฌธ์ https://huggingface.co/facebook/detr-resnet-50
|
46 |
const detector = await '???';
|
|
|
72 |
imageContainer.style.backgroundImage = `url(${img})`;
|
73 |
|
74 |
status.textContent = 'Analysing...';
|
75 |
+
// ๊ฐ์ฒด ํ์ง๋ฅผ ์ํ ํ์ดํ๋ผ์ธ์ ์์ฑํ๊ณ threshold์ percentage๋ฅผ ์ค์ ํฉ๋๋ค.
|
76 |
+
const output = await detector(img, { threshold: 0.5, percentage: true });
|
|
|
|
|
|
|
77 |
status.textContent = '';
|
78 |
output.forEach(renderBox);
|
79 |
}
|
80 |
|
81 |
+
|
82 |
// Render a bounding box and label on the image
|
83 |
function renderBox({ box, label }) {
|
84 |
const { xmax, xmin, ymax, ymin } = box;
|