在Windows 11 使用autoKeras 并透过GPU加速 (内含不用另外下载档案的tensorflow-gpu

之所以写这篇,是因为自己的linux系统是pop-os 22.04,tensorflow版本撞到翻(也有版本直接不支援这个OS...)

而也才发现Tensorflow的GPU用法 要对windows设限了,写这篇提醒未来怎么安装~
依据:https://tensorflow.google.cn/install/source_windows?hl=en#gpu
http://img2.58codes.com/2024/20156181INfFm8d5tS.png
所以只能安装tensorflow-gpu 2.10.0喽~(虽然 tensorflow忘记哪个版本开始 就会侦测是否有nvidia GPU可使用,但结果论 很多问题,所以还是乖乖使用最后支援的tensorflow-gpu 2.10.0吧~)

老样子使用anaconda,一开始步骤都一样,后面则将只使用tensorflow-gpu 与 要使用autoKeras分成两块~

建虚拟环境

conda create -n autokeras python=3.9 -y

进入虚拟环境

conda activate autokeras

查看有甚么板本可用

conda search cudatoolkit conda search cudnn 

安装cuda 与 cudnn

因为我使用的是 rtx4090,所以我直接找最新的版本使用就是了,不过下面的版本 应该适用30x0以上吧

conda install cudatoolkit=11.8.0 -yconda install cudnn=8.9.2.26 -y

下面这行 是因为cudnn 不是下载档案的,有些依赖项没包好

conda install -yc conda-forge zlib-wapi

(一)如果只要使用tensorflow-gpu

pip install tensorflow-gpu==2.10.0

(二)使用autoKeras

pip install git+https://github.com/keras-team/keras-tuner.gitpip install autokeras==1.0.20

(因为目前autoKeras 会莫名的连同tensorflow、Keras等一起下载(官网说不会...),并且会直接安装到很新的板本,不过Windows 已经像上面说的,被排挤了,只能使用到tensorflow-gpu==2.10.0,所以要卸载重装,但放心 不会影响到autoKeras)

pip uninstall tensorflow -ypip uninstall tensorflow-intel -ypip install tensorflow-gpu==2.10.0

测试TF 是否有吃到GPU

pythonimport tensorflow as tftf.test.is_gpu_available()#如果最下方 是True 就可以了exit()

测试AutoKeras

直接使用AutoKeras官方的影像分类範例 有名的mnist

import numpy as npimport tensorflow as tffrom tensorflow.keras.datasets import mnistimport autokeras as ak(x_train, y_train), (x_test, y_test) = mnist.load_data()print(x_train.shape)  # (60000, 28, 28)print(y_train.shape)  # (60000,)print(y_train[:3])  # array([7, 2, 1], dtype=uint8)#Initialize the image classifier.clf = ak.ImageClassifier(overwrite=True, max_trials=1)#Feed the image classifier with training data.clf.fit(x_train, y_train, epochs=10)#Predict with the best model.predicted_y = clf.predict(x_test)print(predicted_y)#Evaluate the best model with testing data.print(clf.evaluate(x_test, y_test))

(晚点再export环境)


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章