Keras Hypermodel - 使用默认参数构建

标签 keras keras-tuner

我使用 KerasTuner 实现了超参数调整。我希望可以选择跳过超参数调整并改用默认值。

现在看起来像这样(搜索后用最好的参数构建模型)

MyHyperModel(HyperModel)
   def build(self, hp)
   ...hp.choice('hyperparameter', [1,2,3], default=3)
   return model

tuner = HyperBand(
    MyHyperModel(),
    ...
    )

tuner.search(
    train_inputs,
    train_targets,
    ...
    )

best_hp = tuner.get_best_hyperparameters()[0]
model = tuner.hypermodel.build(best_hp)

我想要一个类似的东西

default_model = tuner.hypermodel.build(use_default_parameter=True)

它返回具有超参数默认值的 Keras 模型,然后可以进行训练。 但我想不通。

最佳答案

使用空的 HyperParameters 容器作为参数调用构建函数会返回具有默认参数的模型:

hypermodel = MyHyperModel()
hp = kt.HyperParameters()
model = hypermodel.build(hp)

关于Keras Hypermodel - 使用默认参数构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69088545/

相关文章:

python - 使用 Keras Tuner 的未知指标 val_accuracy

python - Keras 调谐器 : mismatch between number of layers used and number of layers reported

python - Tensorflow 2.3.0 - 警告 : get_next_as_optional (from tensorflow. python.data.ops.iterator_ops) 已弃用,并将在未来版本中删除

python - 当我想将整个网络分成两个模型时,为什么 Keras ,"Graph disconnected"中会发生此错误?

python - 在 CloudML for GPU 上加速 TFRecords 馈入 Keras 模型

python - 如何在 keras 中保存整个数据的预测值

python - 如何在 Keras 中的嵌入层中指定带有数组列表的输入?

python - 如何解决AttributeError : module 'tensorflow._api.v2.distribute' has no attribute 'TPUStrategy'

machine-learning - 将参数发送到 Keras Tuner 模型构建器函数