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


Python recordio.unpack方法代码示例

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


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

示例1: next_sample

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def next_sample(self):
        """Helper function for reading in next sample."""
        #set total batch size, for example, 1800, and maximum size for each people, for example 45
        if self.seq is not None:
          while True:
            if self.cur >= len(self.seq):
                raise StopIteration
            idx = self.seq[self.cur]
            self.cur += 1
            if self.imgrec is not None:
              s = self.imgrec.read_idx(idx)
              header, img = recordio.unpack(s)
              label = header.label
              if not isinstance(label, numbers.Number):
                label = label[0]
              return label, img, None, None
            else:
              label, fname, bbox, landmark = self.imglist[idx]
              return label, self.read_image(fname), bbox, landmark
        else:
            s = self.imgrec.read()
            if s is None:
                raise StopIteration
            header, img = recordio.unpack(s)
            return header.label, img, None, None 
开发者ID:deepinsight,项目名称:insightface,代码行数:27,代码来源:image_iter.py

示例2: next_sample

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def next_sample(self):
      """Helper function for reading in next sample."""
      if self.cur >= len(self.seq):
        raise StopIteration
      idx = self.seq[self.cur]
      self.cur += 1
      s = self.imgrec.read_idx(idx)
      header, img = recordio.unpack(s)
      img = mx.image.imdecode(img).asnumpy()
      hlabel = np.array(header.label).reshape( (self.num_classes,2) )
      if not config.label_xfirst:
        hlabel = hlabel[:,::-1] #convert to X/W first
      annot = {'scale': config.base_scale}

      #ul = np.array( (50000,50000), dtype=np.int32)
      #br = np.array( (0,0), dtype=np.int32)
      #for i in range(hlabel.shape[0]):
      #  h = int(hlabel[i][0])
      #  w = int(hlabel[i][1])
      #  key = np.array((h,w))
      #  ul = np.minimum(key, ul)
      #  br = np.maximum(key, br)

      return img, hlabel, annot 
开发者ID:deepinsight,项目名称:insightface,代码行数:26,代码来源:data.py

示例3: _fork

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def _fork(self):
        if self.use_src:
            self.recs = recordio.MXIndexedRecordIO(self.idx_fs, self.rec_fs, 'r')
            self.idxs = list(self.recs.idx.keys())

        if self.use_tgt:
            self.rect = recordio.MXIndexedRecordIO(self.idx_ft, self.rec_ft, 'r')
            self.idxt = list(self.rect.idx.keys())

            if self.use_src:
                cls_lst = []
                for idx in self.idxt:
                    record = self.rect.read_idx(idx)
                    h, _ = recordio.unpack(record)
                    cls_lst.append(h.label)

                self.idxt_cls = self.generate_cls_dict(cls_lst) 
开发者ID:aws-samples,项目名称:d-SNE,代码行数:19,代码来源:datasets_su.py

示例4: load_or_gen_dict

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def load_or_gen_dict(rec_f, rec):
        cls_idx_dict_f = os.path.splitext(rec_f)[0] + '.json'
        if os.path.exists(cls_idx_dict_f):
            cls_idx_dict = load_json(cls_idx_dict_f)
            return cls_idx_dict
        else:
            idx_cls_lst = []
            for idx in rec.idx.keys():
                record = rec.read_idx(idx)
                h, _ = recordio.unpack(record)
                idx_cls_lst.append([idx, h.label])

            cls_idx_dict = {}
            for idx, y in idx_cls_lst:
                if y in cls_idx_dict:
                    cls_idx_dict[y].append(idx)
                else:
                    cls_idx_dict[y] = [idx]

            save_json(cls_idx_dict, os.path.splitext(rec_f)[0] + '.json')

            return cls_idx_dict 
开发者ID:aws-samples,项目名称:d-SNE,代码行数:24,代码来源:datasets_ss.py

示例5: load_or_gen_list

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def load_or_gen_list(rec_f, rec):
        idx_cls_lst_f = os.path.splitext(rec_f)[0] + '-lst.json'
        if os.path.exists(idx_cls_lst_f):
            idx_cls_lst = load_json(idx_cls_lst_f)
            idx_cls_lst = [int(l) for l in idx_cls_lst]
            return idx_cls_lst
        else:
            idx_cls_lst = []
            for idx in rec.idx.keys():
                record = rec.read_idx(idx)
                h, _ = recordio.unpack(record)
                idx_cls_lst.append(int(h.label))

            save_json(idx_cls_lst, idx_cls_lst_f)

            return idx_cls_lst 
