win10下autokeras的入门
win10下autokeras的安装
按照官方网站的方法进行安装,注意:Auto-Keras只支持Python3.6。
项目github:https://github.com/jhfjhfj1/autokeras
pip install autokeras
autokeras需要的依赖项很多,包括tensorflow、pytorch、keras、numpy等,大部分在pip安装autokeras都可以自动下载,除了pytorch需要参考torch官网手动安装。总体而言,还是很简单的。
win10下autokeras的GPU使用
安装完成之后,就可以使用https://github.com/jhfjhfj1/autokeras/blob/master/examples/mnist.py文件进行测试:
from keras.datasets import mnist
from autokeras import ImageClassifier
import tensorflow
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)
clf.fit(x_train, y_train, time_limit=12 * 60 * 60)
clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
y = clf.evaluate(x_test, y_test)
print(y * 100)
运行后输出一行乱码,同时程序可以正常运行,但在cmd中nvidia-smi一下,发现GPU并没有运行,程序干跑CPU。
这是由于autokeras下utils.py文件中get_device()函数使用了Linux中的命令’grep’所造成的。将其修改为win10的批处理命令即可:
//原utils.py下第80行
smi_out = os.popen('nvidia-smi -q -d Memory |grep -A4 GPU|grep Free >tmp').read()
//修改为
smi_out = os.popen('nvidia-smi -q -d Memory | findstr Free').read()
再次运行测试程序,无乱码输出,查看nvidia-smi,可见GPU在运行。
如何更改autokeras中的batch size
打开autokeras下constant.py文件
可见默认MAX_BATCH_SIZE = 128,直接修改MAX_BATCH_SIZE,处理超出显存的问题。