scannet_converter.py 1.43 KB
Newer Older
1
import os
2

liyinhao's avatar
liyinhao committed
3
import mmcv
liyinhao's avatar
liyinhao committed
4
from tools.data_converter.scannet_data_utils import ScanNetData
5
6


7
def create_scannet_info_file(data_path, pkl_prefix='scannet', save_path=None):
liyinhao's avatar
liyinhao committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    '''
        Create scannet information file.

        Get information of the raw data and save it to the pkl file.

        Args:
            data_path (str): Path of the data.
            pkl_prefix (str): Prefix ofr the pkl to be saved. Default: 'scannet'. # noqa: E501
            save_path (str): Path of the pkl to be saved. Default: None.

        Returns:
            None

    '''
22
    assert os.path.exists(data_path)
23
    if save_path is None:
liyinhao's avatar
liyinhao committed
24
        save_path = data_path
25
    else:
liyinhao's avatar
liyinhao committed
26
        save_path = save_path
27
    assert os.path.exists(save_path)
liyinhao's avatar
liyinhao committed
28
29
    train_filename = os.path.join(save_path, f'{pkl_prefix}_infos_train.pkl')
    val_filename = os.path.join(save_path, f'{pkl_prefix}_infos_val.pkl')
liyinhao's avatar
liyinhao committed
30
31
    train_dataset = ScanNetData(root_path=data_path, split='train')
    val_dataset = ScanNetData(root_path=data_path, split='val')
32
    scannet_infos_train = train_dataset.get_scannet_infos(has_label=True)
33
    with open(train_filename, 'wb') as f:
liyinhao's avatar
liyinhao committed
34
35
        mmcv.dump(scannet_infos_train, f, 'pkl')
    print(f'Scannet info train file is saved to {train_filename}')
36
    scannet_infos_val = val_dataset.get_scannet_infos(has_label=True)
37
    with open(val_filename, 'wb') as f:
liyinhao's avatar
liyinhao committed
38
39
        mmcv.dump(scannet_infos_val, f, 'pkl')
    print(f'Scannet info val file is saved to {val_filename}')