src/DOTA_devkit/DOTA2JSON.py
def generate_json_labels(src_path, out_path, trainval=True):
    """Generate .json labels which is similar to coco format
    Args:
        src_path: dataset path containing images and labelTxt folders.
        out_path: output json file path
        trainval: trainval or test?
    """
    img_path = os.path.join(src_path, 'images')
    label_path = os.path.join(src_path, 'labelTxt')
    img_lists = os.listdir(img_path)

    data_dict = []

    with open(out_path, 'w') as f:
        for id, img in enumerate(img_lists):
            img_info = {}
            img_name = osp.splitext(img)[0]
            label = os.path.join(label_path, img_name+'.txt')
            img = Image.open(osp.join(img_path, img))
            img_info['filename'] = img_name+'.png'
            img_info['height'] = img.height
            img_info['width'] = img.width
            img_info['id'] = id
            if(trainval == True):
                if(os.path.exists(label) == False):
                    print('Label:'+img_name+'.txt'+' Not Exist')
                else:
                    bboxes, labels, bboxes_ignore, labels_ignore = parse_ann_info(
                        img_path, label_path, img_name)
                    ann = {}
                    ann['bboxes'] = bboxes
                    ann['labels'] = labels
                    ann['bboxes_ignore'] = bboxes_ignore
                    ann['labels_ignore'] = labels_ignore
                    img_info['annotations'] = ann
            data_dict.append(img_info)
        json.dump(data_dict, f)
Generate .json labels which is similar to coco format
    Args:
        src_path: dataset path containing images and labelTxt folders.
        out_path: output json file path
        trainval: trainval or test?
    
Generate .json labels which is similar to coco format
Generate . json labels which is similar to coco format
def generate_json_labels(src_path, out_path, trainval=True):
    img_path = os.path.join(src_path, 'images')
    label_path = os.path.join(src_path, 'labelTxt')
    img_lists = os.listdir(img_path)
    data_dict = []
    with open(out_path, 'w') as f:
        for id, img in enumerate(img_lists):
            img_info = {}
            img_name = osp.splitext(img)[0]
            label = os.path.join(label_path, img_name+'.txt')
            img = Image.open(osp.join(img_path, img))
            img_info['filename'] = img_name+'.png'
            img_info['height'] = img.height
            img_info['width'] = img.width
            img_info['id'] = id
            if(trainval == True):
                if(os.path.exists(label) == False):
                    print('Label:'+img_name+'.txt'+' Not Exist')
                else:
                    bboxes, labels, bboxes_ignore, labels_ignore = parse_ann_info(
                        img_path, label_path, img_name)
                    ann = {}
                    ann['bboxes'] = bboxes
                    ann['labels'] = labels
                    ann['bboxes_ignore'] = bboxes_ignore
                    ann['labels_ignore'] = labels_ignore
                    img_info['annotations'] = ann
            data_dict.append(img_info)
        json.dump(data_dict, f)
def generate_json_labels ( src_path , out_path , trainval = True ) : img_path = os . path . join ( src_path , 'images' ) label_path = os . path . join ( src_path , 'labelTxt' ) img_lists = os . listdir ( img_path ) data_dict = [ ] with open ( out_path , 'w' ) as f : for id , img in enumerate ( img_lists ) : img_info = { } img_name = osp . splitext ( img ) [ 0 ] label = os . path . join ( label_path , img_name + '.txt' ) img = Image . open ( osp . join ( img_path , img ) ) img_info [ 'filename' ] = img_name + '.png' img_info [ 'height' ] = img . height img_info [ 'width' ] = img . width img_info [ 'id' ] = id if ( trainval == True ) : if ( os . path . exists ( label ) == False ) : print ( 'Label:' + img_name + '.txt' + ' Not Exist' ) else : bboxes , labels , bboxes_ignore , labels_ignore = parse_ann_info ( img_path , label_path , img_name ) ann = { } ann [ 'bboxes' ] = bboxes ann [ 'labels' ] = labels ann [ 'bboxes_ignore' ] = bboxes_ignore ann [ 'labels_ignore' ] = labels_ignore img_info [ 'annotations' ] = ann data_dict . append ( img_info ) json . dump ( data_dict , f )
Generate .json labels which is similar to coco format
Generate . json labels which is similar to coco format
"""Generate .json labels which is similar to coco format
    Args:
        src_path: dataset path containing images and labelTxt folders.
        out_path: output json file path
        trainval: trainval or test?
    """
src_path
dataset path containing images and labelTxt folders.
dataset path containing images and labelTxt folders .
out_path
output json file path
output json file path
trainval
None