|
@@ -7,7 +7,8 @@ import cv2
|
|
import numpy as np
|
|
import numpy as np
|
|
|
|
|
|
import base64
|
|
import base64
|
|
-from core.predictor import LayoutBox, predict_img
|
|
|
|
|
|
+from core.predictor import predict_img
|
|
|
|
+from core.layout import LayoutBox
|
|
from sx_utils import format_print
|
|
from sx_utils import format_print
|
|
|
|
|
|
app = FastAPI()
|
|
app = FastAPI()
|
|
@@ -31,7 +32,6 @@ clazz_names = [
|
|
"style",
|
|
"style",
|
|
"table",
|
|
"table",
|
|
"text",
|
|
"text",
|
|
- "text_jhl",
|
|
|
|
"title",
|
|
"title",
|
|
]
|
|
]
|
|
|
|
|
|
@@ -69,7 +69,9 @@ def drag_and_drop_detect(request: Request):
|
|
def detect_via_web_form(request: Request,
|
|
def detect_via_web_form(request: Request,
|
|
file_list: List[UploadFile] = File(...),
|
|
file_list: List[UploadFile] = File(...),
|
|
model_name: str = Form(...),
|
|
model_name: str = Form(...),
|
|
- img_size: int = Form(1824)):
|
|
|
|
|
|
+ img_size: int = Form(1824),
|
|
|
|
+ multi_scale: bool = Form(False),
|
|
|
|
+ ):
|
|
'''
|
|
'''
|
|
Requires an image file upload, model name (ex. yolov5s). Optional image size parameter (Default 1824).
|
|
Requires an image file upload, model name (ex. yolov5s). Optional image size parameter (Default 1824).
|
|
Intended for human (non-api) users.
|
|
Intended for human (non-api) users.
|
|
@@ -83,7 +85,7 @@ def detect_via_web_form(request: Request,
|
|
# using cvtColor instead of [...,::-1] to keep array contiguous in RAM
|
|
# using cvtColor instead of [...,::-1] to keep array contiguous in RAM
|
|
img_batch_rgb = [cv2.cvtColor(img, cv2.COLOR_BGR2RGB) for img in img_batch]
|
|
img_batch_rgb = [cv2.cvtColor(img, cv2.COLOR_BGR2RGB) for img in img_batch]
|
|
|
|
|
|
- results = [predict_img(img, model_name, img_size) for img in img_batch_rgb]
|
|
|
|
|
|
+ results = [predict_img(img, model_name, img_size, multi_scale) for img in img_batch_rgb]
|
|
|
|
|
|
json_results = boxes_list_to_json(results, clazz_names)
|
|
json_results = boxes_list_to_json(results, clazz_names)
|
|
|
|
|
|
@@ -113,6 +115,7 @@ def detect_via_api(request: Request,
|
|
file_list: List[UploadFile] = File(...),
|
|
file_list: List[UploadFile] = File(...),
|
|
model_name: str = Form(...),
|
|
model_name: str = Form(...),
|
|
img_size: int = Form(1920),
|
|
img_size: int = Form(1920),
|
|
|
|
+ multi_scale: bool = Form(False),
|
|
download_image: Optional[bool] = Form(False)):
|
|
download_image: Optional[bool] = Form(False)):
|
|
'''
|
|
'''
|
|
Requires an image file upload, model name (ex. yolov5s).
|
|
Requires an image file upload, model name (ex. yolov5s).
|
|
@@ -133,7 +136,7 @@ def detect_via_api(request: Request,
|
|
# 转换图片格式
|
|
# 转换图片格式
|
|
img_batch_rgb = [cv2.cvtColor(img, cv2.COLOR_BGR2RGB) for img in img_batch]
|
|
img_batch_rgb = [cv2.cvtColor(img, cv2.COLOR_BGR2RGB) for img in img_batch]
|
|
# 选用相关模型进行模版识别
|
|
# 选用相关模型进行模版识别
|
|
- results = [predict_img(img, model_name, img_size) for img in img_batch_rgb]
|
|
|
|
|
|
+ results = [predict_img(img, model_name, img_size, multi_scale) for img in img_batch_rgb]
|
|
# 处理结果数据
|
|
# 处理结果数据
|
|
json_results = boxes_list_to_json(results, clazz_names)
|
|
json_results = boxes_list_to_json(results, clazz_names)
|
|
|
|
|
|
@@ -212,22 +215,3 @@ def boxes_list_to_json(boxes_list: List[List[LayoutBox]], clazz_names: List[str]
|
|
def ping():
|
|
def ping():
|
|
print("->ping")
|
|
print("->ping")
|
|
return "pong!"
|
|
return "pong!"
|
|
-
|
|
|
|
-
|
|
|
|
-# if __name__ == '__main__':
|
|
|
|
-# import uvicorn
|
|
|
|
-# import argparse
|
|
|
|
-#
|
|
|
|
-# parser = argparse.ArgumentParser()
|
|
|
|
-# parser.add_argument('--host', default='localhost')
|
|
|
|
-# parser.add_argument('--port', default=8080)
|
|
|
|
-# parser.add_argument('--precache-models', action='store_true',
|
|
|
|
-# help='Pre-cache all models in memory upon initialization, otherwise dynamically caches models')
|
|
|
|
-# opt = parser.parse_args()
|
|
|
|
-#
|
|
|
|
-# # if opt.precache_models:
|
|
|
|
-# # model_dict = {model_name: torch.hub.load('ultralytics/yolov5', model_name, pretrained=True)
|
|
|
|
-# # for model_name in model_selection_options}
|
|
|
|
-#
|
|
|
|
-# app_str = 'server:app' # make the app string equal to whatever the name of this file is
|
|
|
|
-# uvicorn.run(app_str, host=opt.host, port=int(opt.port), reload=True)
|
|
|