PointSIFT尝鲜

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Felaim/article/details/81088936

之前也做过点云处理,但用的都是传统的方法,比如说进行平面拟和,有很老的region grow, random seed或者利用层次聚类进行,计算对应法线之类的,这个PointSIFT首先比较吸引LZ的是好多公众号都在报导,在Scannet数据集上效果非常好。二来,也有一定时间没接触深度学习了,tensorflow之类的了,找一个开源的代码读读,回忆回忆。有可能再修改改??

贴出具体论文的信息:

论文:PointSIFT: A SIFT-like Network Module for 3D Point Cloud Semantic Segmentation

论文作者:Mingyang Jiang、Yiran Wu、Cewu Lu (通讯作者)

阅读论文:arXiv:1807.00652, 2018;https://arxiv.org/abs/1807.00652

论文主页:http://www.mvig.org/publications/pointSIFT.html

代码链接:https://github.com/MVIG-SJTU/pointSIFT

放张论文的效果图先吸引下眼球!

这里写图片描述

首先要进行安装,基本的环境得有啊!看到PointSIFT,不禁吸了一口气,怕是没有GPU是扛不住了。。。

有些README.md有的 LZ就直接粘贴了,但是有不一致的地方LZ也会进行补充说明的!好久没用tensorflow了,好激动O(∩_∩)O哈哈~

Installation

In our experiment, All the codes are tested in Python3.5(If you use Python 2.7, please add some system paths), CUDA 8.0 and CUDNN 5.1. 之前运气很好,配置的环境基本都是相同的。正常的安装CUDA 8.0和CUDA 5.1这个是基本配置啦,好多博客都有介绍,LZ就不再赘述了。唯一不同的是LZ使用的是Python2.7版本的。

因为在跑程序,所以内存用的比较多

这里写图片描述

  1. Install TensorFlow (We use v1.4.1).安装tensorflow这个很简单,因为LZ是python2.7,还是习惯使用1.2.0版本的,所以安装的是1.2.0.
    这里写图片描述
    具体的显示如图
sudo pip install tensorflow-gpu==1.2.0

可能会报如下的问题:

Could not find any downloads that satisfy the requirement tensorflow 

这个很方便解决的,update一下对应的pip

pip install -U pip
  1. Install other python libraries like h5py 这个看着安装就行,缺什么sudo pip install就行了

  2. Compile TF operator (Similar to PointNet++). Firstly, you should find Tensorflow include path and library paths.

    import tensorflow as tf
    # include path
    print(tf.sysconfig.get_include())
    # library path 
    print(tf.sysconfig.get_lib())

这个主要是查找一下你的机器上tensorflow的路径的。

这里写图片描述

Then, change the path in all the complie file, like tf_utils/tf_ops/sampling/tf_sampling_compile.sh
Finally, compile the source file, we use tf_sampling as example.

    cd tf_utils/tf_ops/sampling
    chmod +x tf_sampling_compile.sh
    ./tf_sampling_compile.sh

然后对应改就行了,查一下有多少个*.sh,把里面对应的tensorflow的路径改一下就行了,这里贴出其中一个:

tf_sampling_compile.sh

#/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 /home/jmydurant/anaconda3/envs/pointsift/lib/python3.5/site-packages/tensorflow/include -I /usr/local/cuda-8.0/include -I /home/jmydurant/anaconda3/envs/pointsift/lib/python3.5/site-packages/tensorflow/include/external/nsync/public -lcudart -L /usr/local/cuda-8.0/lib64/ -L/home/jmydurant/anaconda3/envs/pointsift/lib/python3.5/site-packages/tensorflow -ltensorflow_framework -O2 -D_GLIBCXX_USE_CXX11_ABI=0

在运行./*.sh,如果报找不到tensorflow的头文件的时候,就要考虑一下你的路径写对了O(∩_∩)O哈哈~

如报如下的错误:

tf_grouping.cpp:6:42: fatal error: tensorflow/core/framework/op.h: No such file or directory #include "tensorflow/core/framework/op.h"

全部完成后就可以进行使用了

Usage

If you want use our model in your own project. After compiling the TF operator, you can import it easily. Here shows a simple case.(we take batch_size * num_point * input_dim as input and get batch_size * num_point * output_dim as output)

import tensorflow as tf
# import our module
from tf_utils.pointSIFT_util import pointSIFT_module
# input coordinates
xyz = tf.tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
# input features
point_feature = tf.tf.placeholder(tf.float32, shape=(batch_size, num_point, input_dim)
# setting phases
is_training = tf.placeholder(dtype=tf.bool, shape=())
# setting searching radius (0.1 as an example)
radius = 0.1
_, out_feature, _ = pointSIFT_module(xyz, point_feature, radius, output_dim, is_training)

LZ暂时还没想好使用这个,既然给出了在ScanNet上的train_and_eval_scannet.py那就试一下吧!

Training and evaluating on ScanNet

All the data can be download from here. They are the same as PointNet++.下载对应的数据集,比起图片动辄几十个G,1.8G对网速的要求还是很仁慈的。解压后如下图所示:

这里写图片描述

Train the data:

python train_and_eval_scannet.py

If you have multiple GPU:

CUDA_VISIBLE_DEVICES=0,1,2,3 python train_and_eval_scannet.py --gpu_num=4

其实在运行上述脚本还是会出现各种问题:

No module named tf_utils.provider

认真的嘛,认真,真的会报错!LZ估计刚开始这些代码是在一个文件夹下的,后来代码公布总得整齐点,让小伙伴们也好知道每块代码的作用,所以分到不同的文件夹下,但是却没有加一个__init__py的文件,所以导致tf_utils.provider这个模块没法找到。

LZ不会说自己傻傻的一直在pip中找这个模块,后来恍然大悟,这模块自己文件夹里就有啊( ⊙ o ⊙ )啊!

Couldn’t import dot_parser, loading of dot files will not be possible.

这个是pyparsing和pydot版本不兼容的问题

直接卸载了重新安装一下就行

//卸载
sudo pip uninstall pyparsing
sudo pip uninstall pydot

//安装
sudo pip install pyparsing
sudo pip install pydot

还有?有!
TypeError: load() got an unexpected keyword argument ‘encoding’

修改部分python代码,修改部分如下

import cPickle as pickle
            #self.scene_points_list = pickle.load(fp, encoding='bytes')
            #self.semantic_labels_list = pickle.load(fp, encoding='bytes')
            self.scene_points_list = pickle.load(fp)
            self.semantic_labels_list = pickle.load(fp)

然后就应该没有了,至少ScanNet的training和Evaluation是可以跑通的了

Resource exhausted: OOM when allocating tensor with shape[32,1024,8,256]

报这个错误字面上就可以理解,资源耗尽,把batch size改小点就行了!

这里写图片描述

电脑跑了一下午还在训练中,没法给效果啦~(≧▽≦)/~啦啦啦

参考博客:
1.https://stackoverflow.com/questions/15951748/pydot-and-graphviz-error-couldnt-import-dot-parser-loading-of-dot-files-will

2.https://blog.csdn.net/csdn_lisword/article/details/55506765

3.https://stackoverflow.com/questions/43895013/pickle-loading-cifar-100-data

4.https://blog.csdn.net/zsg2063/article/details/74332487

猜你喜欢

转载自blog.csdn.net/Felaim/article/details/81088936
今日推荐