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",
],
)