Autokeras 的 AutoModel 和 GraphAutoModel 需要说明

Explanation Needed for Autokeras's AutoModel and GraphAutoModel

我了解 AutoKeras ImageClassifier 的功能 (https://autokeras.com/image_classifier/)

clf = ImageClassifier(verbose=True, augment=False)
clf.fit(x_train, y_train, time_limit=12 * 60 * 60)
clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
y = clf.evaluate(x_test, y_test)

但我无法理解 AutoModel class (https://autokeras.com/auto_model/) 的作用,或者它与 ImageClassifier

有何不同
autokeras.auto_model.AutoModel(
inputs,
outputs,
name="auto_model",
max_trials=100,
directory=None,
objective="val_loss",
tuner="greedy",
seed=None)

参数输入和输出的文档说

  • inputs: A list of or a HyperNode instance. The input node(s) of the AutoModel.
  • outputs: A list of or a HyperHead instance. The output head(s) of the AutoModel.

什么是 HyperNode 实例

同样,GraphAutoModel class 是什么? (https://autokeras.com/graph_auto_model/)

autokeras.auto_model.GraphAutoModel(
inputs,
outputs,
name="graph_auto_model",
max_trials=100,
directory=None,
objective="val_loss",
tuner="greedy",
seed=None)

文档阅读

A HyperModel defined by a graph of HyperBlocks. GraphAutoModel is a subclass of HyperModel. Besides the HyperModel properties, it also has a tuner to tune the HyperModel. The user can use it in a similar way to a Keras model since it also has fit() and predict() methods.

什么是超级块? 如果Image Classifier自动做HyperParameter Tuning,GraphAutoModel有什么用?

链接到任何文档/资源以更好地理解 AutoModel 和 GraphAutoModel 表示赞赏。

最近接触了autokeras,分享一下自己的小知识。

  1. Task API 在做图像classification/regression、文本classification/regression、...等经典任务时,可以使用autokeras提供的最简单的APIs,称为Task APIImageClassifier, ImageRegressor, TextClassifier, TextRegressor, ... 在这种情况下,您有一个输入(图像或文本或表格数据,...)和一个输出(分类、回归) .

  2. Automodel 但是,当您遇到需要多个 inputs/outputs 架构的任务时,您不能直接使用任务 API,这就是 Automodel 发挥作用的地方I/O API。您可以查看提供的示例 in the documentation,其中您有两个输入(图像和结构化数据)和两个输出(分类和回归)

  3. GraphAutoModel GraphAutomodel 的工作方式类似于 keras functional API。它组装不同的块(卷积、LSTM、GRU 等)并使用该块创建模型,然后它将根据您提供的架构寻找最佳超参数。例如,假设我想使用时间序列作为输入数据来执行二元分类任务。 首先让我们生成一个玩具数据集:

import numpy as np
import autokeras as ak

x = np.random.randn(100, 7, 3)
y = np.random.choice([0, 1], size=100, p=[0.5, 0.5])

这里x是一个100个样本的时间序列,每个样本是一个长度为7,特征维度为3的序列。对应的目标变量y是二进制的(0, 1)。 使用 GraphAutomodel,我可以使用所谓的 HyperBlocks 指定我想要的架构。有很多块:Conv,RNN,Dense,... check the full list here。 就我而言,我想使用 RNN 块来创建模型,因为我有时间序列数据:

input_layer = ak.Input()
rnn_layer = ak.RNNBlock(layer_type="lstm")(input_layer)
dense_layer = ak.DenseBlock()(rnn_layer)
output_layer = ak.ClassificationHead(num_classes=2)(dense_layer)

automodel = ak.GraphAutoModel(input_layer, output_layer, max_trials=2, seed=123)
automodel.fit(x, y, validation_split=0.2, epochs=2, batch_size=32)

(如果您不熟悉上述定义模型的方式,那么您应该查看keras functional API文档)。

所以在这个例子中,我可以更灵活地创建我想使用的架构骨架:LSTM 块后跟密集层,然后是分类层,但是我没有指定任何超参数,(数字lstm 层的数量,密集层的数量,lstm 层的大小,密集层的大小,激活函数,dropout,batchnorm,......),Autokeras 将根据我提供的架构(骨架)自动进行超参数调整。