Update app.py
Browse files
app.py
CHANGED
@@ -22,10 +22,10 @@ def box_cxcywh_to_xyxy(x):
|
|
22 |
|
23 |
|
24 |
def rescale_bboxes(out_bbox, size):
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
return
|
29 |
|
30 |
|
31 |
def outputs_to_objects(outputs, img_size, id2label):
|
@@ -50,8 +50,8 @@ def fig2img(fig):
|
|
50 |
buf = io.BytesIO()
|
51 |
fig.savefig(buf)
|
52 |
buf.seek(0)
|
53 |
-
|
54 |
-
return
|
55 |
|
56 |
|
57 |
def visualize_detected_tables(img, det_tables):
|
@@ -117,7 +117,7 @@ def detect_table(image):
|
|
117 |
detected_tables = outputs_to_objects(outputs, image.size, id2label)
|
118 |
|
119 |
# visualize
|
120 |
-
fig = visualize_detected_tables(
|
121 |
image = fig2img(fig)
|
122 |
|
123 |
return image
|
|
|
22 |
|
23 |
|
24 |
def rescale_bboxes(out_bbox, size):
|
25 |
+
width, height = size
|
26 |
+
boxes = box_cxcywh_to_xyxy(out_bbox)
|
27 |
+
boxes = boxes * torch.tensor([width, height, width, height], dtype=torch.float32)
|
28 |
+
return boxes
|
29 |
|
30 |
|
31 |
def outputs_to_objects(outputs, img_size, id2label):
|
|
|
50 |
buf = io.BytesIO()
|
51 |
fig.savefig(buf)
|
52 |
buf.seek(0)
|
53 |
+
image = Image.open(buf)
|
54 |
+
return image
|
55 |
|
56 |
|
57 |
def visualize_detected_tables(img, det_tables):
|
|
|
117 |
detected_tables = outputs_to_objects(outputs, image.size, id2label)
|
118 |
|
119 |
# visualize
|
120 |
+
fig = visualize_detected_tables(image, detected_tables)
|
121 |
image = fig2img(fig)
|
122 |
|
123 |
return image
|