Skip to content

Commit

Permalink
chore: fix workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Joker1212 committed Oct 19, 2024
1 parent cf89e3e commit d407bde
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 68 deletions.
6 changes: 4 additions & 2 deletions tests/test_table_det.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
from pathlib import Path

import pytest
from rapid_table_det import TableDetector


cur_dir = Path(__file__).resolve().parent
root_dir = cur_dir.parent

sys.path.append(str(root_dir))
test_file_dir = cur_dir / "test_files"
table_det = TableDetector()


@pytest.mark.parametrize(
"img_path, expected",
[("chip.jpg", 1), ("doc.png", 2)],
)
def test_input_normal(img_path, expected):
from rapid_table_det import TableDetector

table_det = TableDetector()
img_path = test_file_dir / img_path
result, elapse = table_det(img_path)
assert len(result) == expected
20 changes: 10 additions & 10 deletions tests/test_table_det_paddle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@

import pytest

from rapid_table_det_paddle.inference import TableDetector

cur_dir = Path(__file__).resolve().parent
root_dir = cur_dir.parent

sys.path.append(str(root_dir))
test_file_dir = cur_dir / "test_files"
table_det = TableDetector(
obj_model_path=f"{root_dir}/rapid_table_det_paddle/models/obj_det_paddle",
edge_model_path=f"{root_dir}/rapid_table_det_paddle/models/edge_det_paddle",
cls_model_path=f"{root_dir}/rapid_table_det_paddle/models/cls_det_paddle",
use_obj_det=True,
use_edge_det=True,
use_cls_det=True,
)


@pytest.mark.parametrize(
"img_path, expected",
[("chip.jpg", 1), ("doc.png", 2)],
)
def test_input_normal(img_path, expected):
from rapid_table_det_paddle.inference import TableDetector

