tensorflow 之 bazel安装 & 使用

来源:互联网 发布:淘宝自动回复 编辑:程序博客网 时间:2024/04/24 20:02

目录:

1,机器学习 & MR

Hadoop进阶(hadoop streaming c++实现 & MapReduce参数调优)

hadoop streaming (shell执行 & combiner & 数据分割)

hadoop streaming python 处理 lzo 文件遇到的问题

spark安装与调试

推荐算法之Jaccard相似度与Consine相似度

LibLinear使用总结

深度学习在推荐领域的应用 

2,tensorflow 安转与使用

Tersorflow深度学习入门—— CIFAR-10 训练示例报错及解决方案

tensorflow 之 bazel安装 & 使用

Python的库sklearn安装 & bazel安装 & cmake

TF(tensorflow)安装之python

GBDT 之 Boosting方法

GBDT安装(xgboost LightGBM),

3,工具安装

linux export 环境变量设置   

linux crontab -e报错

configure --prefix=/ & yum install 路径

rethat / CentOS环境配置

redis 值 hiredis (c/c++)

今天发现要学的东西好多啊,自己学得又慢,快没信心了(博文第5部分)

urlencode & quote & unquote (url 中带中文参数)

python httplib urllib urllib2区别(一撇)


4, 工具包的使用

推荐系统学习05-libFM

LibFM使用手册中文版

XGboost & LibLinear (git)

wordart 之用户画像


写在文章前面:

当一个人从一个领域跨到另一个领域的时候会面临很大的改变,理论不同了,方法变换了,遇到这样挑战的时候,很多人都需要长时间去适应和习惯;这种领域的转换其实有三种,一种是理论的改变,一种是方法论的改变,另一种,则是理论和方法论都发生了改变。

1,方法论的变化,重要的应对在于做,多做,多总结,从熟悉到习惯,从习惯到精通;

2,理论的变化,重要的应对在于悟,多想,多问自己为什么,尝试内心的突破,打破自己既有的思维桎梏。

3,有时候觉得方法论更重要,那是因为自己对工具的使用还不熟练,当对工具使用熟练后,会觉得理论更重要,但是在接触到更深的理论后发现,还有更多的工具需要掌握,于是方法论又变得重要,总之,人生就是在知和行中间不断的震荡上行~~~。

扯远了,收回来


0,前言:一些相关连接

http://www.cnblogs.com/Jack47/p/install-bazel-on-redhat-enterprise-5.html (弯路,bazel需要JDK8以上支持,里面很杂)

https://github.com/bazelbuild/bazel/releases    ----- 下载sh文件安装(OK)

https://sonic.gitbooks.io/bazel/chapter1.html   ----- JDK & Bazel安装(OK,感觉也非常的乱)

http://blog.csdn.net/zhangweijiqn/article/details/53200081  (OK,不错的完整的安装JDK --> Bazel --> TF的过程)


1,bazel安装的泪水

(1)安装google的bazel来编译

下载地址:https://github.com/bazelbuild/bazel/releases

chmod +x PATH_TO_INSTALL.SH
./PATH_TO_INSTALL.SH --user

直接安装如果失败,可以尝试从源码安装bazel:
git clone https://github.com/ibmsoe/bazel
cd bazel
git checkout master
./compile.sh
Build successful! Binary is here: /export/App/bazel/output/bazel
注意安装完后的路径是上面给出的路径,由于上面的sh已经把bazel安装到/usr/local/bin/bazel下,所以要使用新安装的bazel修改tensorflow/configure里的bazel改为绝对路径。
(2)安装其他依赖:
# For Python 2.7:$ sudo apt-get install python-numpy swig python-dev python-wheel# For Python 3.x:$ sudo apt-get install python3-numpy swig python3-dev python3-wheel
(3)configuration:
./configure --user
(4)Create the pip package and install
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
报错:
/usr/local/bin/bazel: line 88: /usr/local/lib/bazel/bin/bazel-real: cannot execute binary file
这里解决是重新安装bazel,参考(1)中的从源码安装bazel

上面的步骤完成后,测试一下是否安装成功:


