indoor_converter.py 1.72 KB
Newer Older
liyinhao's avatar
liyinhao committed
1
2
3
4
5
6
7
8
9
10
11
import os

import mmcv
from tools.data_converter.scannet_data_utils import ScanNetData
from tools.data_converter.sunrgbd_data_utils import SUNRGBDData


def create_indoor_info_file(data_path,
                            pkl_prefix='sunrgbd',
                            save_path=None,
                            use_v1=False):
liyinhao's avatar
liyinhao committed
12
    """Create indoor  information file.
liyinhao's avatar
liyinhao committed
13
14
15
16
17
18
19
20
21
22
23

    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 of the pkl to be saved. Default: 'sunrgbd'.
        save_path (str): Path of the pkl to be saved. Default: None.
        use_v1 (bool): Whether to use v1. Default: False.
    """
    assert os.path.exists(data_path)
    assert pkl_prefix in ['sunrgbd', 'scannet']
24
    save_path = data_path if save_path is None else save_path
liyinhao's avatar
liyinhao committed
25
    assert os.path.exists(save_path)
26

liyinhao's avatar
liyinhao committed
27
    train_filename = os.path.join(save_path, f'{pkl_prefix}_infos_train.pkl')
liyinhao's avatar
liyinhao committed
28
29
30
31
32
33
34
35
36
    val_filename = os.path.join(save_path, f'{pkl_prefix}_infos_val.pkl')
    if pkl_prefix == 'sunrgbd':
        train_dataset = SUNRGBDData(
            root_path=data_path, split='train', use_v1=use_v1)
        val_dataset = SUNRGBDData(
            root_path=data_path, split='val', use_v1=use_v1)
    else:
        train_dataset = ScanNetData(root_path=data_path, split='train')
        val_dataset = ScanNetData(root_path=data_path, split='val')
37

liyinhao's avatar
liyinhao committed
38
    infos_train = train_dataset.get_infos(has_label=True)
39
    mmcv.dump(infos_train, train_filename, 'pkl')
liyinhao's avatar
liyinhao committed
40
    print(f'{pkl_prefix} info train file is saved to {train_filename}')
41

liyinhao's avatar
liyinhao committed
42
    infos_val = val_dataset.get_infos(has_label=True)
43
    mmcv.dump(infos_val, val_filename, 'pkl')
liyinhao's avatar
liyinhao committed
44
    print(f'{pkl_prefix} info val file is saved to {val_filename}')