提交 02c8e574 编写于 作者: S sunyanfang01

add comment

上级 8590cb53
...@@ -55,22 +55,28 @@ class X2COCO(object): ...@@ -55,22 +55,28 @@ class X2COCO(object):
annotation["id"] = object_id + 1 annotation["id"] = object_id + 1
return annotation return annotation
def convert(self, image_input_dir, json_input_dir, dataset_save_dir): def convert(self, image_dir, json_dir, dataset_save_dir):
assert osp.exists(image_input_dir), "he image folder does not exist!" """转换。
assert osp.exists(json_input_dir), "The json folder does not exist!" Args:
image_dir (str): 图像文件存放的路径。
json_dir (str): 与每张图像对应的json文件的存放路径。
dataset_save_dir (str): 转换后数据集存放路径。
"""
assert osp.exists(image_dir), "he image folder does not exist!"
assert osp.exists(json_dir), "The json folder does not exist!"
assert osp.exists(dataset_save_dir), "The save folder does not exist!" assert osp.exists(dataset_save_dir), "The save folder does not exist!"
# Convert the image files. # Convert the image files.
new_image_dir = osp.join(dataset_save_dir, "JPEGImages") new_image_dir = osp.join(dataset_save_dir, "JPEGImages")
if osp.exists(new_image_dir): if osp.exists(new_image_dir):
shutil.rmtree(new_image_dir) shutil.rmtree(new_image_dir)
os.makedirs(new_image_dir) os.makedirs(new_image_dir)
for img_name in os.listdir(image_input_dir): for img_name in os.listdir(image_dir):
if is_pic(img_name): if is_pic(img_name):
shutil.copyfile( shutil.copyfile(
osp.join(image_input_dir, img_name), osp.join(image_dir, img_name),
osp.join(new_image_dir, img_name)) osp.join(new_image_dir, img_name))
# Convert the json files. # Convert the json files.
self.analyse_json(new_image_dir, json_input_dir) self.parse_json(new_image_dir, json_dir)
coco_data = {} coco_data = {}
coco_data["images"] = self.images_list coco_data["images"] = self.images_list
coco_data["categories"] = self.categories_list coco_data["categories"] = self.categories_list
...@@ -84,6 +90,8 @@ class X2COCO(object): ...@@ -84,6 +90,8 @@ class X2COCO(object):
class LabelMe2COCO(X2COCO): class LabelMe2COCO(X2COCO):
"""将使用LabelMe标注的数据集转换为COCO数据集。
"""
def __init__(self): def __init__(self):
super(LabelMe2COCO, self).__init__() super(LabelMe2COCO, self).__init__()
...@@ -127,7 +135,7 @@ class LabelMe2COCO(X2COCO): ...@@ -127,7 +135,7 @@ class LabelMe2COCO(X2COCO):
right_bottom_r - left_top_r right_bottom_r - left_top_r
] ]
def analyse_json(self, img_dir, json_dir): def parse_json(self, img_dir, json_dir):
image_id = -1 image_id = -1
object_id = -1 object_id = -1
labels_list = [] labels_list = []
...@@ -168,6 +176,8 @@ class LabelMe2COCO(X2COCO): ...@@ -168,6 +176,8 @@ class LabelMe2COCO(X2COCO):
class EasyData2COCO(X2COCO): class EasyData2COCO(X2COCO):
"""将使用EasyData标注的检测或分割数据集转换为COCO数据集。
"""
def __init__(self): def __init__(self):
super(EasyData2COCO, self).__init__() super(EasyData2COCO, self).__init__()
...@@ -196,7 +206,7 @@ class EasyData2COCO(X2COCO): ...@@ -196,7 +206,7 @@ class EasyData2COCO(X2COCO):
annotation["id"] = object_id + 1 annotation["id"] = object_id + 1
return annotation return annotation
def analyse_json(self, img_dir, json_dir): def parse_json(self, img_dir, json_dir):
from pycocotools.mask import decode from pycocotools.mask import decode
image_id = -1 image_id = -1
object_id = -1 object_id = -1
......
...@@ -23,10 +23,18 @@ import numpy as np ...@@ -23,10 +23,18 @@ import numpy as np
from .base import MyEncoder, is_pic, get_encoding from .base import MyEncoder, is_pic, get_encoding
class EasyData2ImageNet(object): class EasyData2ImageNet(object):
"""将使用EasyData标注的分类数据集转换为COCO数据集。
"""
def __init__(self): def __init__(self):
pass pass
def convert(self, image_dir, json_dir, dataset_save_dir): def convert(self, image_dir, json_dir, dataset_save_dir):
"""转换。
Args:
image_dir (str): 图像文件存放的路径。
json_dir (str): 与每张图像对应的json文件的存放路径。
dataset_save_dir (str): 转换后数据集存放路径。
"""
assert osp.exists(image_dir), "The image folder does not exist!" assert osp.exists(image_dir), "The image folder does not exist!"
assert osp.exists(json_dir), "The json folder does not exist!" assert osp.exists(json_dir), "The json folder does not exist!"
assert osp.exists(dataset_save_dir), "The save folder does not exist!" assert osp.exists(dataset_save_dir), "The save folder does not exist!"
......
...@@ -29,6 +29,7 @@ class X2Seg(object): ...@@ -29,6 +29,7 @@ class X2Seg(object):
self.labels2ids = {'_background_': 0} self.labels2ids = {'_background_': 0}
def shapes_to_label(self, img_shape, shapes, label_name_to_value): def shapes_to_label(self, img_shape, shapes, label_name_to_value):
# This function is based on https://github.com/wkentaro/labelme/blob/master/labelme/utils/shape.py.
def shape_to_mask(img_shape, points, shape_type=None, def shape_to_mask(img_shape, points, shape_type=None,
line_width=10, point_size=5): line_width=10, point_size=5):
mask = np.zeros(img_shape[:2], dtype=np.uint8) mask = np.zeros(img_shape[:2], dtype=np.uint8)
...@@ -102,6 +103,12 @@ class X2Seg(object): ...@@ -102,6 +103,12 @@ class X2Seg(object):
return color_map return color_map
def convert(self, image_dir, json_dir, dataset_save_dir): def convert(self, image_dir, json_dir, dataset_save_dir):
"""转换。
Args:
image_dir (str): 图像文件存放的路径。
json_dir (str): 与每张图像对应的json文件的存放路径。
dataset_save_dir (str): 转换后数据集存放路径。
"""
assert osp.exists(image_dir), "The image folder does not exist!" assert osp.exists(image_dir), "The image folder does not exist!"
assert osp.exists(json_dir), "The json folder does not exist!" assert osp.exists(json_dir), "The json folder does not exist!"
assert osp.exists(dataset_save_dir), "The save folder does not exist!" assert osp.exists(dataset_save_dir), "The save folder does not exist!"
...@@ -130,6 +137,8 @@ class X2Seg(object): ...@@ -130,6 +137,8 @@ class X2Seg(object):
class JingLing2Seg(X2Seg): class JingLing2Seg(X2Seg):
"""将使用标注精灵标注的数据集转换为Seg数据集。
"""
def __init__(self): def __init__(self):
super(JingLing2Seg, self).__init__() super(JingLing2Seg, self).__init__()
...@@ -198,6 +207,8 @@ class JingLing2Seg(X2Seg): ...@@ -198,6 +207,8 @@ class JingLing2Seg(X2Seg):
class LabelMe2Seg(X2Seg): class LabelMe2Seg(X2Seg):
"""将使用LabelMe标注的数据集转换为Seg数据集。
"""
def __init__(self): def __init__(self):
super(LabelMe2Seg, self).__init__() super(LabelMe2Seg, self).__init__()
...@@ -246,6 +257,8 @@ class LabelMe2Seg(X2Seg): ...@@ -246,6 +257,8 @@ class LabelMe2Seg(X2Seg):
class EasyData2Seg(X2Seg): class EasyData2Seg(X2Seg):
"""将使用EasyData标注的分割数据集转换为Seg数据集。
"""
def __init__(self): def __init__(self):
super(EasyData2Seg, self).__init__() super(EasyData2Seg, self).__init__()
......
...@@ -27,6 +27,12 @@ class X2VOC(object): ...@@ -27,6 +27,12 @@ class X2VOC(object):
pass pass
def convert(self, image_dir, json_dir, dataset_save_dir): def convert(self, image_dir, json_dir, dataset_save_dir):
"""转换。
Args:
image_dir (str): 图像文件存放的路径。
json_dir (str): 与每张图像对应的json文件的存放路径。
dataset_save_dir (str): 转换后数据集存放路径。
"""
assert osp.exists(image_dir), "The image folder does not exist!" assert osp.exists(image_dir), "The image folder does not exist!"
assert osp.exists(json_dir), "The json folder does not exist!" assert osp.exists(json_dir), "The json folder does not exist!"
assert osp.exists(dataset_save_dir), "The save folder does not exist!" assert osp.exists(dataset_save_dir), "The save folder does not exist!"
...@@ -49,6 +55,8 @@ class X2VOC(object): ...@@ -49,6 +55,8 @@ class X2VOC(object):
class LabelMe2VOC(X2VOC): class LabelMe2VOC(X2VOC):
"""将使用LabelMe标注的数据集转换为VOC数据集。
"""
def __init__(self): def __init__(self):
pass pass
...@@ -119,6 +127,8 @@ class LabelMe2VOC(X2VOC): ...@@ -119,6 +127,8 @@ class LabelMe2VOC(X2VOC):
class EasyData2VOC(X2VOC): class EasyData2VOC(X2VOC):
"""将使用EasyData标注的分割数据集转换为VOC数据集。
"""
def __init__(self): def __init__(self):
pass pass
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册