Commit
·
e7d8eda
1
Parent(s):
1cededf
image size + boxes infos
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ import cv2
|
|
10 |
from unilm.dit.object_detection.ditod import add_vit_config
|
11 |
|
12 |
import torch
|
|
|
13 |
|
14 |
from detectron2.config import CfgNode as CN
|
15 |
from detectron2.config import get_cfg
|
@@ -51,8 +52,18 @@ def analyze_image(img):
|
|
51 |
result_image = result.get_image()[:, :, ::-1]
|
52 |
|
53 |
num_instances = len(output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
return result_image, num_instances
|
56 |
|
57 |
title = "Interactive demo: Document Layout Analysis with DiT"
|
58 |
description = "Demo for Microsoft's DiT, the Document Image Transformer for state-of-the-art document understanding tasks. This particular model is fine-tuned on PubLayNet, a large dataset for document layout analysis (read more at the links below). To use it, simply upload an image or use the example image below and click 'Submit'. Results will show up in a few seconds. If you want to make the output bigger, right-click on it and select 'Open image in new tab'."
|
@@ -62,7 +73,14 @@ css = ".output-image, .input-image, .image-preview {height: 600px !important}"
|
|
62 |
|
63 |
iface = gr.Interface(fn=analyze_image,
|
64 |
inputs=gr.inputs.Image(type="numpy", label="document image"),
|
65 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
title=title,
|
67 |
description=description,
|
68 |
examples=examples,
|
|
|
10 |
from unilm.dit.object_detection.ditod import add_vit_config
|
11 |
|
12 |
import torch
|
13 |
+
import numpy as np
|
14 |
|
15 |
from detectron2.config import CfgNode as CN
|
16 |
from detectron2.config import get_cfg
|
|
|
52 |
result_image = result.get_image()[:, :, ::-1]
|
53 |
|
54 |
num_instances = len(output)
|
55 |
+
image_size = output._image_size
|
56 |
+
fields = list(output.get_fields().keys())
|
57 |
+
for field in fields:
|
58 |
+
if field == 'pred_boxes':
|
59 |
+
boxes = output.get_fields()[field]
|
60 |
+
boxes_numpy = boxes.tensor.cpu().numpy()
|
61 |
+
boxes_bytes = boxes_numpy.tobytes()
|
62 |
+
boxes_numpy_shape = str(boxes_numpy.shape)
|
63 |
+
boxes_numpy_dtype = str(boxes_numpy.dtype)
|
64 |
+
# boxes_recover = torch.from_numpy(np.frombuffer(boxes_bytes, dtype=boxes_numpy_dtype).reshape(boxes_numpy_shape))
|
65 |
|
66 |
+
return result_image, num_instances, image_size, boxes_bytes, boxes_numpy_shape, boxes_numpy_dtype
|
67 |
|
68 |
title = "Interactive demo: Document Layout Analysis with DiT"
|
69 |
description = "Demo for Microsoft's DiT, the Document Image Transformer for state-of-the-art document understanding tasks. This particular model is fine-tuned on PubLayNet, a large dataset for document layout analysis (read more at the links below). To use it, simply upload an image or use the example image below and click 'Submit'. Results will show up in a few seconds. If you want to make the output bigger, right-click on it and select 'Open image in new tab'."
|
|
|
73 |
|
74 |
iface = gr.Interface(fn=analyze_image,
|
75 |
inputs=gr.inputs.Image(type="numpy", label="document image"),
|
76 |
+
outputs=[
|
77 |
+
gr.outputs.Image(type="numpy", label="annotated document"),
|
78 |
+
gr.outputs.Textbox(label="num instances"),
|
79 |
+
gr.outputs.Textbox(label="image size (h,w in pixels)"),
|
80 |
+
gr.outputs.Textbox(label="boxes bytes"),
|
81 |
+
gr.outputs.Textbox(label="boxes numpy shape"),
|
82 |
+
gr.outputs.Textbox(label="boxes numpy dtype"),
|
83 |
+
],
|
84 |
title=title,
|
85 |
description=description,
|
86 |
examples=examples,
|