File size: 2,893 Bytes
9b33fca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""3D G-DINO data connector."""

from ml_collections import ConfigDict
from vis4d.config import class_config
from vis4d.data.const import CommonKeys as K
from vis4d.engine.connectors import DataConnector, data_key, pred_key

CONN_GDINO3D_LOSS = {
    "all_layers_cls_scores": pred_key("all_layers_cls_scores"),
    "all_layers_bbox_preds": pred_key("all_layers_bbox_preds"),
    "all_layers_bbox_3d_preds": pred_key("all_layers_bbox_3d_preds"),
    "text_token_mask": pred_key("text_token_mask"),
    "enc_cls_scores": pred_key("enc_outputs_class"),
    "enc_bbox_preds": pred_key("enc_outputs_coord"),
    "enc_outputs_3d": pred_key("enc_outputs_3d"),
    "dn_meta": pred_key("dn_meta"),
    "positive_maps": pred_key("positive_maps"),
    "input_hw": data_key(K.input_hw),
    "batch_gt_boxes": data_key(K.boxes2d),
    "batch_gt_boxes_3d": data_key(K.boxes3d),
    "batch_gt_boxes_classes": data_key(K.boxes2d_classes),
    "batch_gt_intrinsics": data_key(K.intrinsics),
}

CONN_BBOX_3D_TRAIN = {
    "images": K.images,
    "input_texts": K.boxes2d_names,
    "input_hw": K.input_hw,
    "boxes2d": K.boxes2d,
    "boxes2d_classes": K.boxes2d_classes,
    "intrinsics": K.intrinsics,
}

CONN_BBOX_3D_TEST = {
    "images": K.images,
    "input_texts": K.boxes2d_names,
    "input_hw": K.input_hw,
    "original_hw": K.original_hw,
    "intrinsics": K.intrinsics,
    "padding": "padding",
    "text_prompt_mapping": "text_prompt_mapping",
}

CONN_COCO_DET3D_EVAL = {
    "coco_image_id": data_key(K.sample_names),
    "pred_boxes": pred_key("boxes"),
    "pred_scores": pred_key("scores"),
    "pred_classes": pred_key("class_ids"),
    "pred_boxes3d": pred_key("boxes3d"),
}

CONN_OMNI3D_DET3D_EVAL = {
    **CONN_COCO_DET3D_EVAL,
    "dataset_names": data_key("dataset_name"),
}

CONN_BBOX_3D_VIS = {
    "images": data_key(K.original_images),
    "image_names": data_key(K.sample_names),
    "intrinsics": data_key("original_intrinsics"),
    "boxes3d": pred_key("boxes3d"),
    "class_ids": pred_key("class_ids"),
    "scores": pred_key("scores"),
    "categories": pred_key("categories"),
}

CONN_DEPTH_LOSS = {
    "depths": pred_key("depth_maps"),
    "target_depths": data_key(K.depth_maps),
}

CONN_DEPTH_VIS = {
    "images": data_key(K.original_images),
    "image_names": data_key(K.sample_names),
    "depths": pred_key("depth_maps"),
    # "depth_gts": data_key(K.depth_maps),
    "intrinsics": data_key("original_intrinsics"),
}


def get_data_connector_cfg(
    center_padding: bool = True,
    with_text_prompt_mapping: bool = True,
) -> tuple[ConfigDict, ConfigDict]:
    """Get the data connector configuration."""
    train_data_connector = class_config(
        DataConnector, key_mapping=CONN_BBOX_3D_TRAIN
    )

    test_data_connector = class_config(
        DataConnector, key_mapping=CONN_BBOX_3D_TEST
    )

    return train_data_connector, test_data_connector