当前位置: 首页>>代码示例>>Python>>正文


Python json_tricks.load方法代码示例

本文整理汇总了Python中json_tricks.load方法的典型用法代码示例。如果您正苦于以下问题:Python json_tricks.load方法的具体用法?Python json_tricks.load怎么用?Python json_tricks.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在json_tricks的用法示例。


在下文中一共展示了json_tricks.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_pickle

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def load_pickle(file, encoding=None):
    """Load a pickle file.

    Args:
        file (str): Path to pickle file

    Returns:
        object: Loaded object from pickle file

    """
    # TODO: test set encoding='latin1' for 2/3 incompatibility
    if encoding:
        with open(file, 'rb') as f:
            return pickle.load(f, encoding=encoding)

    with open(file, 'rb') as f:
       return pickle.load(f) 
开发者ID:SBRG,项目名称:ssbio,代码行数:19,代码来源:__init__.py

示例2: _write_coco_keypoint_results

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def _write_coco_keypoint_results(self, keypoints, res_file):
        data_pack = [
            {
                'cat_id': 1,  # 1 == 'person'
                'cls': 'person',
                'ann_type': 'keypoints',
                'keypoints': keypoints
            }
        ]

        results = self._coco_keypoint_results_one_category_kernel(data_pack[0])
        with open(res_file, 'w') as f:
            json.dump(results, f, sort_keys=True, indent=4)
        try:
            json.load(open(res_file))
        except Exception:
            content = []
            with open(res_file, 'r') as f:
                for line in f:
                    content.append(line)
            content[-1] = ']'
            with open(res_file, 'w') as f:
                for c in content:
                    f.write(c) 
开发者ID:stefanopini,项目名称:simple-HRNet,代码行数:26,代码来源:COCO.py

示例3: _write_coco_keypoint_results

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def _write_coco_keypoint_results(self, keypoints, res_file):
        data_pack = [{'cat_id': self._class_to_coco_ind[cls],
                      'cls_ind': cls_ind,
                      'cls': cls,
                      'ann_type': 'keypoints',
                      'keypoints': keypoints
                      }
                     for cls_ind, cls in enumerate(self.classes) if not cls == '__background__']

        results = self._coco_keypoint_results_one_category_kernel(data_pack[0])
        logger.info('=> Writing results json to %s' % res_file)
        with open(res_file, 'w') as f:
            json.dump(results, f, sort_keys=True, indent=4)
        try:
            json.load(open(res_file))
        except Exception:
            content = []
            with open(res_file, 'r') as f:
                for line in f:
                    content.append(line)
            content[-1] = ']'
            with open(res_file, 'w') as f:
                for c in content:
                    f.write(c) 
开发者ID:Naman-ntc,项目名称:Pytorch-Human-Pose-Estimation,代码行数:26,代码来源:coco.py

示例4: open_model

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def open_model(file_name):
    """ open a file and populate an optical model with the data

    Args:
        file_name (str): a filename of a supported file type

            - .roa - a rayoptics JSON encoded file
            - .seq - a CODE V (TM) sequence file

    Returns:
        if successful, an OpticalModel instance, otherwise, None
    """
    file_extension = os.path.splitext(file_name)[1]
    opm = None
    if file_extension == '.seq':
        opm = cvp.read_lens(file_name)
        create_specsheet_from_model(opm)
    elif file_extension == '.roa':
        with open(file_name, 'r') as f:
            obj_dict = json_tricks.load(f)
            if 'optical_model' in obj_dict:
                opm = obj_dict['optical_model']
                opm.sync_to_restore()
    return opm 
开发者ID:mjhoptics,项目名称:ray-optics,代码行数:26,代码来源:appcmds.py

示例5: __init__

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def __init__(self, cfg, root, image_set, is_train, transform=None):
        super().__init__(cfg, root, image_set, is_train, transform)

        self.num_joints = 16
        self.flip_pairs = [[0, 5], [1, 4], [2, 3], [10, 15], [11, 14], [12, 13]]
        self.parent_ids = [1, 2, 6, 6, 3, 4, 6, 6, 7, 8, 11, 12, 7, 7, 13, 14]

        self.upper_body_ids = (7, 8, 9, 10, 11, 12, 13, 14, 15)
        self.lower_body_ids = (0, 1, 2, 3, 4, 5, 6)

        self.db = self._get_db()

        if is_train and cfg.DATASET.SELECT_DATA:
            self.db = self.select_data(self.db)

        logger.info('=> load {} samples'.format(len(self.db))) 
开发者ID:lxy5513,项目名称:cvToolkit,代码行数:18,代码来源:mpii.py

