Pointnet++ 编译 tf_ops 遇到的问题及解决办法

Pointnet++ 编译 tf_ops 遇到的问题及解决办法

pointnet++在pointnet 的基础上,提出了一个分层特征提取方法。其中涉及到采样(sampling layer),分组(grouping layer)和插值(interpolation layer)操作。再复现其代码时,最主要的问题就是集中在对上述三种操作的代码编译生成“xxxxxxx_so.so”文件。
在这里插入图片描述在这里插入图片描述

1、修改编译文件,以“/samping/tf_sampling_compile.sh”为例

  • Github 上提供的源代码如下,有TF1.2和TF1.4两种版本
#/bin/bash
/usr/local/cuda-8.0/bin/nvcc tf_sampling_g.cu -o tf_sampling_g.cu.o -c -O2 -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC

# TF1.2
g++ -std=c++11 tf_sampling.cpp tf_sampling_g.cu.o -o tf_sampling_so.so -shared -fPIC -I /usr/local/lib/python2.7/dist-packages/tensorflow/include -I /usr/local/cuda-8.0/include -lcudart -L /usr/local/cuda-8.0/lib64/ -O2 -D_GLIBCXX_USE_CXX11_ABI=0

# TF1.4
#g++ -std=c++11 tf_sampling.cpp tf_sampling_g.cu.o -o tf_sampling_so.so -shared -fPIC -I /usr/local/lib/python2.7/dist-packages/tensorflow/include -I /usr/local/cuda-8.0/include -I /usr/local/lib/python2.7/dist-packages/tensorflow/include/external/nsync/public -lcudart -L /usr/local/cuda-8.0/lib64/ -L/usr/local/lib/python2.7/dist-packages/tensorflow -ltensorflow_framework -O2 -D_GLIBCXX_USE_CXX11_ABI=0
  • 为了减少改动,将代码中的CUDA路径和版本改成自己环境的版本,同时将路径用变量表示,替换源代码如下:
#/bin/bash
CUDA_ROOT=/usr/local/cuda-9.0
TF_ROOT=/home/sgl/anaconda3/envs/sgl/lib/python3.7/site-packages/tensorflow
/usr/local/cuda-9.0/bin/nvcc -std=c++11 -c -o tf_sampling_g.cu.o tf_sampling_g.cu -O2 -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC

#TF xxx.xxx
g++ -std=c++11 tf_sampling.cpp tf_sampling_g.cu.o -o tf_sampling_so.so -shared -fPIC -I ${TF_ROOT}/include -I ${CUDA_ROOT}/include -I ${TF_ROOT}/include/external/nsync/public -lcudart -L ${CUDA_ROOT}/lib64/ -L ${TF_ROOT} -ltensorflow_framework -O2 #-D_GLIBCXX_USE_CXX11_ABI=0

查看CUDA版本方法:

cat /usr/local/cuda/version.txt

在这里插入图片描述
查看TensorFlow版本和路径方法:

source activate xxxx
python
import tensorflow as tf
tf.__version__
tf.__path__

在这里插入图片描述

2、编译代码

在‘ .sh ’文件夹下打开中端,激活环境

source activate xxxxx
sh tf_sampling_compile.sh

如果生成了“tf_sampling_so.so”文件则编译成功,如上过程编译其它的两种操作。

3、特别提醒

TensorFlow如果使用最新的版本 1.14.0 在编译过程会报错

/usr/bin/x86_64-linux-gnu-ld: 找不到 -ltensorflow_framework
collect2: error: ld returned 1 exit status

原因是版本1.14.0中将文件“tensorflow_framework.so”改成了“tensorflow_framework.so.1”
为了避免不必要的版本麻烦,我从新建立了一个环境版本是1.13.1,解决问题
应该只要TensorFlow版本不大于 1.14.0 上述过程应该能有所帮助

  • 11
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
TensorFlow是一个非常强大的深度学习框架,支持的操作非常多,但有时某些特殊的操作没有被包含在标准库中,需要使用者自己手动编译代码。如果想在Winodws系统下编译tf_ops,需要遵循以下步骤: 1. 安装Visual Studio Visual Studio是一个从微软公司发布的IDE,用来开发、调试和部署Windows程序,其中包括了C++编译器。由于TensorFlow是用C++实现的,所以需要安装Visual Studio。在Windows下,可以前往微软官网下载最新的Visual Studio Community版本,按照安装向导进行安装即可。 2. 安装CUDA CUDA是NVIDIA发布的一款并行计算平台和编程模型,是TensorFlow的必要条件。需要选择与显卡硬件相适应的CUDA版本,并安装后加入环境变量PATH。 3. 安装cuDNN cuDNN是NVIDIA针对深度神经网络运算的加速库,可以提高TensorFlow的计算效率。需要到NVIDIA官网注册后下载与CUDA版本相匹配的cuDNN,并添加到环境变量PATH。 4. 编译代码 首先需要下载TensorFlow源代码,然后在命令行窗口进入到该源代码目录中。执行以下命令: ```bash cd tensorflow # 进入到源代码目录 bazel build -c opt --config=cuda //tensorflow/core/user_ops:path/to/user_ops ``` 其中`path/to/user_ops`需要被替换成自己存放user ops代码的目录。此命令会自动编译user ops的源代码并生成.so文件,可以用于TensorFlow的其他程序中使用。 总之,Windwos下编译tf_ops需要安装Visual Studio、CUDA和cuDNN,并按照TensorFlow官方文档中的步骤进行编译即可。
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值