最近经常使用keras进行图像分割,小数据量时很方便,直接准备好image和mask,然后
model.fit(x_train, y_train, batch_size=32, epochs=10)
比较简单,但是这只是在小数据量的情况下使用。遇到大数据量,一次存入所有图像和mask会内存不够。在keras中文文档中写到了利用图片生成器ImageDataGenerator的方法,但是第一个例子和第二个例子是关于图像分类的,在最后一个例子和图像分割有关,放上代码:
# we create two instances with the same arguments
data_gen_args = dict(featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=90.,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.2)
image_datagen = ImageDataGenerator(**data_gen_args)
mask_datagen = ImageDataGenerator(**data_gen_args)
# Provide the same seed and keyword arguments to the fit and flow methods
seed = 1
image_datagen.fit(images, augment=True, seed=seed)
mask_datagen.fit(masks, a