| 12 | from utils.point_cloud_utils import load_ply_with_normals |
| 13 | |
| 14 | class FreeMaskPreprocessing(BasePreprocessing): |
| 15 | |
| 16 | FREEMASK_CLASS_IDS = (0, 1) |
| 17 | FREEMASK_CLASS_NAMES = ('background', 'foreground') |
| 18 | FREEMASK_COLOR_MAP = {0: (0, 0, 0), 1: (0, 0, 128)} |
| 19 | FREEMASK_ORACLE_CLASS_IDS = (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 24, 28, 33, 34, 36, 39) |
| 20 | |
| 21 | def __init__( |
| 22 | self, |
| 23 | data_dir: str = "/canis/Datasets/ScanNet/public/v2", |
| 24 | save_dir: str = "./data/processed/freemask", |
| 25 | modes: tuple = ("train", "validation"), |
| 26 | n_jobs: int = -1, |
| 27 | git_repo: str = "data/Datasets/ScanNet/ScanNet", |
| 28 | oracle: bool = False, |
| 29 | freemask_dir: str = "/mnt/data/Datasets/ScanNetFreeMask"): |
| 30 | |
| 31 | super().__init__(data_dir, save_dir, modes, n_jobs) |
| 32 | |
| 33 | self.oracle = oracle |
| 34 | git_repo = Path(git_repo) |
| 35 | self.create_label_database(git_repo) |
| 36 | self.freemask_base_path = Path(freemask_dir) |
| 37 | |
| 38 | for mode in self.modes: |
| 39 | trainval_split_dir = git_repo / "Tasks" / "Benchmark" |
| 40 | scannet_special_mode = "val" if mode == "validation" else mode |
| 41 | with open( |
| 42 | trainval_split_dir / (f"scannetv2_{scannet_special_mode}.txt") |
| 43 | ) as f: |
| 44 | # -1 because the last one is always empty |
| 45 | split_file = f.read().split("\n")[:-1] |
| 46 | |
| 47 | scans_folder = "scans_test" if mode == "test" else "scans" |
| 48 | filepaths = [] |
| 49 | for scene in split_file: |
| 50 | filepaths.append( |
| 51 | self.data_dir / scans_folder / scene / (scene + "_vh_clean_2.ply") |
| 52 | ) |
| 53 | self.files[mode] = natsorted(filepaths) |
| 54 | |
| 55 | def create_label_database(self, git_repo): |
| 56 | label_database = {} |
| 57 | for row_id, class_id in enumerate(self.FREEMASK_CLASS_IDS): |
| 58 | label_database[class_id] = { |
| 59 | 'color': self.FREEMASK_COLOR_MAP[class_id], |
| 60 | 'name': self.FREEMASK_CLASS_NAMES[row_id], |
| 61 | 'validation': True |
| 62 | } |
| 63 | self._save_yaml(self.save_dir / "label_database.yaml", label_database) |
| 64 | return label_database |
| 65 | |
| 66 | def process_file(self, filepath, mode): |
| 67 | """process_file. |
| 68 | |
| 69 | The first part is analogous to the scannet200 preprocessing. |
| 70 | In second part we load the freemask data and masks proposals, which we assign to the points. |
| 71 |
nothing calls this directly
no outgoing calls
no test coverage detected