问题
Talos is a module that allows you to do hyperparameter tuning on keras models you've already written code for. The conventional way it is used in examples is with the Scan
class which is instantiated with x
and y
parameters. These parameters should contain an array with training data and labels respectively.
def modelbuilder(x_train, y_train, x_val, y_val, params):
# modelbuilding
out = model.fit(x_train, y_train)
return model, out
talos.Scan(x, y, params=params, model=modelbuilder)
However Keras provides a second way to import data with the ImageDataGenerator
class, in stead of an array you just need a directory with the train/validation images.
train_datagen = ImageDataGenerator()
train_generator = train_datagen.flow_from_directory(
train_data_dir,
batch_size=batch_size
)
Its unclear to me how I can Scan
this, the datageneration should contains a hyperparameter (batch size) which should be inside the modelbuilder
function. But at the same time Scan
requires data arguments to be provided as an array. Any suggestion how I can combine Talos with the ImageDataGenerator.
回答1:
You can now use fit_generator() in Talos experiments. See the corresponding issue for more information.
There is no specific instructions pertaining to "how to" as in accord with Talos philosophy you can use fit_generator exactly the way you would use it with a standalone Keras model. Just replace model.fit(...)
with model.fit_generator(...)
and use a generator as per your need.
来源:https://stackoverflow.com/questions/53559068/use-keras-imagedatagenerator-flow-from-directory-with-talos-scan