[机器学习]AutoML --- AutoKeras
前 言
? ? ? ?
? ? ? ? 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
?
安裝Auto-keras
?
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
?
Docker Env
?
1. Download Auto-Keras Docker image
docker pull garawalid/autokeras2. Start Auto-Keras Docker container
docker run -it --shm-size 2G garawalid/autokeras /bin/bashIn 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.pyExample :
Let's download the mnist example and run it within the container.
wget https://raw.githubusercontent.com/jhfjhfj1/autokeras/master/examples/mnist.pyRun the mnist example :
docker run -it -v "$(pwd)":/app --shm-size 2G garawalid/autokeras python mnist.py?
K8S?Env
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-autokeraslabels:name: hello-autokeras spec:volumes: - name: dshmemptyDir:medium: Memorycontainers:- image: garawalid/autokerasname: hello-container1ports:- containerPort: 8080hostPort: 6061volumeMounts: - mountPath: /dev/shmname: dshm?
Create the pod using the?shared-memory.yaml?file:
$ kubelet create -f autokeras.yamlAuto-Keras 使用示例
from keras.datasets import mnist from autokeras import ImageClassifierif __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
?
?
?
總結
以上是生活随笔為你收集整理的[机器学习]AutoML --- AutoKeras的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Kettle工具简单使用(spoon)[
- 下一篇: [机器学习]AutoML---谷歌开源A