Update README.md
Browse files
README.md
CHANGED
@@ -1 +1,93 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: transformers.js
|
3 |
+
pipeline_tag: object-detection
|
4 |
+
---
|
5 |
+
|
6 |
+
ONNX weights for https://huggingface.co/hantian/yolo-doclaynet yolo10b
|
7 |
+
|
8 |
+
## Usage (Transformers.js)
|
9 |
+
|
10 |
+
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
|
11 |
+
```bash
|
12 |
+
npm i @huggingface/transformers
|
13 |
+
```
|
14 |
+
|
15 |
+
**Example:** Perform object-detection with `Oblix/yolov10b-doclaynet_ONNX_document-layout-analysis`.
|
16 |
+
|
17 |
+
```js
|
18 |
+
const model = await AutoModel.from_pretrained(
|
19 |
+
"Oblix/yolov10b-doclaynet_ONNX_document-layout-analysis",
|
20 |
+
{
|
21 |
+
dtype: "fp32"
|
22 |
+
}
|
23 |
+
);
|
24 |
+
const processor = await AutoProcessor.from_pretrained(
|
25 |
+
"Oblix/yolov10b-doclaynet_ONNX_document-layout-analysis"
|
26 |
+
);
|
27 |
+
const url =
|
28 |
+
"https://huggingface.co/DILHTWD/documentlayoutsegmentation_YOLOv8_ondoclaynet/resolve/main/sample1.png";
|
29 |
+
const image = await RawImage.read(url);
|
30 |
+
const { pixel_values, reshaped_input_sizes } = await processor(image);
|
31 |
+
|
32 |
+
// Run object detection
|
33 |
+
const { output0 } = await model({ images: pixel_values });
|
34 |
+
const predictions = output0.tolist()[0];
|
35 |
+
|
36 |
+
const threshold = 0.35;
|
37 |
+
const [newHeight, newWidth] = reshaped_input_sizes[0]; // Reshaped height and width
|
38 |
+
const [xs, ys] = [image.width / newWidth, image.height / newHeight]; // x and y resize scales
|
39 |
+
for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
|
40 |
+
if (score < threshold) continue;
|
41 |
+
|
42 |
+
// Convert to original image coordinates
|
43 |
+
const bbox = [xmin * xs, ymin * ys, xmax * xs, ymax * ys]
|
44 |
+
.map((x) => x.toFixed(2))
|
45 |
+
.join(", ");
|
46 |
+
console.log(
|
47 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
48 |
+
`Found "${(model.config as any).id2label[id]}" at [${bbox}] with score ${score.toFixed(
|
49 |
+
2
|
50 |
+
)}.`
|
51 |
+
);
|
52 |
+
}
|
53 |
+
```
|
54 |
+
|
55 |
+
**Result**
|
56 |
+
```
|
57 |
+
Found "Text" at [53.75, 478.56, 623.46, 562.13] with score 0.98.
|
58 |
+
Found "Text" at [54.20, 593.64, 609.42, 637.15] with score 0.98.
|
59 |
+
Found "Text" at [53.98, 715.41, 621.06, 759.33] with score 0.98.
|
60 |
+
Found "Text" at [53.98, 247.44, 610.82, 277.49] with score 0.97.
|
61 |
+
Found "Title" at [53.64, 75.40, 551.96, 159.72] with score 0.97.
|
62 |
+
Found "List-item" at [55.56, 761.62, 607.48, 792.06] with score 0.97.
|
63 |
+
Found "List-item" at [56.05, 657.97, 614.57, 701.79] with score 0.97.
|
64 |
+
Found "Text" at [54.10, 195.40, 221.43, 211.88] with score 0.96.
|
65 |
+
Found "Text" at [54.25, 169.14, 95.17, 186.22] with score 0.95.
|
66 |
+
Found "Text" at [54.15, 222.11, 98.62, 237.74] with score 0.95.
|
67 |
+
Found "Text" at [53.73, 429.63, 412.82, 446.28] with score 0.95.
|
68 |
+
Found "Page-header" at [308.98, 10.07, 605.53, 34.59] with score 0.95.
|
69 |
+
Found "Section-header" at [54.18, 338.87, 102.68, 355.16] with score 0.95.
|
70 |
+
Found "List-item" at [55.75, 793.91, 519.29, 810.43] with score 0.95.
|
71 |
+
Found "Section-header" at [54.20, 453.01, 145.02, 469.42] with score 0.94.
|
72 |
+
Found "Text" at [56.76, 309.85, 316.43, 325.71] with score 0.93.
|
73 |
+
Found "List-item" at [55.62, 812.37, 445.03, 829.42] with score 0.92.
|
74 |
+
Found "Page-footer" at [308.43, 907.93, 374.03, 922.28] with score 0.92.
|
75 |
+
Found "Section-header" at [53.70, 567.21, 75.24, 584.85] with score 0.91.
|
76 |
+
Found "Text" at [56.26, 289.47, 415.46, 306.48] with score 0.80.
|
77 |
+
Found "Text" at [54.11, 365.35, 623.46, 407.97] with score 0.79.
|
78 |
+
Found "List-item" at [55.77, 638.84, 382.47, 655.46] with score 0.60.
|
79 |
+
```
|
80 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64bad74f94c0e3be4aa7cd76/MIja7FCRhuXsjpv25_A8u.png)
|
81 |
+
|
82 |
+
## Labels
|
83 |
+
- Caption [0]
|
84 |
+
- Footnote [1]
|
85 |
+
- Formula [2]
|
86 |
+
- List-item [3]
|
87 |
+
- Page-footer [4]
|
88 |
+
- Page-header [5]
|
89 |
+
- Picture [6]
|
90 |
+
- Section-header [7]
|
91 |
+
- Table [8]
|
92 |
+
- Text [9]
|
93 |
+
- Title [10]
|