當前位置: 首頁>>代碼示例>>Python>>正文


Python dataset_catalog.DATASETS屬性代碼示例

本文整理匯總了Python中datasets.dataset_catalog.DATASETS屬性的典型用法代碼示例。如果您正苦於以下問題:Python dataset_catalog.DATASETS屬性的具體用法?Python dataset_catalog.DATASETS怎麽用?Python dataset_catalog.DATASETS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在datasets.dataset_catalog的用法示例。


在下文中一共展示了dataset_catalog.DATASETS屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: voc_info

# 需要導入模塊: from datasets import dataset_catalog [as 別名]
# 或者: from datasets.dataset_catalog import DATASETS [as 別名]
def voc_info(json_dataset):
    year = json_dataset.name[4:8]
    image_set = json_dataset.name[9:]
    devkit_path = DATASETS[json_dataset.name][DEVKIT_DIR]
    assert os.path.exists(devkit_path), \
        'Devkit directory {} not found'.format(devkit_path)
    anno_path = os.path.join(
        devkit_path, 'VOC' + year, 'Annotations', '{:s}.xml')
    image_set_path = os.path.join(
        devkit_path, 'VOC' + year, 'ImageSets', 'Main', image_set + '.txt')
    return dict(
        year=year,
        image_set=image_set,
        devkit_path=devkit_path,
        anno_path=anno_path,
        image_set_path=image_set_path) 
開發者ID:roytseng-tw,項目名稱:Detectron.pytorch,代碼行數:18,代碼來源:voc_dataset_evaluator.py

示例2: convert

# 需要導入模塊: from datasets import dataset_catalog [as 別名]
# 或者: from datasets.dataset_catalog import DATASETS [as 別名]
def convert(json_file, output_dir):
    print('Reading: {}'.format(json_file))
    with open(json_file, 'r') as fid:
        dt = json.load(fid)
    print('done!')

    test_image_info = DATASETS['coco_2017_test'][ANN_FN]
    with open(test_image_info, 'r') as fid:
        info_test = json.load(fid)
    image_test = info_test['images']
    image_test_id = [i['id'] for i in image_test]
    print('{} has {} images'.format(test_image_info, len(image_test_id)))

    test_dev_image_info = DATASETS['coco_2017_test-dev'][ANN_FN]
    with open(test_dev_image_info, 'r') as fid:
        info_testdev = json.load(fid)
    image_testdev = info_testdev['images']
    image_testdev_id = [i['id'] for i in image_testdev]
    print('{} has {} images'.format(test_dev_image_info, len(image_testdev_id)))

    dt_testdev = []
    print('Filtering test-dev from test...')
    t = Timer()
    t.tic()
    for i in range(len(dt)):
        if i % 1000 == 0:
            print('{}/{}'.format(i, len(dt)))
        if dt[i]['image_id'] in image_testdev_id:
            dt_testdev.append(dt[i])
    print('Done filtering ({:2}s)!'.format(t.toc()))

    filename, file_extension = os.path.splitext(os.path.basename(json_file))
    filename = filename + '_test-dev'
    filename = os.path.join(output_dir, filename + file_extension)
    with open(filename, 'w') as fid:
        info_test = json.dump(dt_testdev, fid)
    print('Done writing: {}!'.format(filename)) 
開發者ID:ronghanghu,項目名稱:seg_every_thing,代碼行數:39,代碼來源:generate_testdev_from_test.py

示例3: evaluate_masks

# 需要導入模塊: from datasets import dataset_catalog [as 別名]
# 或者: from datasets.dataset_catalog import DATASETS [as 別名]
def evaluate_masks(
    json_dataset,
    all_boxes,
    all_segms,
    output_dir,
    use_salt=True,
    cleanup=False
):
    if cfg.CLUSTER.ON_CLUSTER:
        # On the cluster avoid saving these files in the job directory
        output_dir = '/tmp'
    res_file = os.path.join(
        output_dir, 'segmentations_' + json_dataset.name + '_results')
    if use_salt:
        res_file += '_{}'.format(str(uuid.uuid4()))
    res_file += '.json'

    results_dir = os.path.join(output_dir, 'results')
    if not os.path.exists(results_dir):
        os.mkdir(results_dir)

    os.environ['CITYSCAPES_DATASET'] = DATASETS[json_dataset.name][RAW_DIR]
    os.environ['CITYSCAPES_RESULTS'] = output_dir

    # Load the Cityscapes eval script *after* setting the required env vars,
    # since the script reads their values into global variables (at load time).
    import cityscapesscripts.evaluation.evalInstanceLevelSemanticLabeling \
        as cityscapes_eval

    roidb = json_dataset.get_roidb()
    for i, entry in enumerate(roidb):
        im_name = entry['image']

        basename = os.path.splitext(os.path.basename(im_name))[0]
        txtname = os.path.join(output_dir, basename + 'pred.txt')
        with open(txtname, 'w') as fid_txt:
            if i % 10 == 0:
                logger.info('i: {}: {}'.format(i, basename))
            for j in range(1, len(all_segms)):
                clss = json_dataset.classes[j]
                clss_id = cityscapes_eval.name2label[clss].id
                segms = all_segms[j][i]
                boxes = all_boxes[j][i]
                if segms == []:
                    continue
                masks = mask_util.decode(segms)

                for k in range(boxes.shape[0]):
                    score = boxes[k, -1]
                    mask = masks[:, :, k]
                    pngname = os.path.join(
                        'results',
                        basename + '_' + clss + '_{}.png'.format(k))
                    # write txt
                    fid_txt.write('{} {} {}\n'.format(pngname, clss_id, score))
                    # save mask
                    cv2.imwrite(os.path.join(output_dir, pngname), mask * 255)
    logger.info('Evaluating...')
    cityscapes_eval.main([])
    return None 
開發者ID:roytseng-tw,項目名稱:Detectron.pytorch,代碼行數:62,代碼來源:cityscapes_json_dataset_evaluator.py

示例4: eval_json

# 需要導入模塊: from datasets import dataset_catalog [as 別名]
# 或者: from datasets.dataset_catalog import DATASETS [as 別名]
def eval_json(det_json,gt_json):
    json_dataset = JsonDataset(gt_dataset_name)
    gt_json = dataset_catalog.DATASETS[gt_dataset_name]['annotation_file']
    with open(det_json,'rb') as f:
        det = json.load(f)
    f.close()
    with open(gt_json,'rb') as f:
        gt = json.load(f)
    f.close()

    # convert det to the all_boxes list
    num_images = len(gt['images'])
    num_classes = 2
    print('Total number of images:',len(det['images']))
    all_boxes, all_segms, all_keyps = empty_results(num_classes,num_images)
    for cls in range(num_classes):
        for image in range(num_images):
            filename = gt['images'][image]['file_name']
            fid = gt['images'][image]['id']
            img_prop = get_by_filename(det,filename)
            if not (img_prop is None):
                img_id,det_prop = img_prop
                boxes = get_boxes_by_img_id(det,img_id)
                if image%100 == 0:
                    print('Reading detections for:',filename,'--',det_prop['file_name'])
                    print('Det json:',det_json)
                if 'score' in boxes[0]:
                    boxes = np.array([b['bbox']+[b['score']] for b in boxes])
                else:
                    boxes = np.array([b['bbox'] for b in boxes])
                if len(boxes) > 0:
                    # add w, h to get (x2,y2)
                    boxes[:,2] += boxes[:,0]
                    boxes[:,3] += boxes[:,1]
                    all_boxes[cls][image] = boxes
            else:
                all_boxes[cls][image] = []
    # save detections
    with open(os.path.join(output_dir,'detections.pkl'),'wb') as f:
        pickle.dump(dict(all_boxes=all_boxes,all_segms=all_segms,all_keyps=all_keyps),f)
    f.close()
    #input(len(all_boxes[0]))
    coco_eval = evaluate_boxes(json_dataset,all_boxes,output_dir)
    #coco_eval = task_evaluation.evaluate_all(json_dataset,all_boxes,all_segms,all_keyps,output_dir)

    disp_detection_eval_metrics(json_dataset, coco_eval, iou_low=0.5, iou_high=0.5, output_dir=output_dir)
    disp_detection_eval_metrics(json_dataset, coco_eval, iou_low=0.75, iou_high=0.75, output_dir=output_dir)
    disp_detection_eval_metrics(json_dataset, coco_eval, iou_low=0.5, iou_high=0.95, output_dir=output_dir) 
開發者ID:AruniRC,項目名稱:detectron-self-train,代碼行數:50,代碼來源:evaluate_json.py


注:本文中的datasets.dataset_catalog.DATASETS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。