开发者ID:aws-samples,项目名称:d-SNE,代码行数:18,代码来源:datasets_ss.py

示例6: gen_cls_dict

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def gen_cls_dict():
    rec = recordio.MXIndexedRecordIO(os.path.splitext(args.rec)[0] + '.idx', args.rec, 'r')
    cls_lst = []
    pbar = tqdm(total=len(rec.idx.keys()))
    for idx in rec.idx.keys():
        record = rec.read_idx(idx)
        h, _ = recordio.unpack(record)
        cls_lst.append(int(h.label))
        pbar.update()

    pbar.close()

    cls_dict = {}
    for idx, y in enumerate(cls_lst):
        if y in cls_dict:
            cls_dict[y].append(idx)
        else:
            cls_dict[y] = [idx]

    with open(os.path.splitext(args.rec)[0] + '.json', 'w') as f:
        json.dump(cls_dict, f, indent=4, sort_keys=True) 
开发者ID:aws-samples,项目名称:d-SNE,代码行数:23,代码来源:gen_cls_dict_visda.py

示例7: next_sample

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def next_sample(self):
        """Helper function for reading in next sample."""
        # set total batch size, for example, 1800, and maximum size for each people, for example 45
        if self.seq is not None:
            while True:
                if self.cur >= len(self.seq):
                    raise StopIteration
                idx = self.seq[self.cur]
                self.cur += 1
                if self.imgrec is not None:
                    s = self.imgrec.read_idx(idx)
                    header, img = recordio.unpack(s)
                    label = header.label
                    if not isinstance(label, numbers.Number):
                        label = label[0]
                    return label, img, None, None
                else:
                    label, fname, bbox, landmark = self.imglist[idx]
                    return label, self.read_image(fname), bbox, landmark
        else:
            s = self.imgrec.read()
            if s is None:
                raise StopIteration
            header, img = recordio.unpack(s)
            return header.label, img, None, None 
开发者ID:bleakie,项目名称:MaskInsightface,代码行数:27,代码来源:image_iter.py

示例8: __init__

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def __init__(self, filename, gray_scale=False, transform=None, classes=None):
        flag = 0 if gray_scale else 1
        # retrieve number of classes without decoding images
        td = RecordFileDataset(filename)
        s = set([recordio.unpack(td.__getitem__(i))[0].label[0] for i in range(len(td))])
        self._num_classes = len(s)
        if not classes:
            self._classes = [str(i) for i in range(self._num_classes)]
        else:
            if len(self._num_classes) != len(classes):
                warnings.warn('Provided class names do not match data, expected "num_class" is {} '
                              'vs. provided: {}'.format(self._num_classes, len(classes)))
                self._classes = list(classes) + \
                    [str(i) for i in range(len(classes), self._num_classes)]
        self._dataset = ImageRecordDataset(filename, flag=flag)
        if transform:
            self._dataset = self._dataset.transform_first(transform) 
开发者ID:awslabs,项目名称:autogluon,代码行数:19,代码来源:dataset.py

示例9: next_sample

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def next_sample(self):
      while True:
        if self.cur >= len(self.seq):
            raise StopIteration
        idx = self.seq[self.cur]
        self.cur += 1
        s = self.imgrec.read_idx(idx)
        header, img = recordio.unpack(s)
        label = header.label
        if not isinstance(label, numbers.Number):
          label = label[0]
        return label, img, None, None 
开发者ID:deepinsight,项目名称:insightface,代码行数:14,代码来源:triplet_image_iter.py

示例10: __init__

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def __init__(self, batch_size, data_shape,
                 path_imgrec = None,
                 shuffle=False, aug_list=None, mean = None,
                 rand_mirror = False, cutoff = 0, color_jittering = 0,
                 data_name='data', label_name='softmax_label', **kwargs):
        super(FaceImageIter, self).__init__()
        assert path_imgrec
        logging.info('loading recordio %s...',
                     path_imgrec)
        path_imgidx = path_imgrec[0:-4]+".idx"
        self.imgrec = recordio.MXIndexedRecordIO(path_imgidx, path_imgrec, 'r')  # pylint: disable=redefined-variable-type
        s = self.imgrec.read_idx(0)
        header, _ = recordio.unpack(s)
        self.imgidx = list(self.imgrec.keys)
        self.seq = self.imgidx

        self.mean = mean
        self.nd_mean = None
        if self.mean:
          self.mean = np.array(self.mean, dtype=np.float32).reshape(1,1,3)
          self.nd_mean = mx.nd.array(self.mean).reshape((1,1,3))

        self.check_data_shape(data_shape)
        self.provide_data = [(data_name, (batch_size,) + data_shape)]
        self.batch_size = batch_size
        self.data_shape = data_shape
        self.shuffle = shuffle
        self.image_size = '%d,%d'%(data_shape[1],data_shape[2])
        self.rand_mirror = rand_mirror
        print('rand_mirror', rand_mirror)
        self.cutoff = cutoff
        self.color_jittering = color_jittering
        self.CJA = mx.image.ColorJitterAug(0.125, 0.125, 0.125)
        self.provide_label = [(label_name, (batch_size,101))]
        #print(self.provide_label[0][1])
        self.cur = 0
        self.nbatch = 0
        self.is_init = False 