2,使用bazel运行tensorflow的textsum模型

https://github.com/tensorflow/models/tree/master/textsum

How To Run

依赖:Prerequisite: install TensorFlow and Bazel.

第一步:

# cd to your workspace# 1. Clone the textsum code to your workspace 'textsum' directory.# 2. Create an empty 'WORKSPACE' file in your workspace.# 3. Move the train/eval/test data to your workspace 'data' directory.#    In the following example, I named the data training-*, test-*, etc.#    If your data files have different names, update the --data_path.#    If you don't have data but want to try out the model, copy the toy#    data from the textsum/data/data to the data/ directory in the workspace.

上面大意是: 创建工作目录mkdir test_dir; 创建空白文件 touch WORKSPACE; 在test_dir中创建data数据目录(存放training-*, test-*数据,vocab); copy训练数据和测试数据到data目录


第二步: $ bazel build -c opt --config=cuda textsum/...


# Run the training.
$ bazel-bin/textsum/seq2seq_attention \
    --mode=train \
    --article_key=article \        ### 
    --abstract_key=abstract \    ###
    --data_path=data/training-* \      ### 更改对应的训练数据文件路径
    --vocab_path=data/vocab \        ### 类似于dic
    --log_root=textsum/log_root \
    --train_dir=textsum/log_root/train


# Run the eval. Try to avoid running on the same machine as training.
$ bazel-bin/textsum/seq2seq_attention \
    --mode=eval \
    --article_key=article \
    --abstract_key=abstract \
    --data_path=data/validation-* \
    --vocab_path=data/vocab \  
    --log_root=textsum/log_root \
    --eval_dir=textsum/log_root/eval


# Run the decode. Run it when the most is mostly converged.
$ bazel-bin/textsum/seq2seq_attention \
    --mode=decode \
    --article_key=article \
    --abstract_key=abstract \
    --data_path=data/test-* \
    --vocab_path=data/vocab \
    --log_root=textsum/log_root \
    --decode_dir=textsum/log_root/decode \
    --beam_size=8


2,使用bazel编译环境:

第一步:创建WORKSPACE文件:

touch WORKSPACE

第二步:创建一个BUILD文件:vim BUILD 

genrule(
  name = "hello",
  outs = ["hello_world.txt"],
  cmd = "echo Hello World > $@",
)

第三步: 

bazel build :hello  ### 注意build 后面有一个空格

最后结果如下:

lrwxrwxrwx 1 root root 110 4月   5 20:30 bazel-bin -> /root/.cache/bazel/_bazel_root/606cbeb4ca65a774eeb20cb68b5d2d4b/test_bazel/bazel-out/local_linux-fastbuild/bin
lrwxrwxrwx 1 root root 115 4月   5 20:30 bazel-genfiles -> /root/.cache/bazel/_bazel_root/606cbeb4ca65a774eeb20cb68b5d2d4b/test_bazel/bazel-out/local_linux-fastbuild/genfiles
lrwxrwxrwx 1 root root  84 4月   5 20:30 bazel-out -> /root/.cache/bazel/_bazel_root/606cbeb4ca65a774eeb20cb68b5d2d4b/test_bazel/bazel-out
lrwxrwxrwx 1 root root  74 4月   5 20:30 bazel-test_bazel -> /root/.cache/bazel/_bazel_root/606cbeb4ca65a774eeb20cb68b5d2d4b/test_bazel
lrwxrwxrwx 1 root root 115 4月   5 20:30 bazel-testlogs -> /root/.cache/bazel/_bazel_root/606cbeb4ca65a774eeb20cb68b5d2d4b/test_bazel/bazel-out/local_linux-fastbuild/testlogs
-rwxr-xr-x 1 root root  92 4月   5 20:22 BUILD
-rw-r--r-- 1 root root   0 4月   5 19:15 WORKSPACE


bazel相关命令: https://bazel.build/versions/master/docs/bazel-user-manual.html


Tensorflow 自动文摘: 基于Seq2Seq+Attention模型的Textsum模型

http://blog.csdn.net/rockingdingo/article/details/55224282


2 0
原创粉丝点击