记录用bazel编译tensorflow源码

1、各软件版本

ubuntu18.04

cuda10.0+cudnn7.6

tensorflow-1.15.5

bazel-0.26.1

python3.7(anaconda)

gcc\g++ 7.5.0

本博客参考:https://blog.csdn.net/weixin_43056275/article/details/105124979

 

2、准备

(1)卸载与安装bazel

因为之前安装了bazel,但是tensorflow1.15.5运行./configure时明确的说要0.26.1或更早版本的bazel;

卸载:

rm -rf ~/.bazel
rm -rf /home/lzc/bin

安装(参考我之前的博客https://blog.csdn.net/luozhichengaichenlei/article/details/117263003):

./bazel-0.26.1-installer-linux-x86_64.sh --user
sudo gedit ~/.bashrc
export PATH="$PATH:/home/lzc/bin"
source ~/.bashrc

 

(2)tensorflow configure

下载tensorflow源码,网址:https://codeload.github.com/tensorflow/tensorflow/zip/refs/tags/v1.15.5,解压后进入tensorflow-1.15.5目录下,执行:

./configure

然后会有很多选项,或者路径选择,遇到路径就直接回车,选项除了“CUDA support”选y,其余的都选n。

 

3、开始编译

bazel build --config=opt tensorflow/python/tools:freeze_graph
bazel build --config=opt tensorflow/lite/toco:toco
bazel build --config=opt tensorflow/lite/python:tflite_convert

 

4、踩坑记录(这才是我写博客的真正原因)

(1)网络问题, 一些package not found或者下载不下来

解决措施, 搭建本地服务器, 手动下载所需要的文件, 放在本地, 无需联网下载;

先安装服务器

sudo apt-get install nginx-light
sudo service nginx start

之后打开浏览器输入http://127.0.0.1看到Welcome to nginx!之类的内容就说明安装成功了。

然后根据编译时候报错,哪个文件下载不下来,就去手动下载,然后拷贝到/var/www/html/路径下;

使用grep -R xxx命令来找到哪个文件去下载包,然后把本地路径加入,

以grpc为例子,找到以下代码, 将本地路径加到url第一行:

   # WARNING: make sure ncteisen@ and vpai@ are cc-ed on any CL to change the below rule
   tf_http_archive(
       name = "grpc",
       sha256 = "1aa84387232dda273ea8fdfe722622084f72c16f7b84bfc519ac7759b71cdc91",
       strip_prefix = "grpc-69b6c047bc767b4d80e7af4d00ccb7c45b683dae",
       system_build_file = clean_dep("//third_party/systemlibs:grpc.BUILD"),
       urls = [
           "http://127.0.0.1/grpc-69b6c047bc767b4d80e7af4d00ccb7c45b683dae.tar.gz",
           "https://mirror.bazel.build/github.com/grpc/grpc/archive/69b6c047bc767b4d80e7af4d00ccb7c45b683dae.tar.gz",
           "https://github.com/grpc/grpc/archive/69b6c047bc767b4d80e7af4d00ccb7c45b683dae.tar.gz",
       ],
   )

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值