def iterchunks(self, key, batch_size=10, verbose=False):
if key not in self.keys_:
raise RuntimeError('Key %s not found in dataset. keys: %s' % (key, self.keys_))
idx, ii = 0, 0
total_chunks = len(self.meta_file_.chunks)
batch_chunks = grouper(range(len(self.meta_file_.chunks)), batch_size)
for chunk_group in progressbar(batch_chunks, size=total_chunks / batch_size, verbose=verbose):
items = []
# print key, chunk_group
for chunk_idx in chunk_group:
# grouper will fill chunks with default none values
if chunk_idx is None: continue
# Load chunk
data = AttrDict.load(self.get_chunk_filename(chunk_idx))
for item in data[key]:
items.append(item)
yield items
评论列表
文章目录