示例6: _write_coco_keypoint_results

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def _write_coco_keypoint_results(self, keypoints, res_file):
        data_pack = [
            {
                'cat_id': self._class_to_coco_ind[cls],
                'cls_ind': cls_ind,
                'cls': cls,
                'ann_type': 'keypoints',
                'keypoints': keypoints
            }
            for cls_ind, cls in enumerate(self.classes) if not cls == '__background__'
        ]

        results = self._coco_keypoint_results_one_category_kernel(data_pack[0])
        logger.info('=> writing results json to %s' % res_file)
        with open(res_file, 'w') as f:
            json.dump(results, f, sort_keys=True, indent=4)
        try:
            json.load(open(res_file))
        except Exception:
            content = []
            with open(res_file, 'r') as f:
                for line in f:
                    content.append(line)
            content[-1] = ']'
            with open(res_file, 'w') as f:
                for c in content:
                    f.write(c) 
开发者ID:facebookresearch,项目名称:PoseWarper,代码行数:29,代码来源:posetrack.py

示例7: load_json

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def load_json(file, new_root_dir=None, decompression=False):
    """Load a JSON file using json_tricks"""
    if decompression:
        with open(file, 'rb') as f:
            my_object = load(f, decompression=decompression)
    else:
        with open(file, 'r') as f:
            my_object = load(f, decompression=decompression)
    if new_root_dir:
        my_object.root_dir = new_root_dir

    return my_object 
开发者ID:SBRG,项目名称:ssbio,代码行数:14,代码来源:__init__.py

示例8: _write_coco_keypoint_results

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def _write_coco_keypoint_results(self, keypoints, res_file):
        data_pack = [
            {
                'cat_id': self._class_to_coco_ind[cls],
                'cls_ind': cls_ind,
                'cls': cls,
                'ann_type': 'keypoints',
                'keypoints': keypoints
            }
            for cls_ind, cls in enumerate(self.classes) if not cls == '__background__'
        ]

        results = self._coco_keypoint_results_one_category_kernel(data_pack[0])
        logger.info('=> Writing results json to %s' % res_file)
        with open(res_file, 'w') as f:
            json.dump(results, f, sort_keys=True, indent=4)
        try:
            json.load(open(res_file))
        except Exception:
            content = []
            with open(res_file, 'r') as f:
                for line in f:
                    content.append(line)
            content[-1] = ']'
            with open(res_file, 'w') as f:
                for c in content:
                    f.write(c) 
开发者ID:HRNet,项目名称:HigherHRNet-Human-Pose-Estimation,代码行数:29,代码来源:COCODataset.py

示例9: __init__

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def __init__(self, cfg, root, image_set, is_train, transform=None):
        super().__init__(cfg, root, image_set, is_train, transform)

        self.num_joints = 16
        self.flip_pairs = [[0, 5], [1, 4], [2, 3], [10, 15], [11, 14], [12, 13]]
        self.parent_ids = [1, 2, 6, 6, 3, 4, 6, 6, 7, 8, 11, 12, 7, 7, 13, 14]

        self.db = self._get_db()

        if is_train and cfg.DATASET.SELECT_DATA:
            self.db = self.select_data(self.db)

        logger.info('=> load {} samples'.format(len(self.db))) 
开发者ID:lxy5513,项目名称:cvToolkit,代码行数:15,代码来源:mpii.py

示例10: video2filenames

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def video2filenames(annot_dir):
    pathtodir = annot_dir


    mat_files = [f for f in os.listdir(pathtodir) if
             osp.isfile(osp.join(pathtodir, f)) and '.mat' in f]
    json_files = [f for f in os.listdir(pathtodir) if
             osp.isfile(osp.join(pathtodir, f)) and '.json' in f]

    if len(json_files) > 1:
        files = json_files
        ext_types = '.json'
    else:
        files = mat_files
        ext_types = '.mat'


    output = {}
    L = {}
    files = [f for f in os.listdir(pathtodir) if
             osp.isfile(osp.join(pathtodir, f)) and ext_types in f]
    for fname in files:
        if ext_types == '.mat':
            out_fname = fname.replace('.mat', '.json')
            data = sio.loadmat(
                osp.join(pathtodir, fname), squeeze_me=True,
                struct_as_record=False)
            temp = data['annolist'][0].image.name


            data2 = sio.loadmat(osp.join(pathtodir, fname))
            num_frames = len(data2['annolist'][0])
        elif ext_types == '.json':
            out_fname = fname
            with open(osp.join(pathtodir, fname), 'r') as fin:
                data = json.load(fin)

            if 'annolist' in data:
              temp = data['annolist'][0]['image'][0]['name']
              num_frames = len(data['annolist'])
            else:
              temp = data['images'][0]['file_name']
              num_frames = data['images'][0]['nframes']

        else:
            raise NotImplementedError()
        video = osp.dirname(temp)
        output[video] = out_fname
        L[video] = num_frames
    return output, L 
开发者ID:facebookresearch,项目名称:PoseWarper,代码行数:52,代码来源:posetrack.py

示例11: _load_posetrack_person_detection_results

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def _load_posetrack_person_detection_results(self):
        all_boxes = None
        with open(self.bbox_file, 'r') as f:
            all_boxes = json.load(f)

        if not all_boxes:
            logger.error('=> Load %s fail!' % self.bbox_file)
            return None

        logger.info('=> Total boxes: {}'.format(len(all_boxes)))

        kpt_db = []
        num_boxes = 0
        for n_img in range(0, len(all_boxes)):
            det_res = all_boxes[n_img]
            if det_res['category_id'] != 1:
                continue
            #img_name = self.image_path_from_index(det_res['image_id'])
            img_name = det_res['image_name']
            box = det_res['bbox']
            score = det_res['score']
            nframes = det_res['nframes']
            frame_id = det_res['frame_id']

            if score < self.image_thre:
                continue

            num_boxes = num_boxes + 1

            center, scale = self._box2cs(box)
            joints_3d = np.zeros((self.num_joints, 3), dtype=np.float)
            joints_3d_vis = np.ones(
                (self.num_joints, 3), dtype=np.float)
            kpt_db.append({
                'image': self.img_dir + img_name,
                'center': center,
                'scale': scale,
                'score': score,
                'joints_3d': joints_3d,
                'joints_3d_vis': joints_3d_vis,
                'nframes': nframes,
                'frame_id': frame_id,
            })

        logger.info('=> Total boxes after fliter low score@{}: {}'.format(
            self.image_thre, num_boxes))
        return kpt_db 
开发者ID:facebookresearch,项目名称:PoseWarper,代码行数:49,代码来源:posetrack.py

示例12: video2filenames

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def video2filenames(annot_dir):
    pathtodir = annot_dir


    output = {}
    L = {}
    mat_files = [f for f in os.listdir(pathtodir) if
             osp.isfile(osp.join(pathtodir, f)) and '.mat' in f]
    json_files = [f for f in os.listdir(pathtodir) if
             osp.isfile(osp.join(pathtodir, f)) and '.json' in f]

    if len(json_files) > 1:
        files = json_files
        ext_types = '.json'
    else:
        files = mat_files
        ext_types = '.mat'

    for fname in files:
        if ext_types == '.mat':
            out_fname = fname.replace('.mat', '.json')
            data = sio.loadmat(
                osp.join(pathtodir, fname), squeeze_me=True,
                struct_as_record=False)
            temp = data['annolist'][0].image.name


            data2 = sio.loadmat(osp.join(pathtodir, fname))
            num_frames = len(data2['annolist'][0])
        elif ext_types == '.json':
            out_fname = fname
            with open(osp.join(pathtodir, fname), 'r') as fin:
                data = json.load(fin)

            if 'annolist' in data:
              temp = data['annolist'][0]['image'][0]['name']
              num_frames = len(data['annolist'])
            else:
              temp = data['images'][0]['file_name']
              num_frames = data['images'][0]['nframes']


        else:
            raise NotImplementedError()
        video = osp.dirname(temp)
        output[video] = out_fname
        L[video] = num_frames
    return output, L 
开发者ID:facebookresearch,项目名称:PoseWarper,代码行数:50,代码来源:posetrack_PoseAgg.py

示例13: _load_posetrack_person_detection_results

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def _load_posetrack_person_detection_results(self):
        all_boxes = None
        with open(self.bbox_file, 'r') as f:
            all_boxes = json.load(f)

        if not all_boxes:
            logger.error('=> Load %s fail!' % self.bbox_file)
            return None

        logger.info('=> Total boxes: {}'.format(len(all_boxes)))

        kpt_db = []
        num_boxes = 0
        for n_img in range(0, len(all_boxes)):
            det_res = all_boxes[n_img]
            if det_res['category_id'] != 1:
                continue
            img_name = det_res['image_name']
            box = det_res['bbox']
            score = det_res['score']
            nframes = det_res['nframes']
            frame_id = det_res['frame_id']

            if score < self.image_thre:
                continue

            num_boxes = num_boxes + 1

            center, scale = self._box2cs(box)
            joints_3d = np.zeros((self.num_joints, 3), dtype=np.float)
            joints_3d_vis = np.ones(
                (self.num_joints, 3), dtype=np.float)
            kpt_db.append({
                'image': self.img_dir + img_name,
                'center': center,
                'scale': scale,
                'score': score,
                'joints_3d': joints_3d,
                'joints_3d_vis': joints_3d_vis,
                'nframes': nframes,
                'frame_id': frame_id,
            })

        logger.info('=> Total boxes after fliter low score@{}: {}'.format(
            self.image_thre, num_boxes))
        return kpt_db 
