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

import numpy as np

wuyuefeng's avatar
wuyuefeng committed
5
from mmdet3d.core.bbox import DepthInstance3DBoxes
6
from mmdet.datasets import DATASETS
zhangwenwei's avatar
zhangwenwei committed
7
from .custom_3d import Custom3DDataset
8
9
10


@DATASETS.register_module()
zhangwenwei's avatar
zhangwenwei committed
11
class ScanNetDataset(Custom3DDataset):
12

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

    def __init__(self,
zhangwenwei's avatar
zhangwenwei committed
19
                 data_root,
20
21
                 ann_file,
                 pipeline=None,
liyinhao's avatar
liyinhao committed
22
                 classes=None,
liyinhao's avatar
liyinhao committed
23
                 modality=None,
24
                 box_type_3d='Depth',
wuyuefeng's avatar
Votenet  
wuyuefeng committed
25
                 filter_empty_gt=True,
zhangwenwei's avatar
zhangwenwei committed
26
                 test_mode=False):
27
28
29
30
31
32
33
34
35
        super().__init__(
            data_root=data_root,
            ann_file=ann_file,
            pipeline=pipeline,
            classes=classes,
            modality=modality,
            box_type_3d=box_type_3d,
            filter_empty_gt=filter_empty_gt,
            test_mode=test_mode)
36

liyinhao's avatar
liyinhao committed
37
    def get_ann_info(self, index):
38
        # Use index to get the annos, thus the evalhook could also use this api
liyinhao's avatar
liyinhao committed
39
        info = self.data_infos[index]
40
        if info['annos']['gt_num'] != 0:
liyinhao's avatar
liyinhao committed
41
42
43
            gt_bboxes_3d = info['annos']['gt_boxes_upright_depth'].astype(
                np.float32)  # k, 6
            gt_labels_3d = info['annos']['class'].astype(np.long)
44
        else:
liyinhao's avatar
liyinhao committed
45
            gt_bboxes_3d = np.zeros((0, 6), dtype=np.float32)
liyinhao's avatar
liyinhao committed
46
            gt_labels_3d = np.zeros((0, ), dtype=np.long)
wuyuefeng's avatar
wuyuefeng committed
47
48
49
50
51
52
53
54

        # to target box structure
        gt_bboxes_3d = DepthInstance3DBoxes(
            gt_bboxes_3d,
            box_dim=gt_bboxes_3d.shape[-1],
            with_yaw=False,
            origin=(0.5, 0.5, 0.5)).convert_to(self.box_mode_3d)

zhangwenwei's avatar
zhangwenwei committed
55
        pts_instance_mask_path = osp.join(self.data_root,
liyinhao's avatar
liyinhao committed
56
                                          info['pts_instance_mask_path'])
zhangwenwei's avatar
zhangwenwei committed
57
        pts_semantic_mask_path = osp.join(self.data_root,
liyinhao's avatar
liyinhao committed
58
                                          info['pts_semantic_mask_path'])
59
60
61

        anns_results = dict(
            gt_bboxes_3d=gt_bboxes_3d,
zhangwenwei's avatar
zhangwenwei committed
62
            gt_labels_3d=gt_labels_3d,
63
64
65
            pts_instance_mask_path=pts_instance_mask_path,
            pts_semantic_mask_path=pts_semantic_mask_path)
        return anns_results