darknoah99 commited on
Commit
dd2edee
·
verified ·
1 Parent(s): 605fa81

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +50 -46
README.md CHANGED
@@ -1,47 +1,51 @@
1
- Converted from [wybxc/DocLayout-YOLO-DocStructBench-onnx](https://huggingface.co/wybxc/DocLayout-YOLO-DocStructBench-onnx)
2
-
3
- ```ts
4
- import {
5
- AutoProcessor,
6
- RawImage,
7
- AutoModel,
8
- env,
9
- } from '@huggingface/transformers';
10
-
11
-
12
- const model = await AutoModel.from_pretrained('darknoah99/DocLayout-YOLO-DocStructBench-onnx');
13
- const processor = await AutoProcessor.from_pretrained('darknoah99/DocLayout-YOLO-DocStructBench-onnx', {});
14
- let image;
15
- if (isUrl(fileOrUrl)) image = await RawImage.fromURL(fileOrUrl);
16
- else if (fs.statSync(fileOrUrl).isFile()) {
17
- const data = fs.readFileSync(fileOrUrl);
18
- const blob = new Blob([data]);
19
- image = await RawImage.fromBlob(blob);
20
- }
21
- const { pixel_values } = await processor(image);
22
- const output = await model({ images: pixel_values });
23
- const permuted = output.output0[0];
24
- const result = [];
25
- const threshold = 0.3;
26
- const [scaledHeight, scaledWidth] = pixel_values.dims.slice(-2);
27
- for (const [xc, yc, w, h, ...scores] of permuted.tolist()) {
28
- const x1 = (xc / scaledWidth) * image.width;
29
- const y1 = (yc / scaledHeight) * image.height;
30
- const x2 = (w / scaledWidth) * image.width;
31
- const y2 = (h / scaledHeight) * image.height;
32
- const score = scores[0];
33
- if (score > threshold) {
34
- const label = model.config.id2label[scores[1]];
35
- result.push({
36
- x1,
37
- x2,
38
- y1,
39
- y2,
40
- score,
41
- label,
42
- index: scores[1],
43
- });
44
- }
45
- }
46
- console.log(result)
 
 
 
 
47
  ```
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: transformers.js
4
+ ---
5
+ Converted from [wybxc/DocLayout-YOLO-DocStructBench-onnx](https://huggingface.co/wybxc/DocLayout-YOLO-DocStructBench-onnx)
6
+
7
+ ```ts
8
+ import {
9
+ AutoProcessor,
10
+ RawImage,
11
+ AutoModel,
12
+ env,
13
+ } from '@huggingface/transformers';
14
+
15
+
16
+ const model = await AutoModel.from_pretrained('darknoah99/DocLayout-YOLO-DocStructBench-onnx');
17
+ const processor = await AutoProcessor.from_pretrained('darknoah99/DocLayout-YOLO-DocStructBench-onnx', {});
18
+ let image;
19
+ if (isUrl(fileOrUrl)) image = await RawImage.fromURL(fileOrUrl);
20
+ else if (fs.statSync(fileOrUrl).isFile()) {
21
+ const data = fs.readFileSync(fileOrUrl);
22
+ const blob = new Blob([data]);
23
+ image = await RawImage.fromBlob(blob);
24
+ }
25
+ const { pixel_values } = await processor(image);
26
+ const output = await model({ images: pixel_values });
27
+ const permuted = output.output0[0];
28
+ const result = [];
29
+ const threshold = 0.3;
30
+ const [scaledHeight, scaledWidth] = pixel_values.dims.slice(-2);
31
+ for (const [xc, yc, w, h, ...scores] of permuted.tolist()) {
32
+ const x1 = (xc / scaledWidth) * image.width;
33
+ const y1 = (yc / scaledHeight) * image.height;
34
+ const x2 = (w / scaledWidth) * image.width;
35
+ const y2 = (h / scaledHeight) * image.height;
36
+ const score = scores[0];
37
+ if (score > threshold) {
38
+ const label = model.config.id2label[scores[1]];
39
+ result.push({
40
+ x1,
41
+ x2,
42
+ y1,
43
+ y2,
44
+ score,
45
+ label,
46
+ index: scores[1],
47
+ });
48
+ }
49
+ }
50
+ console.log(result)
51
  ```