将keras ImageDataGenerator.flow_from_directory()与Talos Scan()一起使用 [英] Use keras ImageDataGenerator.flow_from_directory() with Talos Scan()

查看:596
本文介绍了将keras ImageDataGenerator.flow_from_directory()与Talos Scan()一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Talos是一个模块,允许您对已经为其编写代码的keras模型进行超参数调整.在示例中使用的常规方式是Scan类,该类用xy参数实例化.这些参数应包含一个分别包含训练数据和标签的数组.

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)

但是Keras提供了第二种使用ImageDataGenerator类导入数据的方法,而不是一个数组,您只需要一个包含训练/验证图像的目录即可.

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
)

我不清楚如何才能做到这一点,数据生成应包含一个超参数(批处理大小),该参数应位于modelbuilder函数内部.但是同时Scan要求将数据参数作为数组提供.关于如何将Talos与ImageDataGenerator结合的任何建议.

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.

推荐答案

您现在可以在Talos实验中使用fit_generator().有关更多信息,请参见相应问题.

You can now use fit_generator() in Talos experiments. See the corresponding issue for more information.

没有关于如何做"的具体说明,根据Talos的哲学,您可以完全按照与独立Keras模型一起使用fit_generator的方式来使用fit_generator.只需将model.fit(...)替换为model.fit_generator(...)并根据需要使用一个生成器.

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.

这篇关于将keras ImageDataGenerator.flow_from_directory()与Talos Scan()一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