MCPcopy Create free account
hub / github.com/RozDavid/UnScene3D / FreeMaskPreprocessing

Class FreeMaskPreprocessing

datasets/preprocessing/arkit_preprocessing.py:15–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13from utils.point_cloud_utils import load_ply_with_normals
14
15class FreeMaskPreprocessing(BasePreprocessing):
16
17 FREEMASK_CLASS_IDS = (0, 1)
18 FREEMASK_CLASS_NAMES = ('background', 'foreground')
19 FREEMASK_COLOR_MAP = {0: (0, 0, 0), 1: (0, 0, 128)}
20
21 def __init__(
22 self,
23 data_dir: str = "data/Datasets/ArKitScenes",
24 save_dir: str = "data/processed/unscene3d_arkit",
25 modes: tuple = ("train", "validation"),
26 n_jobs: int = 8,
27 freemask_dir: str = "data/Datasets/ArKitScenes"):
28
29 super().__init__(data_dir, save_dir, modes, n_jobs)
30
31 self.create_label_database()
32 self.freemask_base_path = Path(freemask_dir)
33
34 for mode in self.modes:
35 trainval_split_dir = data_dir / Path("split")
36 with open(trainval_split_dir / f"{mode}.txt") as f:
37 split_file = f.read().split("\n")[:-1]
38
39 scans_folder = "freemask"
40 filepaths = []
41 for scene in split_file:
42 filepaths.append(self.data_dir / scans_folder / f'{scene}_cloud.npy')
43 self.files[mode] = natsorted(filepaths)
44
45 def create_label_database(self):
46 label_database = {}
47 for row_id, class_id in enumerate(self.FREEMASK_CLASS_IDS):
48 label_database[class_id] = {
49 'color': self.FREEMASK_COLOR_MAP[class_id],
50 'name': self.FREEMASK_CLASS_NAMES[row_id],
51 'validation': True
52 }
53 self._save_yaml(self.save_dir / "label_database.yaml", label_database)
54 return label_database
55
56 def load_ply_cloud_with_normals(self, filepath):
57
58 # load cloud
59 cloud = o3d.io.read_point_cloud(str(filepath))
60
61 # estimate normals
62 cloud.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.1, max_nn=30))
63
64 vertices = np.asarray(cloud.points)
65 normals = np.asarray(cloud.normals)
66 feats = np.asarray(cloud.colors)
67 feats = np.hstack((feats, normals))
68 labels = np.zeros(len(vertices), dtype=np.int32)
69
70 return vertices, feats, labels
71
72 def process_file(self, filepath, mode):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected