sunrgbd_converter.py 1.58 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.sunrgbd_data_utils import SUNRGBDData
5
6
7


def create_sunrgbd_info_file(data_path,
8
                             pkl_prefix='sunrgbd',
9
                             save_path=None,
10
                             use_v1=False):
liyinhao's avatar
liyinhao committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    '''
    Create sunrgbd 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: 'sunrgbd'.
        save_path (str): Path of the pkl to be saved. Default: None.
        use_v1 (bool): Whether to use v1. Default: False.

    Returns:
        None

    '''
26
    assert os.path.exists(data_path)
27
    if save_path is None:
liyinhao's avatar
liyinhao committed
28
        save_path = data_path
29
    else:
liyinhao's avatar
liyinhao committed
30
        save_path = save_path
31
    assert os.path.exists(save_path)
liyinhao's avatar
liyinhao committed
32
33
    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
34
    train_dataset = SUNRGBDData(
35
        root_path=data_path, split='train', use_v1=use_v1)
liyinhao's avatar
liyinhao committed
36
    val_dataset = SUNRGBDData(root_path=data_path, split='val', use_v1=use_v1)
37
    sunrgbd_infos_train = train_dataset.get_sunrgbd_infos(has_label=True)
38
    with open(train_filename, 'wb') as f:
liyinhao's avatar
liyinhao committed
39
40
        mmcv.dump(sunrgbd_infos_train, f, 'pkl')
    print(f'Sunrgbd info train file is saved to {train_filename}')
41
    sunrgbd_infos_val = val_dataset.get_sunrgbd_infos(has_label=True)
42
    with open(val_filename, 'wb') as f:
liyinhao's avatar
liyinhao committed
43
44
        mmcv.dump(sunrgbd_infos_val, f, 'pkl')
    print(f'Sunrgbd info val file is saved to {val_filename}')