本文整理汇总了Python中mxnet.recordio.MXIndexedRecordIO方法的典型用法代码示例。如果您正苦于以下问题:Python recordio.MXIndexedRecordIO方法的具体用法?Python recordio.MXIndexedRecordIO怎么用?Python recordio.MXIndexedRecordIO使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mxnet.recordio
的用法示例。
在下文中一共展示了recordio.MXIndexedRecordIO方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _fork
# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import MXIndexedRecordIO [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)
示例2: gen_cls_dict
# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import MXIndexedRecordIO [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)
示例3: __init__
# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import MXIndexedRecordIO [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
示例4: _fork
# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import MXIndexedRecordIO [as 别名]
def _fork(self):
self.rec1 = recordio.MXIndexedRecordIO(self.idx_f1, self.rec_f1, 'r')
self.cls_idx_d1 = self.load_or_gen_dict(self.rec_f1, self.rec1)
self.idx1 = list(self.rec1.idx.keys())
self.rec2 = recordio.MXIndexedRecordIO(self.idx_2, self.rec_f2, 'r')
self.cls_idx_d2 = self.load_or_gen_dict(self.rec_f2, self.rec2)
self.idx2 = list(self.rec2.idx.keys())
示例5: __init__
# 需要导入模块: from mxnet import recordio [as 别名]
# 或者: from mxnet.recordio import MXIndexedRecordIO [as 别名]
def __init__(self, batch_size, data_shape,
path_imgrec = None,
shuffle=False, aug_list=None, mean = None,
rand_mirror = False, cutoff = 0,
data_name='data', label_name='softmax_label', **kwargs):
super(FaceImageIter, self).__init__()
assert path_imgrec
if 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)
if shuffle:
self.seq = self.imgidx
self.oseq = self.imgidx
print(len(self.seq))
else:
self.seq = None
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.provide_label = [(label_name, (batch_size,102))]
#print(self.provide_label[0][1])
self.cur = 0
self.nbatch = 0
self.is_init = False