-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathkpconv_tensorflow_mix3d.patch
212 lines (195 loc) · 9.43 KB
/
kpconv_tensorflow_mix3d.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
diff --git a/datasets/S3DIS.py b/datasets/S3DIS.py
index 78bba0a..e5eac6f 100755
--- a/datasets/S3DIS.py
+++ b/datasets/S3DIS.py
@@ -600,20 +600,34 @@ class S3DISDataset(Dataset):
# In case batch is full, yield it and reset it
if batch_n + n > self.batch_limit and batch_n > 0:
-
- yield (np.concatenate(p_list, axis=0),
- np.concatenate(c_list, axis=0),
- np.concatenate(pl_list, axis=0),
- np.array([tp.shape[0] for tp in p_list]),
- np.concatenate(pi_list, axis=0),
- np.array(ci_list, dtype=np.int32))
-
- p_list = []
- c_list = []
- pl_list = []
- pi_list = []
- ci_list = []
- batch_n = 0
+ if len(p_list) % 2 == 1:
+ yield (np.concatenate(p_list[:-1], axis=0),
+ np.concatenate(c_list[:-1], axis=0),
+ np.concatenate(pl_list[:-1], axis=0),
+ np.array([tp.shape[0] for tp in p_list[:-1]]),
+ np.concatenate(pi_list[:-1], axis=0),
+ np.array(ci_list[:-1], dtype=np.int32))
+
+ p_list = [p_list[-1]]
+ c_list = [c_list[-1]]
+ pl_list = [pl_list[-1]]
+ pi_list = [pi_list[-1]]
+ ci_list = [ci_list[-1]]
+ batch_n = pl_list[-1].shape[0]
+ else:
+ yield (np.concatenate(p_list, axis=0),
+ np.concatenate(c_list, axis=0),
+ np.concatenate(pl_list, axis=0),
+ np.array([tp.shape[0] for tp in p_list]),
+ np.concatenate(pi_list, axis=0),
+ np.array(ci_list, dtype=np.int32))
+
+ p_list = []
+ c_list = []
+ pl_list = []
+ pi_list = []
+ ci_list = []
+ batch_n = 0
# Add data to current batch
if n > 0:
@@ -626,13 +640,21 @@ class S3DISDataset(Dataset):
# Update batch size
batch_n += n
- if batch_n > 0:
- yield (np.concatenate(p_list, axis=0),
- np.concatenate(c_list, axis=0),
- np.concatenate(pl_list, axis=0),
- np.array([tp.shape[0] for tp in p_list]),
- np.concatenate(pi_list, axis=0),
- np.array(ci_list, dtype=np.int32))
+ if batch_n > 1:
+ if len(p_list) % 2 == 1 and len(p_list) != 1:
+ yield (np.concatenate(p_list[:-1], axis=0),
+ np.concatenate(c_list[:-1], axis=0),
+ np.concatenate(pl_list[:-1], axis=0),
+ np.array([tp.shape[0] for tp in p_list[:-1]]),
+ np.concatenate(pi_list[:-1], axis=0),
+ np.array(ci_list[:-1], dtype=np.int32))
+ else:
+ yield (np.concatenate(p_list, axis=0),
+ np.concatenate(c_list, axis=0),
+ np.concatenate(pl_list, axis=0),
+ np.array([tp.shape[0] for tp in p_list]),
+ np.concatenate(pi_list, axis=0),
+ np.array(ci_list, dtype=np.int32))
###################
# Choose generators
@@ -676,6 +698,15 @@ class S3DISDataset(Dataset):
# First add a column of 1 as feature for the network to be able to learn 3D shapes
stacked_features = tf.ones((tf.shape(stacked_points)[0], 1), dtype=tf.float32)
+
+ # IN BATCH GENERATOR MAKE SURE THAT ALWAYS EVEN
+ # last two spheres are never merged!
+ combined_lengths = tf.reduce_sum(tf.reshape(stacks_lengths[:-2], (-1, 2)), axis=1)
+ stacks_lengths = tf.concat([combined_lengths, stacks_lengths[-2:]], 0)
+
+ batch_inds = self.tf_get_batch_inds(stacks_lengths)
+
+
# Get coordinates and colors
stacked_original_coordinates = stacked_colors[:, 3:]
stacked_colors = stacked_colors[:, :3]
@@ -1085,3 +1116,4 @@ class S3DISDataset(Dataset):
+
diff --git a/datasets/Scannet.py b/datasets/Scannet.py
index 91c7097..10b04d4 100755
--- a/datasets/Scannet.py
+++ b/datasets/Scannet.py
@@ -144,6 +144,7 @@ class ScannetDataset(Dataset):
self.train_path = join(self.path, 'training_points')
self.test_path = join(self.path, 'test_points')
+
# Prepare ply files
self.prepare_pointcloud_ply()
@@ -752,19 +753,34 @@ class ScannetDataset(Dataset):
# In case batch is full, yield it and reset it
if batch_n + n > self.batch_limit and batch_n > 0:
- yield (np.concatenate(p_list, axis=0),
- np.concatenate(c_list, axis=0),
- np.concatenate(pl_list, axis=0),
- np.array([tp.shape[0] for tp in p_list]),
- np.concatenate(pi_list, axis=0),
- np.array(ci_list, dtype=np.int32))
-
- p_list = []
- c_list = []
- pl_list = []
- pi_list = []
- ci_list = []
- batch_n = 0
+ if len(p_list) % 2 == 0:
+ yield (np.concatenate(p_list[:-1], axis=0),
+ np.concatenate(c_list[:-1], axis=0),
+ np.concatenate(pl_list[:-1], axis=0),
+ np.array([tp.shape[0] for tp in p_list[:-1]]),
+ np.concatenate(pi_list[:-1], axis=0),
+ np.array(ci_list[:-1], dtype=np.int32))
+
+ p_list = [p_list[-1]]
+ c_list = [c_list[-1]]
+ pl_list = [pl_list[-1]]
+ pi_list = [pi_list[-1]]
+ ci_list = [ci_list[-1]]
+ batch_n = pl_list[-1].shape[0]
+ else:
+ yield (np.concatenate(p_list, axis=0),
+ np.concatenate(c_list, axis=0),
+ np.concatenate(pl_list, axis=0),
+ np.array([tp.shape[0] for tp in p_list]),
+ np.concatenate(pi_list, axis=0),
+ np.array(ci_list, dtype=np.int32))
+
+ p_list = []
+ c_list = []
+ pl_list = []
+ pi_list = []
+ ci_list = []
+ batch_n = 0
# Add data to current batch
if n > 0:
@@ -777,13 +793,21 @@ class ScannetDataset(Dataset):
# Update batch size
batch_n += n
- if batch_n > 0:
- yield (np.concatenate(p_list, axis=0),
- np.concatenate(c_list, axis=0),
- np.concatenate(pl_list, axis=0),
- np.array([tp.shape[0] for tp in p_list]),
- np.concatenate(pi_list, axis=0),
- np.array(ci_list, dtype=np.int32))
+ if batch_n > 1:
+ if len(p_list) % 2 == 0 and len(p_list) != 0:
+ yield (np.concatenate(p_list[:-1], axis=0),
+ np.concatenate(c_list[:-1], axis=0),
+ np.concatenate(pl_list[:-1], axis=0),
+ np.array([tp.shape[0] for tp in p_list[:-1]]),
+ np.concatenate(pi_list[:-1], axis=0),
+ np.array(ci_list[:-1], dtype=np.int32))
+ else:
+ yield (np.concatenate(p_list, axis=0),
+ np.concatenate(c_list, axis=0),
+ np.concatenate(pl_list, axis=0),
+ np.array([tp.shape[0] for tp in p_list]),
+ np.concatenate(pi_list, axis=0),
+ np.array(ci_list, dtype=np.int32))
###################
# Choose generators
@@ -826,6 +850,14 @@ class ScannetDataset(Dataset):
# First add a column of 1 as feature for the network to be able to learn 3D shapes
stacked_features = tf.ones((tf.shape(stacked_points)[0], 1), dtype=tf.float32)
+ # 2 UNMERGED
+ # IN BATCH GENERATOR MAKE SURE THAT ALWAYS EVEN
+ # last two spheres are never merged!
+ combined_lengths = tf.reduce_sum(tf.reshape(stacks_lengths[:-2], (-1, 2)), axis=1)
+ stacks_lengths = tf.concat([combined_lengths, stacks_lengths[-2:]], 0)
+
+ batch_inds = self.tf_get_batch_inds(stacks_lengths)
+
# Get coordinates and colors
stacked_original_coordinates = stacked_colors[:, 3:]
stacked_colors = stacked_colors[:, :3]
@@ -1235,3 +1267,4 @@ class ScannetDataset(Dataset):
print('\nFinished\n\n')
+