我正在尝试在Keras中应用一种自定义的图像增强技术。我正在使用fit_generator和一个生成器来生成图像。我想只在20个时期之后才开始应用图像增强(所以前20个时期不会有任何数据增强)。不幸的是,生成器没有纪元的概念。你知道怎么做吗?
发布于 2018-08-07 08:26:27
要做到这一点,最简单的方法是在没有实时增强的情况下训练20个时期(使用没有参数的Keras ImageDataGenerator ),并使用ModelCheckpoint回调保存模型。然后重新加载模型并继续使用RA进行训练(使用带有您选择的变换的ImageDataGenerator )。
如果您希望在一个步骤中实现该功能,您可以创建自己的ImageDataGenerator版本。您只需要做以下更改:
def __init__(self,
batch_counter=0, # count the batches elapsed
steps_per_epoch=0, # pass steps per epoch into the custom ImageDataGenerator on init
n_epoch = 0, # count the epochs elapsed然后,只需修改ImageDataGenerator中的NumpyArrayIterator以递增这些变量,并仅在n_epochs过期后调用random_transform。例如,self.image_data_generator.batch_counter += 1
https://stackoverflow.com/questions/51403468
复制相似问题