scannet_dataset.py 2.11 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
    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,
liyinhao's avatar
liyinhao committed
21
                 classes=None,
yinchimaoliang's avatar
yinchimaoliang committed
22
23
                 test_mode=False,
                 with_label=True):
liyinhao's avatar
liyinhao committed
24
25
        super().__init__(root_path, ann_file, pipeline, classes, test_mode,
                         with_label)
26

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

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

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

        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