def __iter__(self):
""" Return an iterator to the data. Get the value (tensor) for self.key
from each object and yield batches of these tensors
"""
start = 0
while start < self.num_entries:
end = min(self.num_entries, start + self.chunk_size)
# linecache line numbering starts at 1
batch = [
json.loads(linecache.getline(self.source, i + 1).strip())[self.key]
for i in self.indices[start:end]
]
yield batch
start = end
###########################################################################
评论列表
文章目录