├── .idea
├── .gitignore
├── misc.xml
├── inspectionProfiles
│ └── profiles_settings.xml
├── modules.xml
└── BAF-LAC.iml
├── imgs
└── BAF-LAC.jpg
├── utils
├── cpp_wrappers
│ ├── compile_wrappers.sh
│ ├── cpp_subsampling
│ │ ├── setup.py
│ │ ├── grid_subsampling
│ │ │ ├── grid_subsampling.h
│ │ │ └── grid_subsampling.cpp
│ │ └── wrapper.cpp
│ └── cpp_utils
│ │ └── cloud
│ │ ├── cloud.cpp
│ │ └── cloud.h
├── meta
│ ├── class_names.txt
│ └── anno_paths.txt
├── nearest_neighbors
│ ├── test.py
│ ├── setup.py
│ ├── knn_.h
│ ├── knn.pyx
│ ├── knn_.cxx
│ └── KDTreeTableAdaptor.h
├── 6_fold_cv.py
├── data_prepare_s3dis.py
├── data_prepare_semantickitti.py
├── data_prepare_semantic3d.py
├── download_semantic3d.sh
└── semantic-kitti.yaml
├── compile_op.sh
├── helper_requirements.txt
├── jobs_6_fold_cv_s3dis.sh
├── jobs_test_semantickitti.sh
├── README.md
├── tester_Semantic3D.py
├── tester_S3DIS.py
├── helper_tf_util.py
├── tester_SemanticKITTI.py
├── helper_ply.py
├── LICENSE
├── main_SemanticKITTI.py
├── main_S3DIS.py
├── helper_tool.py
├── main_Semantic3D.py
└── BAF_LAC.py
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/imgs/BAF-LAC.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiangxu-0103/BAF-LAC/HEAD/imgs/BAF-LAC.jpg
--------------------------------------------------------------------------------
/utils/cpp_wrappers/compile_wrappers.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Compile cpp subsampling
4 | cd cpp_subsampling
5 | python3 setup.py build_ext --inplace
6 | cd ..
7 |
--------------------------------------------------------------------------------
/compile_op.sh:
--------------------------------------------------------------------------------
1 | cd utils/nearest_neighbors
2 | python setup.py install --home="."
3 | cd ../../
4 |
5 | cd utils/cpp_wrappers
6 | sh compile_wrappers.sh
7 | cd ../../../
8 |
--------------------------------------------------------------------------------
/utils/meta/class_names.txt:
--------------------------------------------------------------------------------
1 | ceiling
2 | floor
3 | wall
4 | beam
5 | column
6 | window
7 | door
8 | table
9 | chair
10 | sofa
11 | bookcase
12 | board
13 | clutter
14 |
--------------------------------------------------------------------------------
/helper_requirements.txt:
--------------------------------------------------------------------------------
1 | numpy==1.16.1
2 | h5py==2.10.0
3 | cython==0.29.15
4 | open3d-python==0.3.0
5 | pandas==0.25.3
6 | scikit-learn==0.21.3
7 | scipy==1.4.1
8 | PyYAML==5.1.2
9 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/BAF-LAC.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/utils/nearest_neighbors/test.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import lib.python.nearest_neighbors as nearest_neighbors
3 | import time
4 |
5 | batch_size = 16
6 | num_points = 81920
7 | K = 16
8 | pc = np.random.rand(batch_size, num_points, 3).astype(np.float32)
9 |
10 | # nearest neighbours
11 | start = time.time()
12 | neigh_idx = nearest_neighbors.knn_batch(pc, pc, K, omp=True)
13 | print(time.time() - start)
14 |
--------------------------------------------------------------------------------
/utils/nearest_neighbors/setup.py:
--------------------------------------------------------------------------------
1 | from distutils.core import setup
2 | from distutils.extension import Extension
3 | from Cython.Distutils import build_ext
4 | import numpy
5 |
6 |
7 | ext_modules = [Extension(
8 | "nearest_neighbors",
9 | sources=["knn.pyx", "knn_.cxx"], # source file(s)
10 | include_dirs=["./", numpy.get_include()],
11 | language="c++",
12 | extra_compile_args=["-std=c++11", "-fopenmp"],
13 | extra_link_args=["-std=c++11", '-fopenmp'],
14 | )]
15 |
16 | setup(
17 | name="KNN NanoFLANN",
18 | ext_modules=ext_modules,
19 | cmdclass={'build_ext': build_ext},
20 | )
21 |
--------------------------------------------------------------------------------
/utils/cpp_wrappers/cpp_subsampling/setup.py:
--------------------------------------------------------------------------------
1 | from distutils.core import setup, Extension
2 | import numpy.distutils.misc_util
3 |
4 | # Adding OpenCV to project
5 | # ************************
6 |
7 | # Adding sources of the project
8 | # *****************************
9 |
10 | m_name = "grid_subsampling"
11 |
12 | SOURCES = ["../cpp_utils/cloud/cloud.cpp",
13 | "grid_subsampling/grid_subsampling.cpp",
14 | "wrapper.cpp"]
15 |
16 | module = Extension(m_name,
17 | sources=SOURCES,
18 | extra_compile_args=['-std=c++11',
19 | '-D_GLIBCXX_USE_CXX11_ABI=0'])
20 |
21 | setup(ext_modules=[module], include_dirs=numpy.distutils.misc_util.get_numpy_include_dirs())
22 |
--------------------------------------------------------------------------------
/jobs_6_fold_cv_s3dis.sh:
--------------------------------------------------------------------------------
1 | python -B main_S3DIS.py --gpu 0 --mode train --test_area 1
2 | python -B main_S3DIS.py --gpu 0 --mode test --test_area 1
3 | python -B main_S3DIS.py --gpu 0 --mode train --test_area 2
4 | python -B main_S3DIS.py --gpu 0 --mode test --test_area 2
5 | python -B main_S3DIS.py --gpu 0 --mode train --test_area 3
6 | python -B main_S3DIS.py --gpu 0 --mode test --test_area 3
7 | python -B main_S3DIS.py --gpu 0 --mode train --test_area 4
8 | python -B main_S3DIS.py --gpu 0 --mode test --test_area 4
9 | python -B main_S3DIS.py --gpu 0 --mode train --test_area 5
10 | python -B main_S3DIS.py --gpu 0 --mode test --test_area 5
11 | python -B main_S3DIS.py --gpu 0 --mode train --test_area 6
12 | python -B main_S3DIS.py --gpu 0 --mode test --test_area 6
13 |
--------------------------------------------------------------------------------
/jobs_test_semantickitti.sh:
--------------------------------------------------------------------------------
1 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 11
2 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 12
3 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 13
4 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 14
5 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 15
6 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 16
7 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 17
8 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 18
9 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 19
10 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 20
11 | python -B main_SemanticKITTI.py --gpu 0 --mode test --test_area 21
12 |
--------------------------------------------------------------------------------
/utils/nearest_neighbors/knn_.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #include
4 | void cpp_knn(const float* points, const size_t npts, const size_t dim,
5 | const float* queries, const size_t nqueries,
6 | const size_t K, long* indices);
7 |
8 | void cpp_knn_omp(const float* points, const size_t npts, const size_t dim,
9 | const float* queries, const size_t nqueries,
10 | const size_t K, long* indices);
11 |
12 |
13 | void cpp_knn_batch(const float* batch_data, const size_t batch_size, const size_t npts, const size_t dim,
14 | const float* queries, const size_t nqueries,
15 | const size_t K, long* batch_indices);
16 |
17 | void cpp_knn_batch_omp(const float* batch_data, const size_t batch_size, const size_t npts, const size_t dim,
18 | const float* queries, const size_t nqueries,
19 | const size_t K, long* batch_indices);
20 |
21 | void cpp_knn_batch_distance_pick(const float* batch_data, const size_t batch_size, const size_t npts, const size_t dim,
22 | float* queries, const size_t nqueries,
23 | const size_t K, long* batch_indices);
24 |
25 | void cpp_knn_batch_distance_pick_omp(const float* batch_data, const size_t batch_size, const size_t npts, const size_t dim,
26 | float* batch_queries, const size_t nqueries,
27 | const size_t K, long* batch_indices);
28 |
--------------------------------------------------------------------------------
/utils/cpp_wrappers/cpp_utils/cloud/cloud.cpp:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | // 0==========================0
4 | // | Local feature test |
5 | // 0==========================0
6 | //
7 | // version 1.0 :
8 | // >
9 | //
10 | //---------------------------------------------------
11 | //
12 | // Cloud source :
13 | // Define usefull Functions/Methods
14 | //
15 | //----------------------------------------------------
16 | //
17 | // Hugues THOMAS - 10/02/2017
18 | //
19 |
20 |
21 | #include "cloud.h"
22 |
23 |
24 | // Getters
25 | // *******
26 |
27 | PointXYZ max_point(std::vector points)
28 | {
29 | // Initiate limits
30 | PointXYZ maxP(points[0]);
31 |
32 | // Loop over all points
33 | for (auto p : points)
34 | {
35 | if (p.x > maxP.x)
36 | maxP.x = p.x;
37 |
38 | if (p.y > maxP.y)
39 | maxP.y = p.y;
40 |
41 | if (p.z > maxP.z)
42 | maxP.z = p.z;
43 | }
44 |
45 | return maxP;
46 | }
47 |
48 | PointXYZ min_point(std::vector points)
49 | {
50 | // Initiate limits
51 | PointXYZ minP(points[0]);
52 |
53 | // Loop over all points
54 | for (auto p : points)
55 | {
56 | if (p.x < minP.x)
57 | minP.x = p.x;
58 |
59 | if (p.y < minP.y)
60 | minP.y = p.y;
61 |
62 | if (p.z < minP.z)
63 | minP.z = p.z;
64 | }
65 |
66 | return minP;
67 | }
68 |
--------------------------------------------------------------------------------
/utils/cpp_wrappers/cpp_subsampling/grid_subsampling/grid_subsampling.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #include "../../cpp_utils/cloud/cloud.h"
4 |
5 | #include
6 | #include
7 |
8 | using namespace std;
9 |
10 | class SampledData
11 | {
12 | public:
13 |
14 | // Elements
15 | // ********
16 |
17 | int count;
18 | PointXYZ point;
19 | vector features;
20 | vector> labels;
21 |
22 |
23 | // Methods
24 | // *******
25 |
26 | // Constructor
27 | SampledData()
28 | {
29 | count = 0;
30 | point = PointXYZ();
31 | }
32 |
33 | SampledData(const size_t fdim, const size_t ldim)
34 | {
35 | count = 0;
36 | point = PointXYZ();
37 | features = vector(fdim);
38 | labels = vector>(ldim);
39 | }
40 |
41 | // Method Update
42 | void update_all(const PointXYZ p, vector::iterator f_begin, vector::iterator l_begin)
43 | {
44 | count += 1;
45 | point += p;
46 | transform (features.begin(), features.end(), f_begin, features.begin(), plus());
47 | int i = 0;
48 | for(vector::iterator it = l_begin; it != l_begin + labels.size(); ++it)
49 | {
50 | labels[i][*it] += 1;
51 | i++;
52 | }
53 | return;
54 | }
55 | void update_features(const PointXYZ p, vector::iterator f_begin)
56 | {
57 | count += 1;
58 | point += p;
59 | transform (features.begin(), features.end(), f_begin, features.begin(), plus());
60 | return;
61 | }
62 | void update_classes(const PointXYZ p, vector::iterator l_begin)
63 | {
64 | count += 1;
65 | point += p;
66 | int i = 0;
67 | for(vector::iterator it = l_begin; it != l_begin + labels.size(); ++it)
68 | {
69 | labels[i][*it] += 1;
70 | i++;
71 | }
72 | return;
73 | }
74 | void update_points(const PointXYZ p)
75 | {
76 | count += 1;
77 | point += p;
78 | return;
79 | }
80 | };
81 |
82 |
83 |
84 | void grid_subsampling(vector& original_points,
85 | vector& subsampled_points,
86 | vector& original_features,
87 | vector& subsampled_features,
88 | vector& original_classes,
89 | vector& subsampled_classes,
90 | float sampleDl,
91 | int verbose);
92 |
--------------------------------------------------------------------------------
/utils/6_fold_cv.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import glob, os, sys
3 |
4 | BASE_DIR = os.path.dirname(os.path.abspath(__file__))
5 | ROOT_DIR = os.path.dirname(BASE_DIR)
6 | sys.path.append(ROOT_DIR)
7 | from helper_ply import read_ply
8 | from helper_tool import Plot
9 |
10 |
11 | if __name__ == '__main__':
12 | base_dir = '/home/data/S3DIS/results'
13 | original_data_dir = '/home/data/S3DIS/original_ply'
14 | data_path = glob.glob(os.path.join(base_dir, '*.ply'))
15 | data_path = np.sort(data_path)
16 |
17 | test_total_correct = 0
18 | test_total_seen = 0
19 | gt_classes = [0 for _ in range(13)]
20 | positive_classes = [0 for _ in range(13)]
21 | true_positive_classes = [0 for _ in range(13)]
22 | visualization = False
23 |
24 | for file_name in data_path:
25 | pred_data = read_ply(file_name)
26 | pred = pred_data['pred']
27 | original_data = read_ply(os.path.join(original_data_dir, file_name.split('/')[-1][:-4] + '.ply'))
28 | labels = original_data['class']
29 | points = np.vstack((original_data['x'], original_data['y'], original_data['z'])).T
30 |
31 | ##################
32 | # Visualize data #
33 | ##################
34 | if visualization:
35 | colors = np.vstack((original_data['red'], original_data['green'], original_data['blue'])).T
36 | xyzrgb = np.concatenate([points, colors], axis=-1)
37 | Plot.draw_pc(xyzrgb) # visualize raw point clouds
38 | Plot.draw_pc_sem_ins(points, labels) # visualize ground-truth
39 | Plot.draw_pc_sem_ins(points, pred) # visualize prediction
40 |
41 | correct = np.sum(pred == labels)
42 | print(str(file_name.split('/')[-1][:-4]) + '_acc:' + str(correct / float(len(labels))))
43 | test_total_correct += correct
44 | test_total_seen += len(labels)
45 |
46 | for j in range(len(labels)):
47 | gt_l = int(labels[j])
48 | pred_l = int(pred[j])
49 | gt_classes[gt_l] += 1
50 | positive_classes[pred_l] += 1
51 | true_positive_classes[gt_l] += int(gt_l == pred_l)
52 |
53 | iou_list = []
54 | for n in range(13):
55 | iou = true_positive_classes[n] / float(gt_classes[n] + positive_classes[n] - true_positive_classes[n])
56 | iou_list.append(iou)
57 | mean_iou = sum(iou_list) / 13.0
58 | print('eval accuracy: {}'.format(test_total_correct / float(test_total_seen)))
59 | print('mean IoU: {}'.format(mean_iou))
60 | print(iou_list)
61 |
62 | acc_list = []
63 | for n in range(13):
64 | acc = true_positive_classes[n] / float(gt_classes[n])
65 | acc_list.append(acc)
66 | mean_acc = sum(acc_list) / 13.0
67 | print('mAcc value is: {}'.format(mean_acc))
68 |
--------------------------------------------------------------------------------
/utils/cpp_wrappers/cpp_utils/cloud/cloud.h:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | // 0==========================0
4 | // | Local feature test |
5 | // 0==========================0
6 | //
7 | // version 1.0 :
8 | // >
9 | //
10 | //---------------------------------------------------
11 | //
12 | // Cloud header
13 | //
14 | //----------------------------------------------------
15 | //
16 | // Hugues THOMAS - 10/02/2017
17 | //
18 |
19 |
20 | # pragma once
21 |
22 | #include
23 | #include
24 | #include