瀏覽代碼

[Feat] Support result visualization for time-series pipeline apps and rename layout_parsing_v2 (#3543)

* Fix serving apps

* Convert to RGB

* Fix schema

* Rename layout_parsing_v2 to pp_structurev3

* Update doc
Lin Manhui 8 月之前
父節點
當前提交
59cbdf916a

+ 2 - 2
docs/pipeline_deploy/serving.en.md

@@ -207,8 +207,8 @@ Find the high-stability serving SDK corresponding to the pipeline in the table b
 <td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hps/public/sdks/v3.0.0rc0/paddlex_hps_layout_parsing_sdk.tar.gz">paddlex_hps_layout_parsing_sdk.tar.gz</a></td>
 </tr>
 <tr>
-<td>General layout parsing v2</td>
-<td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hps/public/sdks/v3.0.0rc0/paddlex_hps_layout_parsing_v2_sdk.tar.gz">paddlex_hps_layout_parsing_v2_sdk.tar.gz</a></td>
+<td>PP-StructureV3</td>
+<td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hps/public/sdks/v3.0.0rc0/paddlex_hps_PP-StructureV3_sdk.tar.gz">paddlex_hps_PP-StructureV3_sdk.tar.gz</a></td>
 </tr>
 <tr>
 <td>Formula recognition</td>

+ 2 - 2
docs/pipeline_deploy/serving.md

@@ -207,8 +207,8 @@ paddlex --serve --pipeline image_classification --use_hpip
 <td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hps/public/sdks/v3.0.0rc0/paddlex_hps_layout_parsing_sdk.tar.gz">paddlex_hps_layout_parsing_sdk.tar.gz</a></td>
 </tr>
 <tr>
-<td>通用版面解析 v2</td>
-<td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hps/public/sdks/v3.0.0rc0/paddlex_hps_layout_parsing_v2_sdk.tar.gz">paddlex_hps_layout_parsing_v2_sdk.tar.gz</a></td>
+<td>通用版面解析 v3</td>
+<td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hps/public/sdks/v3.0.0rc0/paddlex_hps_PP-StructureV3_sdk.tar.gz">paddlex_hps_PP-StructureV3_sdk.tar.gz</a></td>
 </tr>
 <tr>
 <td>公式识别</td>

+ 1 - 1
paddlex/inference/serving/basic_serving/_pipeline_apps/layout_parsing_v2.py → paddlex/inference/serving/basic_serving/_pipeline_apps/pp_structurev3.py

@@ -19,7 +19,7 @@ from fastapi import FastAPI
 from ...infra import utils as serving_utils
 from ...infra.config import AppConfig
 from ...infra.models import ResultResponse
-from ...schemas.layout_parsing_v2 import INFER_ENDPOINT, InferRequest, InferResult
+from ...schemas.pp_structurev3 import INFER_ENDPOINT, InferRequest, InferResult
 from .._app import create_app, primary_operation
 from ._common import common
 from ._common import ocr as ocr_common

+ 7 - 1
paddlex/inference/serving/basic_serving/_pipeline_apps/ts_anomaly_detection.py

@@ -47,10 +47,16 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> FastAPI:
         output_csv = serving_utils.base64_encode(
             serving_utils.data_frame_to_bytes(result["anomaly"])
         )
+        if ctx.config.visualize:
+            output_image = serving_utils.base64_encode(
+                serving_utils.image_to_bytes(result.img["res"].convert("RGB"))
+            )
+        else:
+            output_image = None
 
         return ResultResponse[InferResult](
             logId=serving_utils.generate_log_id(),
-            result=InferResult(csv=output_csv),
+            result=InferResult(csv=output_csv, image=output_image),
         )
 
     return app

+ 7 - 1
paddlex/inference/serving/basic_serving/_pipeline_apps/ts_classification.py

@@ -46,10 +46,16 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> FastAPI:
 
         label = str(result["classification"].at[0, "classid"])
         score = float(result["classification"].at[0, "score"])
+        if ctx.config.visualize:
+            output_image = serving_utils.base64_encode(
+                serving_utils.image_to_bytes(result.img["res"].convert("RGB"))
+            )
+        else:
+            output_image = None
 
         return ResultResponse[InferResult](
             logId=serving_utils.generate_log_id(),
-            result=InferResult(label=label, score=score),
+            result=InferResult(label=label, score=score, image=output_image),
         )
 
     return app

+ 7 - 1
paddlex/inference/serving/basic_serving/_pipeline_apps/ts_forecast.py

@@ -47,10 +47,16 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> FastAPI:
         output_csv = serving_utils.base64_encode(
             serving_utils.data_frame_to_bytes(result["forecast"])
         )
+        if ctx.config.visualize:
+            output_image = serving_utils.base64_encode(
+                serving_utils.image_to_bytes(result.img["res"].convert("RGB"))
+            )
+        else:
+            output_image = None
 
         return ResultResponse[InferResult](
             logId=serving_utils.generate_log_id(),
-            result=InferResult(csv=output_csv),
+            result=InferResult(csv=output_csv, image=output_image),
         )
 
     return app

+ 0 - 0
paddlex/inference/serving/schemas/layout_parsing_v2.py → paddlex/inference/serving/schemas/pp_structurev3.py


+ 2 - 1
paddlex/inference/serving/schemas/ts_anomaly_detection.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Final
+from typing import Final, Optional
 
 from pydantic import BaseModel
 
@@ -29,6 +29,7 @@ class InferRequest(BaseModel):
 
 class InferResult(BaseModel):
     csv: str
+    image: Optional[str] = None
 
 
 PRIMARY_OPERATIONS: Final[PrimaryOperations] = {

+ 2 - 1
paddlex/inference/serving/schemas/ts_classification.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Final
+from typing import Final, Optional
 
 from pydantic import BaseModel
 
@@ -30,6 +30,7 @@ class InferRequest(BaseModel):
 class InferResult(BaseModel):
     label: str
     score: float
+    image: Optional[str] = None
 
 
 PRIMARY_OPERATIONS: Final[PrimaryOperations] = {

+ 2 - 1
paddlex/inference/serving/schemas/ts_forecast.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Final
+from typing import Final, Optional
 
 from pydantic import BaseModel
 
@@ -29,6 +29,7 @@ class InferRequest(BaseModel):
 
 class InferResult(BaseModel):
     csv: str
+    image: Optional[str] = None
 
 
 PRIMARY_OPERATIONS: Final[PrimaryOperations] = {