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

僤鯓⒐⒋嵵緔 提交于 2019-12-21 18:31:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!