diff --git a/docs/data/annotation.md b/docs/data/annotation.md index 0220ca8ec765635d31a2f7f93d12ce3cb8c9bc5e..0aa9ad95d9682f352f7865dd0def456a0c5d96a1 100755 --- a/docs/data/annotation.md +++ b/docs/data/annotation.md @@ -36,4 +36,6 @@ paddlex --data_conversion --source labelme --to PascalVOC --pics ./pics --annota | --pics | 指定原图所在的目录路径 | | --annotations | 指定标注文件所在的目录路径 | -**注意**:精灵标注的目标检测数据可以在工具内部导出为PascalVOC格式,因此paddlex未提供精灵标注数据到PascalVOC格式的转换 +**注意**: +1. 精灵标注的目标检测数据可以在工具内部导出为PascalVOC格式,因此paddlex未提供精灵标注数据到PascalVOC格式的转换 +2. 在将LabelMe数据集转换为COCO数据集时,LabelMe的图像文件名和json文件名需要一一对应,才可正确转换 diff --git a/paddlex/tools/x2coco.py b/paddlex/tools/x2coco.py index a90716084cccccd748e64effbd6a0cc92bccb0fa..b99d5d8226551d972a811e61819f319a36b359a9 100644 --- a/paddlex/tools/x2coco.py +++ b/paddlex/tools/x2coco.py @@ -96,12 +96,13 @@ class LabelMe2COCO(X2COCO): def __init__(self): super(LabelMe2COCO, self).__init__() - def generate_images_field(self, json_info, image_id): + def generate_images_field(self, json_info, image_file, image_id): image = {} image["height"] = json_info["imageHeight"] image["width"] = json_info["imageWidth"] image["id"] = image_id + 1 - json_info["imagePath"] = path_normalization(json_info["imagePath"]) + json_img_path = path_normalization(json_info["imagePath"]) + json_info["imagePath"] = osp.join(osp.split(json_img_path)[0], image_file) image["file_name"] = osp.split(json_info["imagePath"])[-1] return image @@ -152,7 +153,7 @@ class LabelMe2COCO(X2COCO): with open(json_file, mode='r', \ encoding=get_encoding(json_file)) as j: json_info = json.load(j) - img_info = self.generate_images_field(json_info, image_id) + img_info = self.generate_images_field(json_info, img_file, image_id) self.images_list.append(img_info) for shapes in json_info["shapes"]: object_id = object_id + 1 @@ -360,6 +361,4 @@ class JingLing2COCO(X2COCO): points.append([obj["bndbox"]["xmax"], obj["bndbox"]["ymin"]]) self.annotations_list.append( self.generate_rectangle_anns_field(points, label, image_id, - object_id, label_to_num)) - - \ No newline at end of file + object_id, label_to_num)) \ No newline at end of file