Press "Enter" to skip to content

使用Keras Tuner进行TensorFlow模型的超参数调优

由Will Francis在Unsplash上的照片

使用Hyperband Tuner完整代码

TensorFlow可以非常高效,但找到合适的参数的过程可能非常繁琐和乏味。另一方面,如果没有正确的参数,它就不会那么出色。我以前关于Tensorflow的所有教程都显示了非常好的结果。但我只展示了我最后一版的结果,因为那是我找到最佳结果的版本。我尝试了很多次才找到合适的参数来得到好的结果。

Keras库有一个很好的工具叫做Keras Tuner,可以在找到合适的超参数方面非常有帮助。在本文中,我们将开展一个项目,开发一个完整的模型,并看看如何在项目中使用Keras Tuner找到超参数。

本教程的先决条件是,我假设您已经知道如何使用Keras和tensorflow。

如果您需要学习有关Tensorflow和Keras模型的知识,请随时先查看我的一些以前的教程。我在本文末尾提供了链接。

此外,您需要安装keras_tuner。我在这个项目中使用了Google Colab笔记本,并使用了以下代码进行安装:

!pip install keras_tuner

现在让我们开始这个项目。以下是必要的导入:

import tensorflow as tffrom keras.models import Sequentialfrom tensorflow.keras.layers import BatchNormalizationfrom keras.layers.convolutional import Conv2Dfrom keras.layers.convolutional import MaxPooling2Dfrom keras.layers.core import Activationfrom keras.layers.core import Flattenfrom keras.layers.core import Dropoutfrom keras.layers.core import Densefrom keras import backend as Kfrom sklearn.preprocessing import LabelBinarizerfrom sklearn.metrics import classification_reportfrom keras.optimizers import SGDfrom keras.datasets import cifar10import matplotlib.pyplot as pltimport numpy as np%matplotlib inline

现在我们将开发一些将在模型中使用的函数。首先是model_build函数。在model_build中,使用了迷你VGG网络结构的卷积神经网络。如果您对这种类型的结构不太熟悉,请查看…

Leave a Reply

Your email address will not be published. Required fields are marked *