我有来自Keras的ImageDataGenerator对象,它无限期地产生批次。我怎样才能将n批次的每个尺寸送到张量流量变细的训练循环中。
from keras.preprocessing.image import ImageDataGenerator
import tensorflow.contrib.slim as slim
datagen = ImageDataGenerator(rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True)
for X_batch, Y_batch in datagen.flow(X_train, Y_train, batch_size=s):
# here I want to feed X_batch and Y_batch to slim.learning.train to run train_op in a loop
batches += 1
if batches >= n:
# we need to break the loop by hand because
# the generator loops indefinitely
break
请注意,我想使用由tensor-slim提供的训练循环,而不是使用原生张量流来编写我自己的例程进行训练。