[关闭]
@iStarLee 2020-04-23T23:43:36.000000Z 字数 4439 阅读 585

深度学习开发环境配置

Deep-Learning


1 查看版本号

查看 CUDA 版本:

  1. cat /usr/local/cuda/version.txt

查看 CUDNN 版本:

  1. cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

2 查找对应的匹配版本

这个在tensorflow-ros-cpp仓库的readme里面可以查看
image_1djtfi102duem3f1brq1mlv1bm59.png-35.2kB

image_1dk4l7t30614qct174713rthpj9.png-111.2kB

我们需要安装的软件如下

3 TensorFlow 源码编译安装

3.1 Install Bazel

https://docs.bazel.build/versions/master/install-ubuntu.html
注意Bazel的版本,一样可能出现问题,我选择了bazel0.16的release文件安装的
image_1djvji41d178b1mdsq395bj1hh39.png-16.7kB

  1. rm -rf ~/.bazel ~/.cache/bazel/ ~/bin

3.2 Install TensorFlow

3.2.1 安装python tensorflow

  1. sudo apt install python-dev python-pip # or python3-dev python3-pip
  2. pip install -U --user pip six numpy wheel setuptools mock 'future>=0.17.1'
  3. pip install -U --user keras_applications==1.0.6 --no-deps
  4. pip install -U --user keras_preprocessing==1.0.5 --no-deps
  1. cd tensorflow
  2. ./configure # 除了选择python版本,cuda点y之外,其他的都默认
  3. # 下面两个选择其中之一进行编译
  4. # 1 GPU suport
  5. bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
  6. bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so
  7. # 2 cpu only
  8. bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
  9. bazel build --config=opt //tensorflow:libtensorflow_cc.so
  1. bazel clean --expunge # 清除编译文件,重新来过
  1. bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/tensorflow_package
  2. # 安装
  3. pip3 install ~/tensorflow_package/file_name.whl
  1. #!/usr/bin/python3
  2. import tensorflow as tf
  3. hello = tf.constant('Hello, TensorFlow!')
  4. sess = tf.Session()
  5. print(sess.run(hello))

如果弹出以下文字

  1. usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.

说明是numpy版本和tensorflow版本不和,需要将numpy版本降级,降到1.6应该就ok了

  1. # 1. remove
  2. sudo apt-get remove python3-numpy
  3. # 2. install
  4. sudo python3 -m pip install numpy==1.16

3.2.2 安装tensorflow cpp lib

Install Reference

  1. ./tensorflow/contrib/makefile/download_dependencies.sh
  2. source tensorflow/contrib/makefile/build_all_linux.sh
  3. # protobuf
  4. mkdir /tmp/proto
  5. ./tensorflow/contrib/makefile/download_dependencies.sh
  6. cd tensorflow/contrib/makefile/downloads/protobuf/
  7. ./autogen.sh
  8. ./configure --prefix=/tmp/proto/
  9. make
  10. make install
  11. # eigen
  12. mkdir /tmp/eigen
  13. cd ../eigen
  14. mkdir build_dir
  15. cd build_dir
  16. cmake -DCMAKE_INSTALL_PREFIX=/tmp/eigen/ ../
  17. make install
  18. cd ../../../../../..
  1. # lib
  2. mkdir -p ../tf_test/lib
  3. cp bazel-bin/tensorflow/libtensorflow_cc.so ../tf_test/lib/
  4. cp bazel-bin/tensorflow/libtensorflow_framework.so ../tf_test/lib/ # 之前编译r0.12和r1.3版本的库,只需要libtensorflow_cc.so,1.4版本的似乎分成了两个so文件,即还需要libtensorflow_framework.so
  5. cp /tmp/proto/lib/libprotobuf.a ../tf_test/lib/
  6. # include
  7. mkdir -p ../tf_test/include/tensorflow
  8. cp -r bazel-genfiles/* ../tf_test/include/
  9. cp -r tensorflow/cc ../tf_test/include/tensorflow
  10. cp -r tensorflow/core ../tf_test/include/tensorflow
  11. cp -r third_party ../tf_test/include
  12. cp -r /tmp/proto/include/* ../tf_test/include
  13. cp -r /tmp/eigen/include/eigen3/* ../tf_test/include
  14. # nsync
  15. 门槛低人-跑
  16. cp -r tensorflow/contrib/makefile/downloads/nsync/public ../tf_test/include/external/nsync/public
  17. # 删除多余cc文件
  18. cd ../tf_test/
  19. find . -name "*.cc" -type f -delete
  1. cmake_minimum_required(VERSION 3.0)
  2. project(cpptensorflow)
  3. set(CMAKE_CXX_STANDARD 11)
  4. set(tensorflow_path /home/nrsl/Downloads/tf_test)
  5. link_directories(${tensorflow_path}/lib)
  6. include_directories(
  7. ${tensorflow_path}/include
  8. )
  9. add_executable(cpptensorflow main.cpp ann_model_loader.h model_loader_base.h ann_model_loader.cpp)
  10. target_link_libraries(cpptensorflow tensorflow_cc tensorflow_framework)

4 Using tensorflow ros cpp

一个傻逼的包,劳资不用你了,我自己链接我的程序,多好用!!

  1. pip install catkin_pkg empy pyyaml

测试tensorflow-ros-cpp安装是否成功
https://github.com/tradr-project/tensorflow_ros_test/tree/kinetic-devel

当然如果还是想要使用。。
编译方法如下,wiki链接

  1. catkin build tensorflow_ros_cpp --cmake-args -DFORCE_TF_PIP_SEARCH="ON" \
  2. -DTF_PYTHON_VERSION="python3" \
  3. -DTF_PIP_PATH="/usr/local/lib/python3.5/dist-packages/tensorflow" \
  4. -DTF_PIP_EXECUTABLE="/home/nrsl/.local/bin/pip3" \
  5. -DTF_PYTHON_LIBRARY="/usr/lib/x86_64-linux-gnu/libpython3.5m.so"

5 其他错误记录

  1. ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

这是因为链接库的时候找不到cuda9的库,

  1. sudo gedit /etc/ld.so.conf
  2. # 添加
  3. /usr/local/cuda-9.0/lib64
  4. # 生效
  5. sudo ldconfig
  1. # 找到pip3的安装位置, 比如我的是 /home/nrsl/.local/bin/pip3.5
  2. locate pip3
  3. # 建立软连接,这样就可以使用sudo pip-py3 install xx_pylib
  4. sudo ln -s /home/nrsl/.local/bin/pip3.5 /usr/local/bin/pip-py3
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注