scannet_converter.py 1.18 KB
Newer Older
1
import os
2
3
4
5
6
7
import pickle
from pathlib import Path

from tools.data_converter.scannet_data_utils import ScannetObject


8
9
def create_scannet_info_file(data_path, pkl_prefix='scannet', save_path=None):
    assert os.path.exists(data_path)
10
11
12
13
    if save_path is None:
        save_path = Path(data_path)
    else:
        save_path = Path(save_path)
14
    assert os.path.exists(save_path)
15
16
    train_filename = save_path / f'{pkl_prefix}_infos_train.pkl'
    val_filename = save_path / f'{pkl_prefix}_infos_val.pkl'
17
18
19
    train_dataset = ScannetObject(root_path=data_path, split='train')
    val_dataset = ScannetObject(root_path=data_path, split='val')
    scannet_infos_train = train_dataset.get_scannet_infos(has_label=True)
20
21
22
    with open(train_filename, 'wb') as f:
        pickle.dump(scannet_infos_train, f)
    print('Scannet info train file is saved to %s' % train_filename)
23
    scannet_infos_val = val_dataset.get_scannet_infos(has_label=True)
24
25
26
27
28
29
30
31
    with open(val_filename, 'wb') as f:
        pickle.dump(scannet_infos_val, f)
    print('Scannet info val file is saved to %s' % val_filename)


if __name__ == '__main__':
    create_scannet_info_file(
        data_path='./data/scannet', save_path='./data/scannet')