tasks.py 2.42 KB
Newer Older
lishj6's avatar
init  
lishj6 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Copyright 2021 Toyota Research Institute.  All rights reserved.
from collections import OrderedDict

# from detectron2.config import configurable


class Task():
    def __init__(self, name, is_detection_task, is_dense_prediction_task):
        self.name = name
        self.is_detection_task = is_detection_task
        self.is_dense_prediction_task = is_dense_prediction_task


# yapf: disable
TASKS = [
    Task(
        name="box2d",
        is_detection_task=True,
        is_dense_prediction_task=False,
    ),
    Task(
        name="box3d",
        is_detection_task=True,
        is_dense_prediction_task=False,
    ),
    Task(
        name="depth",
        is_detection_task=False,
        is_dense_prediction_task=True,
    )
]
# yapf: enable

NAME_TO_TASK = OrderedDict([(task.name, task) for task in TASKS])


class TaskManager():
    #@configurable
    def __init__(self, box2d_on=False, box3d_on=False, depth_on=False):
        """
        configurable is experimental.
        """
        self._box2d_on = self._mask2d_on = self._box3d_on = self._semseg2d_on = self._depth_on = False
        tasks = []
        if box2d_on:
            tasks.append(NAME_TO_TASK['box2d'])
            self._box2d_on = True
        if box3d_on:
            tasks.append(NAME_TO_TASK['box3d'])
            self._box3d_on = True
        if depth_on:
            tasks.append(NAME_TO_TASK['depth'])
            self._depth_on = True

        if not tasks:
            raise ValueError("No task specified.")

        self._tasks = tasks

    @property
    def tasks(self):
        return self._tasks

    '''@classmethod
    def from_config(cls, cfg):
        # yapf: disable
        return OrderedDict(
            box2d_on    = cfg.MODEL.BOX2D_ON,
            box3d_on    = cfg.MODEL.BOX3D_ON,
            depth_on    = cfg.MODEL.DEPTH_ON,
        )
        # yapf: enable'''

    # Indicators that tells if each task is enabled.
    @property
    def box2d_on(self):
        return self._box2d_on

    @property
    def box3d_on(self):
        return self._box3d_on

    @property
    def depth_on(self):
        return self._depth_on

    @property
    def has_dense_prediction_task(self):
        return any([task.is_dense_prediction_task for task in self.tasks])

    @property
    def has_detection_task(self):
        return any([task.is_detection_task for task in self.tasks])

    @property
    def task_names(self):
        return [task.name for task in self.tasks]