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

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,
liyinhao's avatar
liyinhao committed
11
12
                            use_v1=False,
                            workers=4):
liyinhao's avatar
liyinhao committed
13
    """Create indoor information file.
liyinhao's avatar
liyinhao committed
14
15
16
17
18
19
20
21

    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.
liyinhao's avatar
liyinhao committed
22
        workers (int): Number of threads to be used. Default: 4.
liyinhao's avatar
liyinhao committed
23
24
25
    """
    assert os.path.exists(data_path)
    assert pkl_prefix in ['sunrgbd', 'scannet']
26
    save_path = data_path if save_path is None else save_path
liyinhao's avatar
liyinhao committed
27
    assert os.path.exists(save_path)
28

liyinhao's avatar
liyinhao committed
29
    train_filename = os.path.join(save_path, f'{pkl_prefix}_infos_train.pkl')
liyinhao's avatar
liyinhao committed
30
31
32
33
34
35
36
37
38
    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')
39

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

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