Эх сурвалжийг харах

pop 'input_img' for face and kpt result (#2886)

学卿 10 сар өмнө
parent
commit
e354b24b22

+ 12 - 1
paddlex/inference/models_new/keypoint_detection/result.py

@@ -13,12 +13,13 @@
 # limitations under the License.
 
 import cv2
+import copy
 import math
 
 import matplotlib.pyplot as plt
 import numpy as np
 
-from ...common.result import BaseCVResult
+from ...common.result import BaseCVResult, StrMixin, JsonMixin
 
 
 def get_color(idx):
@@ -175,3 +176,13 @@ class KptResult(BaseCVResult):
             ]  # for top-down pipeline result
         image = draw_keypoints(self["input_img"], dict(keypoints=np.stack(keypoints)))
         return {"res": image}
+
+    def _to_str(self, *args, **kwargs):
+        data = copy.deepcopy(self)
+        data.pop("input_img")
+        return StrMixin._to_str(data, *args, **kwargs)
+
+    def _to_json(self, *args, **kwargs):
+        data = copy.deepcopy(self)
+        data.pop("input_img")
+        return JsonMixin._to_json(data, *args, **kwargs)

+ 12 - 1
paddlex/inference/pipelines_new/face_recognition/result.py

@@ -12,7 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from ...common.result import BaseCVResult
+import copy
+from ...common.result import BaseCVResult, JsonMixin, StrMixin
 from ..pp_shitu_v2.result import draw_box
 
 
@@ -30,3 +31,13 @@ class FaceRecResult(BaseCVResult):
         ]
         image = draw_box(self["input_img"][..., ::-1], boxes)
         return {"res": image}
+
+    def _to_str(self, *args, **kwargs):
+        data = copy.deepcopy(self)
+        data.pop("input_img")
+        return StrMixin._to_str(data, *args, **kwargs)
+
+    def _to_json(self, *args, **kwargs):
+        data = copy.deepcopy(self)
+        data.pop("input_img")
+        return JsonMixin._to_json(data, *args, **kwargs)

+ 14 - 2
paddlex/inference/pipelines_new/pp_shitu_v2/result.py

@@ -12,11 +12,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import copy
+
 import PIL
 from PIL import Image, ImageDraw, ImageFont
 
 from ....utils.fonts import PINGFANG_FONT_FILE_PATH, create_font
-from ...common.result import BaseCVResult
+from ...common.result import BaseCVResult, StrMixin, JsonMixin
 from ...utils.color_map import get_colormap, font_colormap
 
 
@@ -107,4 +109,14 @@ class ShiTuResult(BaseCVResult):
             if box["rec_scores"] is not None
         ]
         image = draw_box(self["input_img"], boxes)
-        return image
+        return {"res": image}
+
+    def _to_str(self, *args, **kwargs):
+        data = copy.deepcopy(self)
+        data.pop("input_img")
+        return StrMixin._to_str(data, *args, **kwargs)
+
+    def _to_json(self, *args, **kwargs):
+        data = copy.deepcopy(self)
+        data.pop("input_img")
+        return JsonMixin._to_json(data, *args, **kwargs)