Python中如何使用Auto-Keras自动搜索深度学习模型的网络架构和超参数

Auto-Keras 是一个开源的自动机器学习库。Auto-Keras 的终极目标是允许所有领域的只需要很少的数据科学或者机器学习背景的专家都可以很容易的使用深度学习。Auto-Keras 提供了一系列函数来自动搜索深度学习模型的网络和超参数。

安装:

pip install autokeras

样例:

import autokeras as ak
clf = ak.ImageClassifier()
clf.fit(x_train, y_train)
results = clf.predict(x_test)

官方网站: http://autokeras.com/
开源项目: https://github.com/jhfjhfj1/autokeras

Auto-Keras is an open source software library for automated machine learning (AutoML). The ultimate goal of AutoML is to allow domain experts with limited data science or machine learning background easily accessible to deep learning models. Auto-Keras provides functions to automatically search for architecture and hyperparameters of deep learning models.

翻译: http://www.tf86.com/2018/08/03/auto-keras/
Python中如何使用Auto-Keras自动搜索深度学习模型的网络架构和超参数


13 回复

抢个沙发试试。auto-keras,有点可怕。


Auto-Keras是一个基于Keras的自动机器学习库,它能自动搜索最优的神经网络架构和超参数。下面是一个完整的示例,展示如何使用Auto-Keras进行图像分类任务。

# 首先安装Auto-Keras和必要的依赖
# pip install autokeras tensorflow

import numpy as np
import tensorflow as tf
import autokeras as ak

# 1. 准备数据
# 这里使用MNIST数据集作为示例
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
# 扩展维度以符合Auto-Keras输入要求 (样本数, 高度, 宽度, 通道数)
x_train = np.expand_dims(x_train, -1).astype("float32") / 255.0
x_test = np.expand_dims(x_test, -1).astype("float32") / 255.0

# 2. 初始化图像分类器
# max_trials: 最大尝试次数,控制搜索强度
# overwrite: 是否覆盖之前的搜索结果
clf = ak.ImageClassifier(
    max_trials=10,  # 尝试10个不同的模型架构/超参数组合
    overwrite=True,
)

# 3. 开始自动搜索
# 这会自动尝试不同的网络架构(如ResNet、DenseNet等)和超参数(学习率、层数等)
clf.fit(x_train, y_train, epochs=5)

# 4. 评估最佳模型
accuracy = clf.evaluate(x_test, y_test)
print(f"测试准确率: {accuracy}")

# 5. 导出最佳模型为Keras模型
best_model = clf.export_model()
best_model.summary()

# 6. 保存模型
best_model.save("best_auto_model.h5")

关键点说明:

  • max_trials参数控制搜索的广度,值越大找到好模型的机会越大,但耗时也更长
  • Auto-Keras会自动处理数据预处理、网络架构搜索、超参数调优
  • 搜索完成后,可以用export_model()获取最终的Keras模型进行部署

一句话建议: 对于简单任务,max_trials设为10-20就够了,复杂任务可以适当增加。

等会就试试…😯

看起来有点牛批,sklearn 的翻版?

sklearn 不是有个 gridSearch?跟那个有什么区别?

深度学习帮码农挑选优质特征

神经网络超参数太多,不会用网格搜索这种遍历调参的。调参的时候蛮多 trick 的

之前是自动调参数,现在是自动调网络

看文档,这个模型也会调。

本质是个 NAS 吧。

不是已经有 hpot 了吗?

厉害了!
虽然 tensorflow 很难用,但为了这些周边,还是值得搞 TF 的~

First, each dataset is split by60-20-20 into training, validation and testing set.
Second, run the method for 12 hours on a single GPU (NVIDIA GeForce GTX 1080Ti) on the training and validation set.
Third, the output architecture is trained with both training and validation set.
Fourth, the testing set is used to evaluate the trained architecture

最近经常见 200 块 gpu,训练个把月的 RL 文章,这方法简直是一股清流

回到顶部