【发布时间】:2020-03-25 10:42:06
【问题描述】:
我想在自己的数据集上创建自己的自定义 DataGenerator。我已阅读所有图像并将位置及其标签存储在两个名为 images 和 labels 的变量中。我已经编写了这个自定义生成器:
def data_gen(img_folder, y, batch_size):
c = 0
n_image = list(np.arange(0,len(img_folder),1)) #List of training images
random.shuffle(n_image)
while (True):
img = np.zeros((batch_size, 224, 224, 3)).astype('float') #Create zero arrays to store the batches of training images
label = np.zeros((batch_size)).astype('float') #Create zero arrays to store the batches of label images
for i in range(c, c+batch_size): #initially from 0 to 16, c = 0.
train_img = imread(img_folder[n_image[i]])
# row,col= train_img.shape
train_img = cv2.resize(train_img, (224,224), interpolation = cv2.INTER_LANCZOS4)
train_img = train_img.reshape(224, 224, 3)
# binary_img = binary_img[:,:128//2]
img[i-c] = train_img #add to array - img[0], img[1], and so on.
label[i-c] = y[n_image[i]]
c+=batch_size
if(c+batch_size>=len((img_folder))):
c=0
random.shuffle(n_image)
# print "randomizing again"
yield img, label
我想知道的是如何向此生成器添加其他增强功能,例如 flip、crop、rotate?此外,我应该如何yield 这些扩充,以便它们与正确的标签相关联。
请告诉我。
【问题讨论】:
标签: python-3.x keras deep-learning data-augmentation data-generation