一、Tensorflow安装
Tensorflow安装分源码安装和pip安装两种方式。
1.源码安装
需要安装java8(否则容易出现找不到javac的问题),安装Bazel,下载Tensorflow源码,再编译,不推荐这种方式,会出现无法import tensorflow错误,python 开发环境找不到tensorflow模块的错误。
1.1 java 8的安装
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
如果你因为防火墙或者其他原因,导致installer下载速度很慢,可以中断操作.然后下载好相应jdk的tar.gz 包,放在:
/var/cache/oracle-jdk7-installer (jdk7)
/var/cache/oracle-jdk8-installer (jdk8)
下面,然后安装一次installer. installer 则会默认使用 你下载的tar.gz包
运行测试:
java -version
javac -version
以上参考 http://www.cnblogs.com/a2211009/p/4265225.html
1.2 Bazel的安装
chmod +x bazel-0.5.2-installer-linux-x86_64.sh
./bazel-0.5.2-installer-linux-x86_64.sh –user
以上参考 http://www.cnblogs.com/simplelovecs/p/5150114.html
1.3 Tensorflow的源码编译 (结果是无法import tensorflow)
git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git
sudo apt-get install python-numpy swig python-dev
运行 tensorflow 根目录下的 configure 脚本进行配置:
./configure 主要配置点如下:
python location输入/usr/bin/python2.7
python lib location直接回车,确认默认位置
google选择n
mpi选择n
编译源码:
bazel build -c opt --config=cuda --spawn_strategy=standalone //tensorflow/cc:tutorials_example_trainer
运行测试程序:
bazel-bin/tensorflow/cc/tutorials_example_trainer --use_gpu
以上参考:http://www.cnblogs.com/simplelovecs/p/5150114.html
2.Eclipse+pydev的安装
sudo apt-get purge openjdk*
下载Eclipse(选择合适的版本,我选的Java开发版,有人选择的是C/C++版):
https://www.eclipse.org/downloads/eclipse-packages/
解压到自己定的目录,就可以运行Eclipse了。
在Help菜单中,选择Install New Software···,
选择Add按钮,Name:PyDev(这个随便起),Location:http://pydev.org/updates
选择PyDev下的PyDev for Eclipse,别的都不要选,否则依赖检查那关过不去。
按照提示即可安装成功。
3.pip安装需要安装scipy,再运行pip安装命令。
3.1 pip安装Tensorflow(成功)
由于墙的原因,通过pip在线安装tensorflow会出现无法连接的现象。
所以,从tensorflow github网站 code页面下面installation中下载最新的tensorflow whl安装包,注意根据自己需要选择合适的whl。我选择的linux 64 gpu python2对应的包。
sudo pip install --ignore-installed --upgrade tensorflow_gpu-1.3.0rc2-cp27-none-linux_x86_64.whl
这时会发现scipy安装失败,现象和http://blog.csdn.net/u010551621/article/details/46363853 中相同,需要按照该网站的方法来安装支持包。
成功安装tensorflow后,在python中import tensorflow会出现找不到libcudnn.so.6库文件错误,重新下载安装cudnn 6.0, 成功。
3.2 Ubuntu 14.0.4 pip 安装scipy
1. sudo pip install numpy
2. sudo apt-get install liblapack-dev libblas-dev gfortran
3. sudo pip install nose
4. sudo pip install atlas
5. sudo pip install scipy
二、Tensorflow实例
网络资源
1) yongyehuang/Tensorflow-Tutorial https://github.com/yongyehuang/Tensorflow-Tutorial
2) lucko515/tesla-stocks-prediction https://github.com/lucko515/tesla-stocks-prediction
3) Stock Price Prediction using LSTM https://github.com/tencia/stocks_rnn
4) 利用LSTM预测股票每日最高价 http://blog.csdn.net/mylove0414/article/details/55805974
对应github https://github.com/LouisScorpio/datamining/tree/master/tensorflow-program/rnn/stock_predict
5) TensorFlow核心使用技巧 http://www.52cs.org/?p=1157
高级应用实例:TFRecords、QueueRunner、Checkpoint、TensorBoard、Inference、GPU支持、分布式训练和多层神经网络模型等特性 https://github.com/tobegit3hub/tensorflow_template_application
Tensorboard显示图表问题:
运行mnist_with_summaries.py 报Couldn't open CUDA library libcupti.so.8.0. LD_LIBRARY_PATH
修改LD_LIBRARY_PATH变量,增加路径/usr/local/cuda/extras/CUPTI/lib64/
用tensorboard --logdir= ./mnist_with_summaries/
curl http://127.0.0.1:6006 -o tensorboard.html
在tensorboard运行的控制台报如下错误:
WARNING:tensorflow:path /weblas.map.json not found, sending 404
WARNING:tensorflow:path /web-animations-next-lite.min.js.map not found, sending 404
拷贝tensorboard.html到chrome浏览器,发现可以显示一些页面内容,不是空白。
安装Chrome
1)安装参考 https://github.com/FZUG/repo/wiki/%E5%AE%89%E8%A3%85-Chrome
2)sudo wget https://repo.fdzh.org/chrome/google-chrome.list -P /etc/apt/sources.list.d/
3)sudo apt-get update
4)sudo apt-get install google-chrome-stable
检查event文件,tensorboard --inspect --event_file=/home/jqh/jiangqiuhua/Tensorflow/mnist_with_summaries/test/events.out.tfevents.1502444010.jqhgpu
运行 tensorboard --logdir=/home/jqh/jiangqiuhuTensorflow/mnist_with_summaries/
在chrome中输入 localhost:6006既可以看到图表。