Update example code to sort by reading order
Browse files
README.md
CHANGED
|
@@ -64,25 +64,21 @@ def run_doclayout_onnx():
|
|
| 64 |
input_names[1]: input_blob,
|
| 65 |
input_names[2]: [[scale_h, scale_w]]}
|
| 66 |
|
| 67 |
-
# shape=(300,
|
| 68 |
output = model.run(output_names, input_feed)[0]
|
| 69 |
|
| 70 |
# Filter out low-confidence boxes
|
| 71 |
boxes = output[output[:, 1] > 0.5]
|
| 72 |
print('--- DocLayoutV3 ONNX Output: ---')
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
def print_doclayout_res(boxes):
|
| 77 |
-
print('cls_id\tscore\txmin\tymin\txmax\tymax')
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
else:
|
| 82 |
-
for box in sorted(boxes, key=lambda x: x['coordinate'][0]):
|
| 83 |
-
xmin, ymin, xmax, ymax = box['coordinate']
|
| 84 |
-
print(f"{box['cls_id']:.0f}\t{box['score']:.3f}"
|
| 85 |
-
f"\t{xmin:.2f}\t{ymin:.2f}\t{xmax:.2f}\t{ymax:.2f}")
|
| 86 |
|
| 87 |
if __name__ == '__main__':
|
| 88 |
run_doclayout_onnx()
|
|
|
|
| 64 |
input_names[1]: input_blob,
|
| 65 |
input_names[2]: [[scale_h, scale_w]]}
|
| 66 |
|
| 67 |
+
# shape=(300, 7), Values are [label_index, score, xmin, ymin, xmax, ymax, read_order]
|
| 68 |
output = model.run(output_names, input_feed)[0]
|
| 69 |
|
| 70 |
# Filter out low-confidence boxes
|
| 71 |
boxes = output[output[:, 1] > 0.5]
|
| 72 |
print('--- DocLayoutV3 ONNX Output: ---')
|
| 73 |
+
# Sort by reading order
|
| 74 |
+
print_doclayout_res(boxes[np.argsort(boxes[:, 6])])
|
| 75 |
|
| 76 |
|
| 77 |
def print_doclayout_res(boxes):
|
| 78 |
+
print('cls_id\tscore\txmin\tymin\txmax\tymax\tread_order')
|
| 79 |
+
for box in boxes:
|
| 80 |
+
print(f"{box[0]:.0f}\t\t{box[1]:.3f}\t{box[2]:.2f}\t{box[3]:.2f}\t{box[4]:.2f}\t{box[5]:.2f}\t{box[6]:.0f}")
|
| 81 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
if __name__ == '__main__':
|
| 84 |
run_doclayout_onnx()
|