Skip to content

Commit c479412

Browse files
author
Fangchang Ma
committed
fixed bug with uniform random sampling for KITTI
1 parent dcf1937 commit c479412

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

dataloaders/dense_to_sparse.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ def dense_to_sparse(self, rgb, depth):
1616
def __repr__(self):
1717
pass
1818

19-
2019
class UniformSampling(DenseToSparse):
2120
name = "uar"
22-
2321
def __init__(self, num_samples, max_depth=np.inf):
2422
DenseToSparse.__init__(self)
2523
self.num_samples = num_samples
@@ -34,17 +32,15 @@ def dense_to_sparse(self, rgb, depth):
3432
Only pixels with a maximum depth of `max_depth` are considered.
3533
If no `max_depth` is given, samples in all pixels
3634
"""
35+
mask_keep = depth > 0
3736
if self.max_depth is not np.inf:
38-
mask_keep = depth <= self.max_depth
39-
n_keep = np.count_nonzero(mask_keep)
40-
if n_keep == 0:
41-
return mask_keep
42-
else:
43-
prob = float(self.num_samples) / n_keep
44-
return np.bitwise_and(mask_keep, np.random.uniform(0, 1, depth.shape) < prob)
37+
mask_keep = np.bitwise_and(mask_keep, depth <= self.max_depth)
38+
n_keep = np.count_nonzero(mask_keep)
39+
if n_keep == 0:
40+
return mask_keep
4541
else:
46-
prob = float(self.num_samples) / depth.size
47-
return np.random.uniform(0, 1, depth.shape) < prob
42+
prob = float(self.num_samples) / n_keep
43+
return np.bitwise_and(mask_keep, np.random.uniform(0, 1, depth.shape) < prob)
4844

4945

5046
class SimulatedStereo(DenseToSparse):

0 commit comments

Comments
 (0)