table_det = TableDetector(
obj_model_path=f"{root_dir}/rapid_table_det_paddle/models/obj_det_paddle",
edge_model_path=f"{root_dir}/rapid_table_det_paddle/models/edge_det_paddle",
cls_model_path=f"{root_dir}/rapid_table_det_paddle/models/cls_det_paddle",
use_obj_det=True,
use_edge_det=True,
use_cls_det=True,
)
img_path = test_file_dir / img_path
result, elapse = table_det(img_path)
assert len(result) == expected
117 changes: 61 additions & 56 deletions tools/onnx_transform.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,28 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"start_time": "2024-10-19T12:16:02.498617Z"
},
"collapsed": false,
"jupyter": {
"is_executing": true,
"outputs_hidden": false
},
"pycharm": {
"name": "#%%\n"
},
"ExecuteTime": {
"end_time": "2024-10-19T13:58:51.289307Z",
"start_time": "2024-10-19T13:58:31.510101Z"
}
},
"source": [
"!paddle2onnx --model_dir ../rapid_table_det_paddle/models --model_filename obj_det_paddle.pdmodel --params_filename obj_det_paddle.pdiparams --save_file ../rapid_table_det/models/obj_det.onnx --opset_version 16 --enable_onnx_checker True\n",
"!paddle2onnx --model_dir ../rapid_table_det_paddle/models --model_filename edge_det_paddle.pdmodel --params_filename edge_det_paddle.pdiparams --save_file ../rapid_table_det/models/edge_det.onnx --opset_version 16 --enable_onnx_checker True\n",
"!paddle2onnx --model_dir ../rapid_table_det_paddle/models --model_filename cls_det_paddle.pdmodel --params_filename cls_det_paddle.pdiparams --save_file ../rapid_table_det/models/cls_det.onnx --opset_version 16 --enable_onnx_checker True\n",
"\n",
"!onnxslim ../rapid_table_det/models/obj_det.onnx ../rapid_table_det/models/obj_det.onnx\n",
"!onnxslim ../rapid_table_det/models/edge_det.onnx ../rapid_table_det/models/edge_det.onnx\n",
"!onnxslim ../rapid_table_det/models/cls_det.onnx ../rapid_table_det/models/cls_det.onnx"
],
"outputs": [
{
"name": "stdout",
Expand All @@ -37,24 +45,24 @@
"[Paddle2ONNX] Use opset_version = 16 for ONNX export.\n",
"[WARN][Paddle2ONNX] [multiclass_nms3: multiclass_nms3_0.tmp_1] [WARNING] Due to the operator multiclass_nms3, the exported ONNX model will only supports inference with input batch_size == 1.\n",
"[Paddle2ONNX] PaddlePaddle model is exported as ONNX format now.\n",
"2024-10-19 20:17:46 [INFO]\t===============Make PaddlePaddle Better!================\n",
"2024-10-19 20:17:46 [INFO]\tA little survey: https://iwenjuan.baidu.com/?code=r8hu2s\n",
"2024-10-19 21:58:34 [INFO]\t===============Make PaddlePaddle Better!================\n",
"2024-10-19 21:58:34 [INFO]\tA little survey: https://iwenjuan.baidu.com/?code=r8hu2s\n",
"[Paddle2ONNX] Start to parse PaddlePaddle model...\n",
"[Paddle2ONNX] Model file path: ../rapid_table_det_paddle/models\\edge_det_paddle.pdmodel\n",
"[Paddle2ONNX] Paramters file path: ../rapid_table_det_paddle/models\\edge_det_paddle.pdiparams\n",
"[Paddle2ONNX] Start to parsing Paddle model...\n",
"[Paddle2ONNX] Use opset_version = 16 for ONNX export.\n",
"[Paddle2ONNX] PaddlePaddle model is exported as ONNX format now.\n",
"2024-10-19 20:17:46 [INFO]\t===============Make PaddlePaddle Better!================\n",
"2024-10-19 20:17:46 [INFO]\tA little survey: https://iwenjuan.baidu.com/?code=r8hu2s\n",
"2024-10-19 21:58:35 [INFO]\t===============Make PaddlePaddle Better!================\n",
"2024-10-19 21:58:35 [INFO]\tA little survey: https://iwenjuan.baidu.com/?code=r8hu2s\n",
"[Paddle2ONNX] Start to parse PaddlePaddle model...\n",
"[Paddle2ONNX] Model file path: ../rapid_table_det_paddle/models\\cls_det_paddle.pdmodel\n",
"[Paddle2ONNX] Paramters file path: ../rapid_table_det_paddle/models\\cls_det_paddle.pdiparams\n",
"[Paddle2ONNX] Start to parsing Paddle model...\n",
"[Paddle2ONNX] Use opset_version = 16 for ONNX export.\n",
"[Paddle2ONNX] PaddlePaddle model is exported as ONNX format now.\n",
"2024-10-19 20:17:47 [INFO]\t===============Make PaddlePaddle Better!================\n",
"2024-10-19 20:17:47 [INFO]\tA little survey: https://iwenjuan.baidu.com/?code=r8hu2s\n",
"2024-10-19 21:58:35 [INFO]\t===============Make PaddlePaddle Better!================\n",
"2024-10-19 21:58:35 [INFO]\tA little survey: https://iwenjuan.baidu.com/?code=r8hu2s\n",
"+------------------------------+----------------------------------------+---------------------------------+\n",
"| Model Name | obj_det.onnx | Op Set: 16 |\n",
"+------------------------------+----------------------------------------+---------------------------------+\n",
Expand All @@ -72,21 +80,21 @@
"| OUT: multiclass_nms3_0.tmp_2 | int32: ('p2o.DynamicDimension.3',) | int32: (1,) |\n",
"+------------------------------+----------------------------------------+---------------------------------+\n",
"| Add | 30 | 30 |\n",
"| BatchNormalization | 89 | \u001b[32m0\u001b[37m\u001b[0m |\n",
"| BatchNormalization | 89 | \u001B[32m0\u001B[37m\u001B[0m |\n",
"| Cast | 2 | 2 |\n",
"| Concat | 20 | 20 |\n",
"| Constant | 735 | \u001b[32m0\u001b[37m\u001b[0m |\n",
"| Constant | 735 | \u001B[32m0\u001B[37m\u001B[0m |\n",
"| Conv | 152 | 152 |\n",
"| Div | 1 | 1 |\n",
"| Gather | 7 | 7 |\n",
"| GlobalAveragePool | 3 | 3 |\n",
"| HardSigmoid | 4 | 4 |\n",
"| MaxPool | 3 | 3 |\n",
"| Mul | 279 | \u001b[32m146\u001b[37m\u001b[0m |\n",
"| Mul | 279 | \u001B[32m146\u001B[37m\u001B[0m |\n",
"| NonMaxSuppression | 1 | 1 |\n",
"| ReduceMean | 4 | 4 |\n",
"| ReduceMin | 1 | 1 |\n",
"| Reshape | 12 | \u001b[32m11\u001b[37m\u001b[0m |\n",
"| Reshape | 12 | \u001B[32m11\u001B[37m\u001B[0m |\n",
"| Resize | 2 | 2 |\n",
"| Shape | 2 | 2 |\n",
"| Sigmoid | 142 | 142 |\n",
Expand All @@ -99,7 +107,7 @@
"+------------------------------+----------------------------------------+---------------------------------+\n",
"| Model Size | 371.46 MB | 371.08 MB |\n",
"+------------------------------+----------------------------------------+---------------------------------+\n",
"| Elapsed Time | 8.01 s |\n",
"| Elapsed Time | 9.41 s |\n",
"+------------------------------+----------------------------------------+---------------------------------+\n"
]
},
Expand Down Expand Up @@ -130,9 +138,9 @@
"+-------------------------+----------------------------------------+----------------------------------------+\n",
"| Add | 24 | 24 |\n",
"| AveragePool | 3 | 3 |\n",
"| BatchNormalization | 59 | \u001b[32m2\u001b[37m\u001b[0m |\n",
"| BatchNormalization | 59 | \u001B[32m2\u001B[37m\u001B[0m |\n",
"| Concat | 1 | 1 |\n",
"| Constant | 323 | \u001b[32m0\u001b[37m\u001b[0m |\n",
"| Constant | 323 | \u001B[32m0\u001B[37m\u001B[0m |\n",
"| Conv | 65 | 65 |\n",
"| ConvTranspose | 4 | 4 |\n",
"| Exp | 1 | 1 |\n",
Expand All @@ -146,7 +154,7 @@
"+-------------------------+----------------------------------------+----------------------------------------+\n",
"| Model Size | 97.26 MB | 96.94 MB |\n",
"+-------------------------+----------------------------------------+----------------------------------------+\n",
"| Elapsed Time | 1.68 s |\n",
"| Elapsed Time | 1.88 s |\n",
"+-------------------------+----------------------------------------+----------------------------------------+\n"
]
},
Expand Down Expand Up @@ -174,9 +182,9 @@
"| OUT: linear_1.tmp_1 | float32: ('p2o.DynamicDimension.1', 4) | float32: ('p2o.DynamicDimension.0', 4) |\n",
"+---------------------+----------------------------------------+----------------------------------------+\n",
"| Add | 1 | 1 |\n",
"| BatchNormalization | 27 | \u001b[32m0\u001b[37m\u001b[0m |\n",
"| Concat | 1 | \u001b[32m0\u001b[37m\u001b[0m |\n",
"| Constant | 151 | \u001b[32m0\u001b[37m\u001b[0m |\n",
"| BatchNormalization | 27 | \u001B[32m0\u001B[37m\u001B[0m |\n",
"| Concat | 1 | \u001B[32m0\u001B[37m\u001B[0m |\n",
"| Constant | 151 | \u001B[32m0\u001B[37m\u001B[0m |\n",
"| Conv | 32 | 32 |\n",
"| GlobalAveragePool | 3 | 3 |\n",
"| HardSigmoid | 2 | 2 |\n",
Expand All @@ -185,12 +193,12 @@
"| Mul | 3 | 3 |\n",
"| Relu | 2 | 2 |\n",
"| Reshape | 1 | 1 |\n",
"| Shape | 1 | \u001b[32m0\u001b[37m\u001b[0m |\n",
"| Slice | 1 | \u001b[32m0\u001b[37m\u001b[0m |\n",
"| Shape | 1 | \u001B[32m0\u001B[37m\u001B[0m |\n",
"| Slice | 1 | \u001B[32m0\u001B[37m\u001B[0m |\n",
"+---------------------+----------------------------------------+----------------------------------------+\n",
"| Model Size | 6.46 MB | 6.39 MB |\n",
"+---------------------+----------------------------------------+----------------------------------------+\n",
"| Elapsed Time | 0.21 s |\n",
"| Elapsed Time | 0.23 s |\n",
"+---------------------+----------------------------------------+----------------------------------------+\n"
]
},
Expand All @@ -202,33 +210,23 @@
]
}
],
"source": [
"!paddle2onnx --model_dir ../rapid_table_det_paddle/models --model_filename obj_det_paddle.pdmodel --params_filename obj_det_paddle.pdiparams --save_file ../rapid_table_det/models/obj_det.onnx --opset_version 16 --enable_onnx_checker True\n",
"!paddle2onnx --model_dir ../rapid_table_det_paddle/models --model_filename edge_det_paddle.pdmodel --params_filename edge_det_paddle.pdiparams --save_file ../rapid_table_det/models/edge_det.onnx --opset_version 16 --enable_onnx_checker True\n",
"!paddle2onnx --model_dir ../rapid_table_det_paddle/models --model_filename cls_det_paddle.pdmodel --params_filename cls_det_paddle.pdiparams --save_file ../rapid_table_det/models/cls_det.onnx --opset_version 16 --enable_onnx_checker True\n",
"\n",
"!onnxslim ../rapid_table_det/models/obj_det.onnx ../rapid_table_det/models/obj_det.onnx\n",
"!onnxslim ../rapid_table_det/models/edge_det.onnx ../rapid_table_det/models/edge_det.onnx\n",
"!onnxslim ../rapid_table_det/models/cls_det.onnx ../rapid_table_det/models/cls_det.onnx"
]
"execution_count": 1
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-16T15:11:21.028896Z",
"start_time": "2024-10-16T15:11:20.250683Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"pycharm": {
"name": "#%%\n"
},
"ExecuteTime": {
"end_time": "2024-10-19T13:58:56.174983Z",
"start_time": "2024-10-19T13:58:55.580038Z"
}
},
"outputs": [],
"source": [
"from pathlib import Path\n",
"import onnx\n",
Expand All @@ -252,24 +250,31 @@
" quantized_model = onnx.load(quantized_model_path)\n",
" onnx.checker.check_model(quantized_model)\n",
" print(\"Quantized model is valid.\")"
]
],
"outputs": [],
"execution_count": 2
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-15T14:02:23.904231Z",
"start_time": "2024-10-15T14:02:20.842278Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"pycharm": {
"name": "#%%\n"
},
"ExecuteTime": {
"end_time": "2024-10-19T13:59:14.149803Z",
"start_time": "2024-10-19T13:58:59.542092Z"
}
},
"source": [
"root_dir_str = \"..\"\n",
"model_dir = f\"rapid_table_det/models\"\n",
"quantize_model(root_dir_str, model_dir, \"obj_det\")\n",
"quantize_model(root_dir_str, model_dir, \"edge_det\")"
],
"outputs": [
{
"name": "stdout",
Expand All @@ -280,18 +285,16 @@
]
}
],
"source": [
"root_dir_str = \"..\"\n",
"model_dir = f\"rapid_table_det/models\"\n",
"quantize_model(root_dir_str, model_dir, \"obj_det\")\n",
"quantize_model(root_dir_str, model_dir, \"edge_det\")"
]
"execution_count": 3
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-19T13:59:19.984452Z",
"start_time": "2024-10-19T13:59:18.181521Z"
}
},
"source": [
"from fix_onnx import fix_onnx\n",
"import os\n",
Expand All @@ -302,7 +305,9 @@
"fix_onnx(model_path)\n",
"model_path = os.path.join(model_dir, \"obj_det_quantized.onnx\")\n",
"fix_onnx(model_path)"
]
],
"outputs": [],
"execution_count": 4
},
{
"cell_type": "code",
Expand Down

0 comments on commit d407bde

Please sign in to comment.