开发者ID:facebookresearch,项目名称:PoseWarper,代码行数:48,代码来源:posetrack_PoseAgg.py

示例14: __init__

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def __init__(self, opts, root, image_set, is_train, transform=None):
        super().__init__(opts, root, image_set, is_train, transform)
        self.nms_thre = 1.0#cfg.TEST.NMS_THRE
        self.image_thre = 0.0#cfg.TEST.IMAGE_THRE
        self.oks_thre = 0.9#cfg.TEST.OKS_THRE
        self.in_vis_thre = 0.2#cfg.TEST.IN_VIS_THRE
        self.bbox_file = opts.dataDir + '/person_detection_resuts/COCO_val2017_detections_AP_H_56_person.json'#cfg.TEST.COCO_BBOX_FILE
        self.use_gt_bbox = True#cfg.TEST.USE_GT_BBOX
        self.image_width = 256#cfg.MODEL.IMAGE_SIZE[0]
        self.image_height = 256#cfg.MODEL.IMAGE_SIZE[1]
        self.aspect_ratio = self.image_width * 1.0 / self.image_height
        self.pixel_std = 200
        self.coco = COCO(self._get_ann_file_keypoint())

        # deal with class names
        cats = [cat['name']
                for cat in self.coco.loadCats(self.coco.getCatIds())]
        self.classes = ['__background__'] + cats
        logger.info('=> classes: {}'.format(self.classes))
        self.num_classes = len(self.classes)
        self._class_to_ind = dict(zip(self.classes, range(self.num_classes)))
        self._class_to_coco_ind = dict(zip(cats, self.coco.getCatIds()))
        self._coco_ind_to_class_ind = dict([(self._class_to_coco_ind[cls],
                                             self._class_to_ind[cls])
                                            for cls in self.classes[1:]])

        # load image file names
        self.image_set_index = self._load_image_set_index()
        self.num_images = len(self.image_set_index)
        logger.info('=> num_images: {}'.format(self.num_images))

        self.num_joints = 17
        self.flip_pairs = [[1, 2], [3, 4], [5, 6], [7, 8],
                           [9, 10], [11, 12], [13, 14], [15, 16]]
        self.parent_ids = None

        self.db = self._get_db()

        if is_train and None:#cfg.DATASET.SELECT_DATA:
            self.db = self.select_data(self.db)

        logger.info('=> load {} samples'.format(len(self.db))) 
开发者ID:Naman-ntc,项目名称:Pytorch-Human-Pose-Estimation,代码行数:44,代码来源:coco.py

示例15: _load_coco_person_detection_results

# 需要导入模块: import json_tricks [as 别名]
# 或者: from json_tricks import load [as 别名]
def _load_coco_person_detection_results(self):
        all_boxes = None
        with open(self.bbox_file, 'r') as f:
            all_boxes = json.load(f)

        if not all_boxes:
            logger.error('=> Load %s fail!' % self.bbox_file)
            return None

        logger.info('=> Total boxes: {}'.format(len(all_boxes)))

        kpt_db = []
        num_boxes = 0
        for n_img in range(0, len(all_boxes)):
            det_res = all_boxes[n_img]
            if det_res['category_id'] != 1:
                continue
            img_name = self.image_path_from_index(det_res['image_id'])
            box = det_res['bbox']
            score = det_res['score']

            if score < self.image_thre:
                continue

            num_boxes = num_boxes + 1

            center, scale = self._box2cs(box)
            joints_3d = np.zeros((self.num_joints, 3), dtype=np.float)
            joints_3d_vis = np.ones(
                (self.num_joints, 3), dtype=np.float)
            kpt_db.append({
                'image': img_name,
                'center': center,
                'scale': scale,
                'score': score,
                'joints_3d': joints_3d,
                'joints_3d_vis': joints_3d_vis,
            })

        logger.info('=> Total boxes after fliter low score@{}: {}'.format(
            self.image_thre, num_boxes))
        return kpt_db

    # need double check this API and classes field 
开发者ID:Naman-ntc,项目名称:Pytorch-Human-Pose-Estimation,代码行数:46,代码来源:coco.py


注:本文中的json_tricks.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。