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

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +47 -3
README.md CHANGED
@@ -1,3 +1,47 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ```