没想到安装一个Tensorflow 都有那么多坑
经过一天时间的折腾,重要完美的走完所有 菜鸟会遇到的坑。
以下经验教训总结为 傻瓜式 完全教程。
一. 在Windows10 下安装 双系统的Ubuntu
Win10下硬盘安装Ubuntu双系统教程(EasyBCD法)
二.配置Ubuntu 系统环境
1.因为默认系统环境 是open-jdk8.0 ,所以作为开发环境 需要替换成 oracel jdk会更好。
[在Linux系统配置Oracle Java JDK 8]
(http://jingyan.baidu.com/article/215817f7eea4a01eda142326.html)
2.命令行里 确认 $ : python --version
是否对应 python2.7,Yes就继续
3. Install Bazel
sudo apt-get update && sudo apt-get install bazel
4.Install other dependencies
sudo apt-get install python-numpy swig python-dev python-wheel
5.
三.下载CUDA8.0 +CUDNN5
1. 下载(CUDA8.0 的两个文件)[https://developer.nvidia.com/cuda-release-candidate-download]
Paste_Image.png2. (下载CUDNN5)[https://developer.nvidia.com/rdp/cudnn-download]
选择 cuDNN v5.1 for CUDA 8.0RC
Paste_Image.png
tar xvzf cudnn-8.0-linux-x64-v4.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
四.以源文件编译方式安装Tensorflow
1. clone tensorflow sources
$ git clone https://github.com/tensorflow/tensorflow
2. download and install cuDNN
Download and install cuDNN
https://developer.nvidia.com/cudnn
Download cuDNN v4 (v5 is currently a release candidate and is only supported when installing TensorFlow from sources).
Uncompress and copy the cuDNN files into the toolkit directory. Assuming the toolkit is installed in /usr/local/cuda
, run the following commands (edited to reflect the cuDNN version you downloaded):
3.Configure the installation
Run the configure
script at the root of the tree. The configure script asks you for the path to your python interpreter and allows (optional) configuration of the CUDA libraries.
This step is used to locate the python and numpy header files as well as enabling GPU support if you have a CUDA enabled GPU and Toolkit installed. Select the option Y
when asked to build TensorFlow with GPU support.
If you have several versions of Cuda or cuDNN installed, you should definitely select one explicitly instead of relying on the system default.
For example:
$ ./configurePlease specify the location of python. [Default is /usr/bin/python]:
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] N
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with GPU support? [y/N] y
GPU support will be enabled for TensorFlow
Please specify which gcc nvcc should use as the host compiler. [Default is /usr/bin/gcc]:
Please specify the Cuda SDK version you want to use, e.g. 7.0.
[Leave empty to use system default]:
7.5Please specify the location where CUDA 7.5 toolkit is installed.
Refer to README.md for more details.
[Default is /usr/local/cuda]:
Please specify the cuDNN version you want to use.
[Leave empty to use system default]: 5
Please specify the location where cuDNN 5 library is installed.
Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 3.0
Setting up Cuda include
Setting up Cuda libSetting up Cuda bin
Setting up Cuda nvvmSetting up CUPTI include
Setting up CUPTI lib64Configuration finished
This creates a canonical set of symbolic links to the Cuda libraries on your system.
Every time you change the Cuda library paths you need to run this step again before you invoke the bazel build command.
For the cuDNN libraries, use '6.5' for R2, '7.0' for R3, and '4.0.4' for R4-RC.
$ bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer$ bazel-bin/tensorflow/cc/tutorials_example_trainer
--use_gpu
# Lots of output. This tutorial iteratively calculates the major eigenvalue of
# a 2x2 matrix, on GPU. The last few lines look like this.
000009/000005 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]
000006/000001 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]
000009/000009 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]
Note that "--config=cuda" is needed to enable the GPU support.
Known issues
Although it is possible to build both Cuda and non-Cuda configs under the same source tree, we recommend to run bazel clean
when switching between these two configs in the same source tree.
You have to run configure before running bazel build. Otherwise, the build will fail with a clear error message. In the future, we might consider making this more convenient by including the configure step in our build process.
Create the pip package and install
When building from source, you will still build a pip package and install that.
$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
# To build with GPU support:
$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
# The name of the .whl file will depend on your platform.
$ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.10.0rc0-py2-none-any.whl
Setting up TensorFlow for Development
If you're working on TensorFlow itself, it is useful to be able to test your changes in an interactive python shell without having to reinstall TensorFlow.
To set up TensorFlow such that all files are linked (instead of copied) from the system directories, run the following commands inside the TensorFlow root directory:
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
# To build with GPU support:
bazel build -c opt --config=cuda
//tensorflow/tools/pip_package:build_pip_package
mkdir _python_build
cd _python_build
ln -s ../bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/* .
ln -s ../tensorflow/tools/pip_package/* .
python setup.py develop
Note that this setup still requires you to rebuild the //tensorflow/tools/pip_package:
build_pip_package
target every time you change a C++ file; add, delete, or move any python file;
or if you change bazel build rules.
Train your first TensorFlow neural net model
$ cd tensorflow/models/image/mnist
$ python convolutional.py
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
...
Minibatch loss: 12.054, learning rate: 0.010000
Minibatch error: 90.6%
Validation error: 84.6%
Epoch 0.12
Minibatch loss: 3.285, learning rate: 0.010000
Minibatch error: 6.2%
Validation error: 7.0%
...
关于 遇到的疑难杂症: 重启后无限登陆 不进去图形桌面
ctrl+alt+f1
sudo stop lightdmsudo
apt-get updatesudo
apt-get upgradesudo
apt-get install --reinstall lightdm
sudo reboot
看看有沒有改善
网友评论