def get_batcher(self, shuffle=True, augment=True):
""" produces batch generator """
w, h = self.resize
if shuffle: np.random.shuffle(self.data)
data = iter(self.data)
while True:
x = np.zeros((self.batch_size, self.timesteps, h, w, 3))
y = np.zeros((self.batch_size, 1))
for b in range(self.batch_size):
images, label = next(data)
for t, img_name in enumerate(images):
image_path = self.folder + 'images/' + img_name
img = cv2.imread(image_path)
img = img[190:350, 100:520] # crop
if augment:
img = aug.augment_image(img) # augmentation
img = cv2.resize(img.copy(), (w, h))
x[b, t] = img
y[b] = label
x = np.transpose(x, [0, 4, 1, 2, 3])
yield x, y
评论列表
文章目录