gpt4 book ai didi

machine-learning - Autokeras 的 AutoModel 和 GraphAutoModel 需要解释

转载 作者:行者123 更新时间:2023-11-30 10:00:16 24 4
gpt4 key购买 nike

我了解 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 类 ( 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 类? (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.

什么是 super block ?如果Image Classifier自动进行HyperParameter Tuning,那GraphAutoModel还有什么用呢?

任何文档/资源的链接,以便更好地理解 AutoModel 和 GraphAutoModel,值得赞赏。

最佳答案

最近在autokeras工作过,可以分享一下我的一点知识。

  1. 任务 API在执行图像分类/回归、文本分类/回归等经典任务时,您可以使用 autokeras 提供的最简单的 API,称为 Task API:ImageClassifierImageRegressorTextClassifierTextRegressor、...在这种情况下,您有一个输入(图像或文本或表格数据,...)并且一个输出(分类、回归)。

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

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

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 来指定我想要的架构。有很多 block :Conv、RNN、Dense、... check the full list here 。就我而言,我想使用 RNN block 来创建模型,因为我有时间序列数据:

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功能API文档)。

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

关于machine-learning - Autokeras 的 AutoModel 和 GraphAutoModel 需要解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59301161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com