单纯的想复制代码…
class SemanticDataset:
def __init__(
self, num_points_per_sample, split, use_color, box_size_x, box_size_y, path
):
# Dataset parameters
self.num_points_per_sample = num_points_per_sample
self.split = split
self.use_color = use_color
self.box_size_x = box_size_x
self.box_size_y = box_size_y
self.num_classes = 9
self.path = path
self.labels_names = [
"unlabeled",
"man-made terrain",
"natural terrain",
"high vegetation",
"low vegetation",
"buildings",
"hard scape",
"scanning artifact",
"cars",
]
# Get file_prefixes
file_prefixes = map_name_to_file_prefixes[self.split]
print("Dataset split:", self.split)
print("Loading file_prefixes:", file_prefixes)
# Load files
self.list_file_data = []
for file_prefix in file_prefixes:
file_path_without_ext = os.path.join(self.path, file_prefix)
file_data = SemanticFileData(
file_path_without_ext=file_path_without_ext,
has_label=self.split != "test",
use_color=self.use_color,
box_size_x=self.box_size_x,
box_size_y=self.box_size_y,
)
self.list_file_data.append(file_data)
# Pre-compute the probability of picking a scene
self.num_scenes = len(self.list_file_data)
self.scene_probas = [
len(fd.points) / self.get_total_num_points() for fd in self.list_file_data
]
# Pre-compute the points weights if it is a training set
if self.split == "train" or self.split == "train_full":
# First, compute the histogram of each labels
label_weights = np.zeros(9)
for labels in [fd.labels for fd in self.list_file_data]:
tmp, _ = np.histogram(labels, range(10))
label_weights += tmp
# Then, a heuristic gives the weights
# 1 / log(1.2 + probability of occurrence)
label_weights = label_weights.astype(np.float32)
label_weights = label_weights / np.sum(label_weights)
self.label_weights = 1 / np.log(1.2 + label_weights)
else:
self.label_weights = np.zeros(9)
读取数据集,for循环,对每个数据集都做以下提取操作
class SemanticFileData:
def __init__(
self, file_path_without_ext, has_label, use_color, box_size_x, box_size_y
):
"""
Loads file data
"""
self.file_path_without_ext = file_path_without_ext
self.box_size_x = box_size_x
self.box_size_y = box_size_y
# Load points
pcd = open3d.read_point_cloud(file_path_without_ext + ".pcd")
self.points = np.asarray(pcd.points)
# Load label. In pure test set, fill with zeros.
if has_label:
self.labels = load_labels(file_path_without_ext + ".labels")
else:
self.labels = np.zeros(len(self.points)).astype(bool)
# Load colors. If not use_color, fill with zeros.
if use_color:
self.colors = np.asarray(pcd.colors)
else:
self.colors = np.zeros_like(self.points)
# Sort according to x to speed up computation of boxes and z-boxes
sort_idx = np.argsort(self.points[:, 0])
self.points = self.points[sort_idx]
self.labels = self.labels[sort_idx]
self.colors = self.colors[sort_idx]
数据预处理,将坐标,标签,颜色,权重全部提取出来