机器学习0002 安装TensorFlow


机器学习0002 安装Tensorflow


不得不说我的运气真这次真的不好,踩了好几个坑,安装之前应该认真阅读官方文档。这里以我安装Tensorflow为例,本人计算机是Windows10 64位操作系统,之前安装过基于Linux的Tensorflow安装的。Tensorflow有两个版本,一个是基于cpu的,一个是基于gpu的基于cpu的安装比较容易。gpu版本跑起来速度会快一些。

下面是进行一些实践后补充的内容:1.要是学习的话,装cpu版的比较合适,gpu版容易显存溢出。一般个人的电脑,显存2G左右,不适合训练一个大的模型。2.安装tf前一定要先升级一下pip,有些系统不升级pip,会提示找不到tf。


安装前的注意事项:

1.python一定要是3.5版本的,安装时记得把环境变量和pip上打上“√”,我在3.6版本下不能安装。

2.如果你的电脑上有其他python版本,一定要先卸载,再安装3.5版本的python


如果你要安装GPU版本,请注意:

1.要安装CUDA Toolkit8.0 ,一定要注意是8.0 !!!! 其他版本TF会跑不起来的。

2.安装cuDNN V6 注意一定要是6.0或6.1版本,其他版本跑不起来,这个东西其实就是几个文件,目录结构如下:


需要手动的把bin目录配置成环境变量,这里不再介绍环境变量配置方法。

  • CUDA® Toolkit 8.0. For details, see NVIDIA's documentation Ensure that you append the relevant Cuda pathnames to the %PATH% environment variable as described in the NVIDIA documentation.
  • The NVIDIA drivers associated with CUDA Toolkit 8.0.
  • cuDNN v6 or v6.1. For details, see NVIDIA's documentation. Note that cuDNN is typically installed in a different location from the other CUDA DLLs. Ensure that you add the directory where you installed the cuDNN DLL to your %PATH% environment variable.
  • GPU card with CUDA Compute Capability 3.0 or higher. See NVIDIA documentation for a list of supported GPU cards.


官网是这样介绍的:

  • TensorFlow with CPU support only. If your system does not have a NVIDIA® GPU, you must install this version. Note that this version of TensorFlow is typically much easier to install (typically, in 5 or 10 minutes), so even if you have an NVIDIA GPU, we recommend installing this version first.
  • TensorFlow with GPU support. TensorFlow programs typically run significantly faster on a GPU than on a CPU. Therefore, if your system has a NVIDIA® GPU meeting the prerequisites shown below and you need to run performance-critical applications, you should ultimately install this version.

上面说的是,要是电脑上有NVIDIA GPU的话可以安装GPU版本,要是没有的话只能安装CPU版本。


当你准备好了上面的内容,那么接下来你就轻松了:

1.以管理员身份运行CMD或者是Power Shell

2.GPU版本在命令行中输入:pip3 install --upgrade tensorflow-gpu

   CPU版本在命令行中输入:pip3 install --upgrade tensorflow

3.安装速度取决于网络条件,等待完成后,在命令行中输入python,进入python命令模式

4.在python命令模式中输入:

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))


大功告成!!!

猜你喜欢

转载自blog.csdn.net/moluth/article/details/78192514