Browse Source

rm input img for attr rec (#2887)

zhangyubo0722 10 months ago
parent
commit
21947014e0

+ 1 - 1
api_examples/pipelines/test_pedestrian_attribute_rec.py

@@ -17,7 +17,7 @@ from paddlex import create_pipeline
 pipeline = create_pipeline(pipeline="pedestrian_attribute_recognition")
 
 output = pipeline.predict(
-    "./test_samples/pedestrian_attribute_002.jpg", det_threshold=0.7, cls_threshold=0.7
+    "./test_samples/pedestrian_attribute_002.jpg", det_threshold=0.5, cls_threshold=0.7
 )
 
 for res in output:

+ 1 - 1
api_examples/pipelines/test_vehicle_attribute_rec.py

@@ -17,7 +17,7 @@ from paddlex import create_pipeline
 pipeline = create_pipeline(pipeline="vehicle_attribute_recognition")
 
 output = pipeline.predict(
-    "./test_samples/vehicle_attribute_002.jpg", det_threshold=0.7, cls_threshold=0.7
+    "./test_samples/vehicle_attribute_002.jpg", det_threshold=0.5, cls_threshold=0.7
 )
 
 for res in output:

+ 1 - 1
paddlex/configs/pipelines/pedestrian_attribute_recognition.yaml

@@ -12,4 +12,4 @@ SubModules:
     model_name: PP-LCNet_x1_0_pedestrian_attribute
     model_dir: null
     batch_size: 1
-    threshold: 0.5
+    threshold: 0.7

+ 1 - 1
paddlex/configs/pipelines/vehicle_attribute_recognition.yaml

@@ -12,4 +12,4 @@ SubModules:
     model_name: PP-LCNet_x1_0_vehicle_attribute
     model_dir: null
     batch_size: 1
-    threshold: 0.5
+    threshold: 0.7

+ 3 - 3
paddlex/inference/pipelines_new/attribute_recognition/pipeline.py

@@ -43,7 +43,7 @@ class AttributeRecPipeline(BasePipeline):
         self._crop_by_boxes = CropByBoxes()
         self._img_reader = ReadImage(format="BGR")
 
-        self.det_threshold = config["SubModules"]["Detection"].get("threshold", 0.7)
+        self.det_threshold = config["SubModules"]["Detection"].get("threshold", 0.5)
         self.cls_threshold = config["SubModules"]["Classification"].get(
             "threshold", 0.7
         )
@@ -76,12 +76,12 @@ class AttributeRecPipeline(BasePipeline):
     def get_final_result(self, input_data, raw_img, det_res, rec_res):
         single_img_res = {"input_path": input_data, "input_img": raw_img, "boxes": []}
         for i, obj in enumerate(det_res["boxes"]):
-            rec_scores = rec_res["score"][i]
+            cls_scores = rec_res["score"][i]
             labels = rec_res["label"][i]
             single_img_res["boxes"].append(
                 {
                     "labels": labels,
-                    "rec_scores": rec_scores,
+                    "cls_scores": cls_scores,
                     "det_score": obj["score"],
                     "coordinate": obj["coordinate"],
                 }

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

@@ -14,13 +14,14 @@
 
 import os
 import cv2
+import copy
 import numpy as np
 import PIL
 from PIL import Image, ImageDraw, ImageFont
 
 from ....utils.fonts import PINGFANG_FONT_FILE_PATH
 from ...utils.io import ImageReader
-from ...common.result import BaseCVResult
+from ...common.result import BaseCVResult, StrMixin, JsonMixin
 from ...utils.color_map import get_colormap, font_colormap
 
 
@@ -74,6 +75,16 @@ def draw_attribute_result(img, boxes):
 
 class AttributeRecResult(BaseCVResult):
 
+    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)
+
     def _to_img(self):
         """apply"""
         img_reader = ImageReader(backend="pillow")