Przeglądaj źródła

category_id in detection prediction results starts from 0 and is continous

will-jl944 4 lat temu
rodzic
commit
12f7ba98d7

+ 5 - 4
dygraph/paddlex/cv/models/detector.py

@@ -455,10 +455,11 @@ class BaseDetector(BaseModel):
             If img_file is a string or np.array, the result is a list of dict with key-value pairs:
             {"category_id": `category_id`, "category": `category`, "bbox": `[x, y, w, h]`, "score": `score`}.
             If img_file is a list, the result is a list composed of dicts with the corresponding fields:
-            category_id(int): the predicted category ID
+            category_id(int): the predicted category ID. 0 represents the first category in the dataset, and so on.
             category(str): category name
             bbox(list): bounding box in [x, y, w, h] format
             score(str): confidence
+            mask(dict): Only for instance segmentation task. Mask of the object in RLE format
 
         """
         if transforms is None and not hasattr(self, 'test_transforms'):
@@ -512,7 +513,7 @@ class BaseDetector(BaseModel):
                     h = ymax - ymin
                     bbox = [xmin, ymin, w, h]
                     dt_res = {
-                        'category_id': int(num_id) + 1,
+                        'category_id': int(num_id),
                         'category': category,
                         'bbox': bbox,
                         'score': score
@@ -544,9 +545,9 @@ class BaseDetector(BaseModel):
                         if 'counts' in rle:
                             rle['counts'] = rle['counts'].decode("utf8")
                     sg_res = {
-                        'category_id': int(label) + 1,
+                        'category_id': int(label),
                         'category': category,
-                        'segmentation': rle,
+                        'mask': rle,
                         'score': score
                     }
                     seg_res.append(sg_res)

+ 2 - 2
dygraph/paddlex/cv/models/utils/visualize.py

@@ -252,8 +252,8 @@ def draw_bbox_mask(image, results, threshold=0.5, color_map=None):
                 linestyle="-", ))
 
         # draw mask
-        if 'segmentation' in dt:
-            mask = mask_util.decode(dt['segmentation'])
+        if 'mask' in dt:
+            mask = mask_util.decode(dt['mask'])
             mask = np.ascontiguousarray(mask)
             res = cv2.findContours(
                 mask.astype("uint8"), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)

+ 4 - 4
dygraph/paddlex/cv/transforms/operators.py

@@ -915,9 +915,9 @@ class Padding(Transform):
                  offsets=None,
                  im_padding_value=(127.5, 127.5, 127.5),
                  label_padding_value=255,
-                 coarsest_stride=32):
+                 size_divisor=32):
         """
-        Pad image to a specified size or multiple of coarsest_stride.
+        Pad image to a specified size or multiple of size_divisor.
 
         Args:
             target_size(int, Sequence, optional): Image target size, if None, pad to multiple of size_divisor. Defaults to None.
@@ -925,7 +925,7 @@ class Padding(Transform):
                 if 0, only pad to right and bottom. If 1, pad according to center. If 2, only pad left and top. Defaults to 0.
             im_padding_value(Sequence[float]): RGB value of pad area. Defaults to (127.5, 127.5, 127.5).
             label_padding_value(int, optional): Filling value for the mask. Defaults to 255.
-            coarsest_stride(int): Image width and height after padding is a multiple of coarsest_stride.
+            size_divisor(int): Image width and height after padding is a multiple of coarsest_stride.
         """
         super(Padding, self).__init__()
         if isinstance(target_size, (list, tuple)):
@@ -943,7 +943,7 @@ class Padding(Transform):
             assert offsets, 'if pad_mode is -1, offsets should not be None'
 
         self.target_size = target_size
-        self.coarsest_stride = coarsest_stride
+        self.coarsest_stride = size_divisor
         self.pad_mode = pad_mode
         self.offsets = offsets
         self.im_padding_value = im_padding_value