Windows 10 安装 Cuda, Tensorflow, 和keras,附CPU/GPU切换小技巧

本文介绍了在Windows 10上安装CUDA、CuDNN、Tensorflow和Keras的步骤,以及如何在CPU和GPU之间切换。首先,通过Anaconda安装Python 3.5,然后下载并安装CUDA和CuDNN。接着使用pip安装Tensorflow的CPU或GPU版本,最后一步是安装Keras并验证安装是否成功。文章还提供了在CPU和GPU上运行示例代码的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Originally published on Medium, reblogged in case of blocking

I’ve tried months ago to install the GPU-based Machine learning framework, namely keras with tensorflow, but get stuck following the official indication of the latter, and the issue remained unresolved until yesterday because of loads of patients in summer vocation, and I finally managed to get m1000m working.

I basically followed instructions written in Chinese in http://blog.youkuaiyun.com/u012898521/article/details/69611800, with a few modifications according to keras documentation in Chinese HERE, and actually I did a combination of both.

Step 1 — python

By far tensorflow only support python 3 but no newer than major version of 3.5, and last time I got a lot of trouble tried to install the dependencies especially scipy. I didn’t use anaconda because it starts rather slow and Google said you could install tensorflow without it, and it was later I found scipy itself WILL encounter problems when installed on windows.

这里写图片描述

SO, just install Anaconda with python 3.5 (I installed Anaconda 4.2.0 with python 3.5.2) HERE, and it will save you all the troubles.

Step 2 — CUDA and CuDNN

CUDA is toolkit enables you to all the fun programming with NVIDIA GPU, you’re welcomed unless your GPU is prior to GTX 5XX.

You can download it HERE, and you’ll find it a bit of time consuming.

这里写图片描述

Installation is simple a series of ‘Next’s.

And now you can install CuDNN, an acceleration library for CUDA. You’ll require to signed a developer account in order to get it HERE, and then unzip the folders and overwrite folders atC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\8.0 with same names.

Step 3 — Tensorflow

Simply use pip with installation.

To install CPU version(required)

>pip install tensorflow

To install GPU version(optional)

>pip install tensorflow-gpu

If it says pip is outdated or cannot find resource,try upgrading pip

python.exe -m pip install — upgrade pip

Then, test with import and it should not return any errors

>python
>>>import tensorflow as tf

Step 4 — Keras

A line of code will do

pip install keras

Keras will be installed with theano by default, but it will use tensorflow as the back-end, so don’t panic, and test if keras is installed correctly by

import keras

Now we could run the MNIST example in Keras with either CPU or GPU

Step 4 — Run and switch between CPU and GPU

Download keras testing data sets HERE, or if you have git run

git clone https://github.com/fchollet/keras.git

Locate at keras/examples/, and run mnist_mlp.py, if you installed CUDA and CuDNN correctly, it will run on GPU by default, and here’s my running on GPU:

这里写图片描述

Sadly I have only a M1000M on a laptop, whose performance is compromised. ��

If you want to know how it will be on using CPU, you may Googled and get a suggestion os.environ["CUDA_VISIBLE_DEVICES"] ="", which you may well find vitiate.

And here’s the trick, simply change the value to -1 will do. More specifically, add these two lines whenever you want to run it on CPU:

import os
os.environ[“CUDA_VISIBLE_DEVICES”] = ‘-1

My i7–6850HQ runs two times slower than the ‘weak’ GPU M1000M

这里写图片描述

Finally, we have GPU based computer��

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值