Skip to content

Commit 29dc38e

Browse files
committed
Add lidar and lidarseg metadata to cache generator
Signed-off-by: Kok Seang Tan <kseangtan@gmail.com>
1 parent dc08c8e commit 29dc38e

17 files changed

Lines changed: 1341 additions & 81 deletions

autoware_ml/common/enums/enums.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@
1515
from enum import Enum
1616

1717

18+
class Modality(str, Enum):
19+
"""
20+
Modality.
21+
22+
Attributes:
23+
LIDAR: Lidar modality.
24+
CAMERA: Camera modality.
25+
RADAR: Radar modality.
26+
"""
27+
28+
LIDAR = "lidar"
29+
CAMERA = "camera"
30+
RADAR = "radar"
31+
32+
1833
class SplitType(str, Enum):
1934
"""
2035
Split type.

autoware_ml/configs/database/t4dataset/t4dataset_base.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ defaults:
1818
- t4dataset/scenarios@scenarios.db_jpntaxi_base: detection3d/db_jpntaxi_base
1919
- t4dataset/scenarios@scenarios.db_largebus: detection3d/db_largebus
2020

21+
# Number of features in the lidar pointcloud
22+
lidar_pointcloud_num_features: 5
23+
2124
# Processor settings
2225
num_workers: 16

autoware_ml/configs/database/t4dataset/t4dataset_j6gen2_base.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ defaults:
1616
- t4dataset/scenarios@scenarios.db_j6gen2: detection3d/db_j6gen2
1717
- t4dataset/scenarios@scenarios.db_largebus: detection3d/db_largebus
1818

19+
# Number of features in the lidar pointcloud
20+
lidar_pointcloud_num_features: 5
21+
1922
# Processor settings
2023
num_workers: 16

autoware_ml/configs/database/t4dataset/t4dataset_jpntaxi_base.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ cache_file_prefix_name: database
1414
defaults:
1515
- t4dataset/scenarios@scenarios.db_jpntaxi_base: detection3d/db_jpntaxi_base
1616

17+
# Number of features in the lidar pointcloud
18+
lidar_pointcloud_num_features: 5
19+
1720
# Processor settings
1821
num_workers: 16

autoware_ml/databases/base_database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import polars as pl
2323

2424
from autoware_ml.databases.scenarios import Scenarios, ScenarioData
25-
from autoware_ml.databases.schemas import DatasetRecord, DatasetTableSchema
25+
from autoware_ml.databases.schemas.dataset_schemas import DatasetRecord, DatasetTableSchema
2626

2727
logger = logging.getLogger(__name__)
2828

autoware_ml/databases/database_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from types import MappingProxyType
2020

2121
from autoware_ml.databases.scenarios import Scenarios, ScenarioData
22-
from autoware_ml.databases.schemas import DatasetRecord
22+
from autoware_ml.databases.schemas.dataset_schemas import DatasetRecord
2323

2424

2525
class DatabaseInterface(Protocol):

autoware_ml/databases/schemas/__init__.py

Whitespace-only changes.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright 2026 TIER IV, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import annotations
16+
17+
from abc import ABC, abstractmethod
18+
from typing import NamedTuple, Sequence, Mapping, Any
19+
20+
import polars as pl
21+
22+
23+
class DatasetTableColumn(NamedTuple):
24+
"""
25+
Annotation table column.
26+
27+
Attributes:
28+
name: Name of the column.
29+
dtype: Data type of the column.
30+
"""
31+
32+
name: str
33+
dtype: pl.DataType
34+
35+
36+
class BaseFieldSchema:
37+
"""
38+
Base class for field schemas.
39+
"""
40+
41+
@classmethod
42+
def to_polars_field_schema(cls) -> Sequence[pl.Field]:
43+
"""
44+
Convert the lidar column schema to a Polars field schema.
45+
46+
Returns:
47+
pl.Schema: Polars schema.
48+
"""
49+
50+
return [
51+
pl.Field(v.name, v.dtype)
52+
for k, v in cls.__dict__.items()
53+
if not k.startswith("__") and isinstance(v, DatasetTableColumn)
54+
]
55+
56+
57+
class DataModelInterface(ABC):
58+
"""
59+
Interface for data models.
60+
"""
61+
62+
@abstractmethod
63+
def to_dictionary(self) -> Mapping[str, Any]:
64+
"""
65+
Convert the data model to a dictionary.
66+
67+
Returns:
68+
Mapping[str, Any]: Dictionary representation of the data model.
69+
"""
70+
71+
raise NotImplementedError("Subclasses must implement to_dictionary!")
72+
73+
@classmethod
74+
def load_from_dictionary(cls, data_model: Mapping[str, Any]) -> DataModelInterface:
75+
"""
76+
Load the data model and decode it to the corresponding data model from a dictionary, which is
77+
deserialized from a Polars dataframe.
78+
79+
Args:
80+
data_model: Dictionary representation of the data model, which is
81+
deserialized from a Polars dataframe.
82+
83+
Returns:
84+
DataModelInterface: Data model.
85+
"""
86+
87+
raise NotImplementedError("Subclasses must implement load_from_dictionary!")
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright 2026 TIER IV, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import annotations
16+
17+
from dataclasses import dataclass
18+
from typing import Sequence, Any, Mapping
19+
20+
import polars as pl
21+
from pydantic import BaseModel, ConfigDict
22+
23+
from autoware_ml.databases.schemas.base_schemas import (
24+
BaseFieldSchema,
25+
DatasetTableColumn,
26+
DataModelInterface,
27+
)
28+
29+
30+
@dataclass(frozen=True)
31+
class CategoryMappingDatasetSchema(BaseFieldSchema):
32+
"""
33+
Dataclass to define polars schema for columns related to category mapping.
34+
"""
35+
36+
CATEGORY_NAMES = DatasetTableColumn("category_names", pl.List(pl.String))
37+
CATEGORY_INDICES = DatasetTableColumn("category_indices", pl.List(pl.Int32))
38+
39+
40+
class CategoryMappingDataModel(BaseModel, DataModelInterface):
41+
"""
42+
Category mapping data model that can be shared by multiple datasets.
43+
44+
Attributes:
45+
category_name: Category name.
46+
category_index: Category index.
47+
"""
48+
49+
model_config = ConfigDict(frozen=True, strict=True, arbitrary_types_allowed=True)
50+
51+
category_names: Sequence[str]
52+
category_indices: Sequence[int]
53+
54+
def model_post_init(self, __context: Any) -> None:
55+
"""Validate that all attributes are of the same length."""
56+
57+
assert len(self.category_names) == len(self.category_indices), (
58+
"All attributes must be of the same length"
59+
)
60+
61+
def to_dictionary(self) -> Mapping[str, Any]:
62+
"""
63+
Convert the category mapping data model to a dictionary.
64+
65+
Returns:
66+
Mapping[str, Any]: Dictionary representation of the category mapping data model.
67+
"""
68+
69+
return self.model_dump()
70+
71+
@classmethod
72+
def load_from_dictionary(cls, data_model: Mapping[str, Any]) -> CategoryMappingDataModel:
73+
"""
74+
Load the category mapping data model and decode it to the corresponding CategoryMappingDataModel
75+
from a dictionary, which is deserialized from a Polars dataframe.
76+
77+
Args:
78+
data_model: Dictionary representation of the category mapping data model, which is
79+
deserialized from a Polars dataframe.
80+
"""
81+
return cls(
82+
category_names=data_model[CategoryMappingDatasetSchema.CATEGORY_NAMES.name],
83+
category_indices=data_model[CategoryMappingDatasetSchema.CATEGORY_INDICES.name],
84+
)

0 commit comments

Comments
 (0)