def load_batches(self):
""" Load max_batches batches into memory """
is_new = False
if self.batches:
batches = self.batches
else:
is_new = True
batches = []
self.batches = batches
image_dir = self.image_dir
batch_size = self.batch_size
image_h = self.image_h
image_w = self.image_w
file_list = os.listdir(image_dir) if image_dir != DUMMY else []
n = self.last_load
for b in range(self.max_batches):
if is_new:
arr = np.zeros((batch_size, image_h, image_w, 3))
batches.append(arr)
else:
arr = batches[b]
if image_dir != DUMMY:
i = 0
while i < batch_size:
file_name = file_list[n]
try:
image = utils.load_image(os.path.join(image_dir,file_name), image_h, image_w)
arr[i] = image
i += 1
except:
pass
n += 1 if not self.valid else -1
self.last_load = n
评论列表
文章目录