简体   繁体   中英

Use keras ImageDataGenerator.flow_from_directory() with Talos Scan()

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM