PaddleSeg icon indicating copy to clipboard operation
PaddleSeg copied to clipboard

eiseg的语义分割标注文件,如何转换为coco数据集标注文件,或者是PASCALVOC2012,标注文件?转labelme也行

Open ouyang11111 opened this issue 3 years ago • 5 comments

ouyang11111 avatar Oct 22 '21 03:10 ouyang11111

eiseg0.3以上版本支持coco类型的标注格式,欢迎体验

haoyuying avatar Oct 22 '21 06:10 haoyuying

eiseg0.3以上版本支持coco类型的标注格式,欢迎体验

这个保存的 COCO 格式在 PADDLEX 和 PaddleDetection 下训练都报错了,请问下是什么情况啊?

[10/23 17:12:10] ppdet.data.source.coco WARNING: Found an invalid bbox in annotations: im_id: 346, area: 0.0 x1: 664.0, y1: 690.0, x2: 853.0, y2: 908.0.
Traceback (most recent call last):
  File "tools/train.py", line 138, in <module>
    main()
  File "tools/train.py", line 134, in main
    run(FLAGS, cfg)
  File "tools/train.py", line 100, in run
    trainer = Trainer(cfg, mode='train')
  File "/opt/deeplearning/PaddleDetection/ppdet/engine/trainer.py", line 74, in __init__
    self.loader = create('{}Reader'.format(self.mode.capitalize()))(
  File "/opt/deeplearning/PaddleDetection/ppdet/data/reader.py", line 163, in __call__
    self.dataset.parse_dataset()
  File "/opt/deeplearning/PaddleDetection/ppdet/data/source/coco.py", line 243, in parse_dataset
    assert ct > 0, 'not found any coco record in %s' % (anno_path)
AssertionError: not found any coco record in dataset/splotch_coco/train.json

chenglong-do avatar Oct 23 '21 09:10 chenglong-do

请问您解决这个问题了吗?我这也报这个错误。

Wang-Zhenxing avatar Mar 11 '22 10:03 Wang-Zhenxing

一样的问题,有官方解答一下嘛

stepstep123 avatar Jun 07 '22 09:06 stepstep123

I have solved,the code below : import cv2 import json import os

path 为eiseg的json标注文件 save_file为保存待转labelme的标注文件 image_file 标注数据的对应图片文件

path = "./eiseg_annotation/" # avoid os miss match linux / win
save_file = "./labelme_annotation/"

file = 'DJI_20211209173323_0012_Z150.json'

image_file = "images" file_list = os.listdir(path)

print(file_list)

for file in file_list: filename = os.path.join(path, file)

image_name = file[:-4] + "jpg"
jpg = cv2.imread(image_file + "/" + image_name)
# print(jpg.shape)  # H , W ,3

with open(filename, 'r', encoding='utf-8') as file1:
    # print(type(filename))  # str
    data = json.load(file1)
    box_num = len(data)  # 分割块个数
    value2 = []
    for i in range(box_num):
# 取 第 0个 分割块
        for key ,value in data[i].items():   #data[0].values()   items():  .keys()
            # print(key)
            # print(value)
            if key == 'name':
                label_name = value
            if key == 'points':
                points = value

        #for key 5,6
        dict2 = [{'label': label_name, 'points': points, 'group_id': None, 'shape_type': 'polygon', 'flags': {}}]
        key0 = 'version'
        value0 = '4.0.0'
        key1 = "flags"
        value1 = {}
        key2 = "shapes"
        # value2 = [dict2]  # need to add too much here
        key3 = 'imagePath'
        value3 = image_name  # img name
        key4 = 'imageData'
        value4 = None
        key5 = 'imageHeight'
        value5 = jpg.shape[0]
        key6 = 'imageWidth'
        value6 = jpg.shape[1]
        value2 = value2+dict2  # need to add too much here
final_dict = {key0:value0,key1:value1,key2:value2,key3:value3,key4:value4,key5:value5,key6:value6}
# print(final_dict)

with open(save_file+file,'w',encoding='utf-8') as json_file:
    # print(json_file)
    json.dump(final_dict,json_file,ensure_ascii=False)

ouyang11111 avatar Jul 04 '22 06:07 ouyang11111

I have solved,the code below : import cv2 import json import os

path 为eiseg的json标注文件 save_file为保存待转labelme的标注文件 image_file 标注数据的对应图片文件

path = "./eiseg_annotation/" # avoid os miss match linux / win save_file = "./labelme_annotation/"

file = 'DJI_20211209173323_0012_Z150.json'

image_file = "images" file_list = os.listdir(path)

print(file_list)

for file in file_list: filename = os.path.join(path, file)

image_name = file[:-4] + "jpg"
jpg = cv2.imread(image_file + "/" + image_name)
# print(jpg.shape)  # H , W ,3

with open(filename, 'r', encoding='utf-8') as file1:
    # print(type(filename))  # str
    data = json.load(file1)
    box_num = len(data)  # 分割块个数
    value2 = []
    for i in range(box_num):
# 取 第 0个 分割块
        for key ,value in data[i].items():   #data[0].values()   items():  .keys()
            # print(key)
            # print(value)
            if key == 'name':
                label_name = value
            if key == 'points':
                points = value

        #for key 5,6
        dict2 = [{'label': label_name, 'points': points, 'group_id': None, 'shape_type': 'polygon', 'flags': {}}]
        key0 = 'version'
        value0 = '4.0.0'
        key1 = "flags"
        value1 = {}
        key2 = "shapes"
        # value2 = [dict2]  # need to add too much here
        key3 = 'imagePath'
        value3 = image_name  # img name
        key4 = 'imageData'
        value4 = None
        key5 = 'imageHeight'
        value5 = jpg.shape[0]
        key6 = 'imageWidth'
        value6 = jpg.shape[1]
        value2 = value2+dict2  # need to add too much here
final_dict = {key0:value0,key1:value1,key2:value2,key3:value3,key4:value4,key5:value5,key6:value6}
# print(final_dict)

with open(save_file+file,'w',encoding='utf-8') as json_file:
    # print(json_file)
    json.dump(final_dict,json_file,ensure_ascii=False)

hi,can you succeed?

duduzai2019 avatar Oct 17 '22 06:10 duduzai2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Dec 16 '22 17:12 github-actions[bot]