Keras 是一个用 Python 编写的高级神经网络 API,能够在 TensorFlow、CNTK 或 Theano 之上运行。它的意义在于可以实现快速实验。而能够以最小的延迟把想法变成结果是顺利进行研究的关键。
AutoKeras是一个开源的,基于 Keras 的新型 AutoML 库。AutoKeras 是一个用于自动化机器学习的开源软件库,提供自动搜索深度学习模型的架构和超参数的功能。AutoKeras 采用的架构搜索方法是一种结合了贝叶斯优化的神经架构搜索。它主要关注于降低架构搜索所需要的计算力,并提高搜索结果在各种任务上的性能。
官方网站:https://autokeras.com/
项目github:https://github.com/jhfjhfj1/autokeras
TensorFlow版本:https://github.com/melodyguan/enas
PyTorch 版本:https://github.com/carpedm20/ENAS-pytorch
Note: currently, Auto-Keras is only compatible with: Python 3.6.
1 Auto-Keras依赖于Keras, Pytorch, Tensorflow组件,打开Anconda Prompt,输入以下命令:
pip install keras
pip install install pytorch
pip install tensorflow-gpu
等待安装完毕即可。
2 安装graphviz
此依赖包的目的是为了绘制Auto-Keras生成的网络结构,同样的输入以下命令:
pip install graphviz
3. 安装Auto-Keras
最后来安装Auto-Keras,输入命令:
pip install autokeras
1. Download Auto-Keras Docker image
docker pull garawalid/autokeras
2. Start Auto-Keras Docker container
docker run -it --shm-size 2G garawalid/autokeras /bin/bash
In case you need more memory to run the container, change the value of shm-size
. (Docker run reference)
3. Run application :
To run a local script file.py
using Auto-Keras within the container, mount the host directory -v hostDir:/app
.
docker run -it -v hostDir:/app --shm-size 2G garawalid/autokeras python file.py
Example :
Let's download the mnist example and run it within the container.
wget https://raw.githubusercontent.com/jhfjhfj1/autokeras/master/examples/mnist.py
Run the mnist example :
docker run -it -v "$(pwd)":/app --shm-size 2G garawalid/autokeras python mnist.py
1. specifies the tmpfs volume dshm.
2. enables POSIX shared memory for hello-container1 via dshm.
https://docs.okd.io/latest/dev_guide/shared_memory.html
apiVersion: v1
id: hello-autokeras
kind: Pod
metadata:
name: hello-autokeras
labels:
name: hello-autokeras
spec:
volumes:
- name: dshm
emptyDir:
medium: Memory
containers:
- image: garawalid/autokeras
name: hello-container1
ports:
- containerPort: 8080
hostPort: 6061
volumeMounts:
- mountPath: /dev/shm
name: dshm
Create the pod using the shared-memory.yaml file:
$ kubelet create -f autokeras.yaml
from keras.datasets import mnist
from autokeras import ImageClassifier
if __name__ == '__main__':
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.reshape(x_train.shape+(1,))
x_test = x_test.reshape(x_test.shape+(1,))
clf = ImageClassifier(verbose=True, augment=False)
clf.fit(x_train, y_train, time_limit=30 * 60)
clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
y = clf.evaluate(x_test, y_test)
print(y * 100)
clf.load_searcher().load_best_model().produce_keras_model().save('\my_model.h5')
运行代码,显示Auto-Keras正在不断进行迭代以寻找最优网络:
参考: https://towardsdatascience.com/auto-keras-or-how-you-can-create-a-deep-learning-model-in-4-lines-of-code-b2ba448ccf5e