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

import mmcv
import numpy as np

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


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

13
14
15
16
17
18
19
20
21
22
    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,
23
                 cat_ids=None,
yinchimaoliang's avatar
yinchimaoliang committed
24
25
                 test_mode=False,
                 with_label=True):
26
        super().__init__(root_path, ann_file, pipeline, training, cat_ids,
27
                         test_mode, with_label)
28

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

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

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

        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