Prechádzať zdrojové kódy

Fix labelme2coco.py to parse with pycocotools

Keys: id, segmentation
Kentaro Wada 6 rokov pred
rodič
commit
c1b1543e86

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 0 - 0
examples/instance_segmentation/data_dataset_coco/annotations.json


+ 13 - 6
examples/instance_segmentation/labelme2coco.py

@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 #!/usr/bin/env python
 
 
 import argparse
 import argparse
+import collections
 import datetime
 import datetime
 import glob
 import glob
 import json
 import json
@@ -107,7 +108,8 @@ def main():
             id=image_id,
             id=image_id,
         ))
         ))
 
 
-        masks = {}
+        masks = {}                                     # for area
+        segmentations = collections.defaultdict(list)  # for segmentation
         for shape in label_data['shapes']:
         for shape in label_data['shapes']:
             points = shape['points']
             points = shape['points']
             label = shape['label']
             label = shape['label']
@@ -116,22 +118,27 @@ def main():
                 img.shape[:2], points, shape_type
                 img.shape[:2], points, shape_type
             )
             )
 
 
-            mask = np.asfortranarray(mask.astype(np.uint8))
             if label in masks:
             if label in masks:
                 masks[label] = masks[label] | mask
                 masks[label] = masks[label] | mask
             else:
             else:
                 masks[label] = mask
                 masks[label] = mask
 
 
+            points = np.asarray(points).flatten().tolist()
+            segmentations[label].append(points)
+
         for label, mask in masks.items():
         for label, mask in masks.items():
             cls_name = label.split('-')[0]
             cls_name = label.split('-')[0]
             if cls_name not in class_name_to_id:
             if cls_name not in class_name_to_id:
                 continue
                 continue
             cls_id = class_name_to_id[cls_name]
             cls_id = class_name_to_id[cls_name]
-            segmentation = pycocotools.mask.encode(mask)
-            segmentation['counts'] = segmentation['counts'].decode()
-            area = float(pycocotools.mask.area(segmentation))
+
+            mask = np.asfortranarray(mask.astype(np.uint8))
+            mask = pycocotools.mask.encode(mask)
+            area = float(pycocotools.mask.area(mask))
+
             data['annotations'].append(dict(
             data['annotations'].append(dict(
-                segmentation=segmentation,
+                id=len(data['annotations']),
+                segmentation=segmentations[label],
                 area=area,
                 area=area,
                 iscrowd=None,
                 iscrowd=None,
                 image_id=image_id,
                 image_id=image_id,

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov