scannet_dataset.py 2.15 KB
Newer Older
1
2
3
4
5
import os.path as osp

import numpy as np

from mmdet.datasets import DATASETS
6
from .indoor_base_dataset import IndoorBaseDataset
7
8
9


@DATASETS.register_module()
10
11
class ScannetBaseDataset(IndoorBaseDataset):

12
13
14
15
16
17
18
19
20
21
    CLASSES = ('cabinet', 'bed', 'chair', 'sofa', 'table', 'door', 'window',
               'bookshelf', 'picture', 'counter', 'desk', 'curtain',
               'refrigerator', 'showercurtrain', 'toilet', 'sink', 'bathtub',
               'garbagebin')

    def __init__(self,
                 root_path,
                 ann_file,
                 pipeline=None,
                 training=False,
liyinhao's avatar
liyinhao committed
22
                 classes=None,
yinchimaoliang's avatar
yinchimaoliang committed
23
24
                 test_mode=False,
                 with_label=True):
liyinhao's avatar
liyinhao committed
25
        super().__init__(root_path, ann_file, pipeline, training, classes,
26
                         test_mode, with_label)
27

liyinhao's avatar
liyinhao committed
28
        self.data_path = osp.join(root_path, 'scannet_train_instance_data')
29

yinchimaoliang's avatar
yinchimaoliang committed
30
    def _get_pts_filename(self, sample_idx):
31
        pts_filename = osp.join(self.data_path, f'{sample_idx}_vert.npy')
yinchimaoliang's avatar
yinchimaoliang committed
32
        return pts_filename
33

yinchimaoliang's avatar
yinchimaoliang committed
34
    def _get_ann_info(self, index, sample_idx):
35
        # Use index to get the annos, thus the evalhook could also use this api
liyinhao's avatar
liyinhao committed
36
        info = self.data_infos[index]
37
38
        if info['annos']['gt_num'] != 0:
            gt_bboxes_3d = info['annos']['gt_boxes_upright_depth']  # k, 6
yinchimaoliang's avatar
yinchimaoliang committed
39
40
            gt_labels = info['annos']['class']
            gt_bboxes_3d_mask = np.ones_like(gt_labels).astype(np.bool)
41
42
        else:
            gt_bboxes_3d = np.zeros((1, 6), dtype=np.float32)
yinchimaoliang's avatar
yinchimaoliang committed
43
44
            gt_labels = np.zeros(1, ).astype(np.bool)
            gt_bboxes_3d_mask = np.zeros(1, ).astype(np.bool)
45
        pts_instance_mask_path = osp.join(self.data_path,
liyinhao's avatar
liyinhao committed
46
                                          f'{sample_idx}_ins_label.npy')
47
        pts_semantic_mask_path = osp.join(self.data_path,
liyinhao's avatar
liyinhao committed
48
                                          f'{sample_idx}_sem_label.npy')
49
50
51
52
53
54
55
56

        anns_results = dict(
            gt_bboxes_3d=gt_bboxes_3d,
            gt_labels=gt_labels,
            gt_bboxes_3d_mask=gt_bboxes_3d_mask,
            pts_instance_mask_path=pts_instance_mask_path,
            pts_semantic_mask_path=pts_semantic_mask_path)
        return anns_results