开发者ID:deepinsight,项目名称:insightface,代码行数:40,代码来源:data.py

示例11: next_sample

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def next_sample(self):
        if self.cur >= len(self.seq):
            raise StopIteration
        idx = self.seq[self.cur]
        self.cur += 1
        s = self.imgrec.read_idx(idx)
        header, img = recordio.unpack(s)
        label = header.label
        return label, img, None, None 
开发者ID:deepinsight,项目名称:insightface,代码行数:11,代码来源:data.py

示例12: load_or_gen_dict

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def load_or_gen_dict(rec_f, rec):
        cls_idx_dict_f = os.path.splitext(rec_f)[0] + '.json'
        if os.path.exists(cls_idx_dict_f):
            cls_idx_dict = load_json(cls_idx_dict_f)
            keys = list(cls_idx_dict.keys())
            for k in keys:
                cls_idx_dict[int(float(k))] = cls_idx_dict.pop(k)
            return cls_idx_dict
        else:
            idx_cls_lst = []
            for idx in rec.idx.keys():
                record = rec.read_idx(idx)
                h, _ = recordio.unpack(record)
                idx_cls_lst.append([idx, h.label])

            cls_idx_dict = {}
            for idx, y in idx_cls_lst:
                if y in cls_idx_dict:
                    cls_idx_dict[y].append(idx)
                else:
                    cls_idx_dict[y] = [idx]

            with open(os.path.splitext(rec_f)[0] + '.json', 'w') as f:
                json.dump(cls_idx_dict, f, indent=4, sort_keys=True)

            return cls_idx_dict 
开发者ID:aws-samples,项目名称:d-SNE,代码行数:28,代码来源:datasets_su.py

示例13: __getitem__

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def __getitem__(self, idx):
        if self.use1 and not self.use2:
            record = self.rec1.read_idx(self.idx1[idx])
            h, im = recordio.unpack(record)
            im = image.imdecode(im, self._flag)
            l = h.label
            if self.tform1 is not None:
                im = self.tform1(im)

            return im, l
        elif self.use2 and not self.use1:
            record = self.rec1.read_idx(self.idx2[idx])
            h, im = recordio.unpack(record)
            im = image.imdecode(im, self._flag)
            l = h.label
            if self.tform2 is not None:
                im = self.tform2(im)

            return im, l
        else:
            # online sample pairs generation
            r1 = self.rec1.read_idx(self.idx1[idx[0]])
            h1, im1 = recordio.unpack(r1)
            im1 = image.imdecode(im1, self._flag)
            l1 = h1.label
            if self.tform1 is not None:
                im1 = self.tform1(im1)

            r2 = self.rec2.read_idx(self.idx2[idx[1]])
            h2, im2 = recordio.unpack(r2)
            im2 = image.imdecode(im2, self._flag)
            l2 = h2.label

            if self.tform2 is not None:
                im2 = self.tform2(im2)

            yc = 1 if l1 == l2 else 0

            return im1, l1, im2, l2, yc 
开发者ID:aws-samples,项目名称:d-SNE,代码行数:41,代码来源:datasets_su.py

示例14: __getitem__

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def __getitem__(self, idx):
        r = self.rec.read_idx(idx)
        h, im = recordio.unpack(r)
        im = image.imdecode(im, self._flag)
        l = h.label

        pseudo_l = self.labels[idx]

        if self.tform is not None:
            im = self.tform(im)

        return im, l, pseudo_l 
开发者ID:aws-samples,项目名称:d-SNE,代码行数:14,代码来源:datasets_ss.py

示例15: read_record

# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import unpack [as 别名]
def read_record(rec, idx):
        record = rec.read_idx(idx)
        header, im = recordio.unpack(record)
        im = image.imdecode(im)

        label = header.label

        return im, label 
开发者ID:aws-samples,项目名称:d-SNE,代码行数:10,代码来源:datasets_ss.py


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