Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions docs/tutorials/initialize.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,50 @@

---

`Tier4` class expects the following dataset directly structure:

```shell
data/tier4/
├── annotation ...contains `*.json` files.
├── data
│   ├── CAM_BACK
│   ├── CAM_BACK_LEFT
│   ├── CAM_BACK_RIGHT
│   ├── CAM_FRONT
│   ├── CAM_FRONT_LEFT
│   ├── CAM_FRONT_RIGHT
│   ├── LIDAR_CONCAT
│   └── ...Other sensor channels
...
```
`Tier4` class expects both following dataset directly structure with or without `<VERSION>` directory:

- With `<VERSION>` directory:

```shell
data/tier4/
└── <VERSION> ...version number
├── annotation ...contains `*.json` files
├── data
│   ├── CAM_BACK
│   ├── CAM_BACK_LEFT
│   ├── CAM_BACK_RIGHT
│   ├── CAM_FRONT
│   ├── CAM_FRONT_LEFT
│   ├── CAM_FRONT_RIGHT
│   ├── LIDAR_CONCAT
│   └── ...Other sensor channels
...
```

- Without `<VERSION>` directory:

```shell
data/tier4/
├── annotation ...contains `*.json` files
├── data
│   ├── CAM_BACK
│   ├── CAM_BACK_LEFT
│   ├── CAM_BACK_RIGHT
│   ├── CAM_FRONT
│   ├── CAM_FRONT_LEFT
│   ├── CAM_FRONT_RIGHT
│   ├── LIDAR_CONCAT
│   └── ...Other sensor channels
...
```

You can initialize a `Tier4` instance as follows:

```python

>>> from t4_devkit import Tier4

>>> t4 = Tier4("annotation", "data/tier4/", verbose=True)
>>> t4 = Tier4("data/tier4/", verbose=True)
======
Loading T4 tables in `annotation`...
Reverse indexing...
Expand Down
22 changes: 12 additions & 10 deletions docs/tutorials/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ If you want to visualize annotation results, `Tier4` supports some rendering met
### Scene

```python
>>> scene_token = t4.scene[0].token
>>> t4.render_scene(scene_token)
>>> t4.render_scene()
```

![Render Scene GIF](../assets/render_scene.gif)
Expand All @@ -20,18 +19,21 @@ If you want to visualize annotation results, `Tier4` supports some rendering met

![Render Instance GIF](../assets/render_instance.gif)

You can also render multiple instances at once:
<!-- prettier-ignore-start -->
!!! NOTE
You can also render multiple instances at once:

```python
>>> instance_tokens = [inst.token for inst in t4.instance[:3]]
>>> t4.render_instance(instance_tokens)
```
<!-- markdownlint-disable MD046 -->
```python
>>> instance_tokens = [inst.token for inst in t4.instance[:3]]
>>> t4.render_instance(instance_tokens)
```
<!-- prettier-ignore-end -->

### PointCloud

```python
>>> scene_token = t4.scene[0].token
>>> t4.render_pointcloud(scene_token)
>>> t4.render_pointcloud()
```

![Render PointCloud GIF](../assets/render_pointcloud.gif)
Expand All @@ -42,7 +44,7 @@ You can also render multiple instances at once:

<!-- markdownlint-disable MD046 -->
```python
>>> t4.render_pointcloud(scene_token, ignore_distortion=True)
>>> t4.render_pointcloud(ignore_distortion=True)
```
<!-- prettier-ignore-end -->

Expand Down
16 changes: 5 additions & 11 deletions t4_devkit/cli/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ def scene(
) -> None:
_create_dir(output)

t4 = Tier4("annotation", data_root, verbose=False)
scene_token = t4.scene[0].token
t4.render_scene(scene_token, future_seconds=future, save_dir=output)
t4 = Tier4(data_root, verbose=False)
t4.render_scene(future_seconds=future, save_dir=output)


@cli.command("instance", help="Visualize a particular instance in the corresponding scene.")
Expand Down Expand Up @@ -71,7 +70,7 @@ def instance(
) -> None:
_create_dir(output)

t4 = Tier4("annotation", data_root, verbose=False)
t4 = Tier4(data_root, verbose=False)
t4.render_instance(instance_token=instance, future_seconds=future, save_dir=output)


Expand Down Expand Up @@ -99,13 +98,8 @@ def pointcloud(
) -> None:
_create_dir(output)

t4 = Tier4("annotation", data_root, verbose=False)
scene_token = t4.scene[0].token
t4.render_pointcloud(
scene_token,
ignore_distortion=ignore_distortion,
save_dir=output,
)
t4 = Tier4(data_root, verbose=False)
t4.render_pointcloud(ignore_distortion=ignore_distortion, save_dir=output)


def _create_dir(dir_path: str | None) -> None:
Expand Down
22 changes: 6 additions & 16 deletions t4_devkit/common/sanity.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from __future__ import annotations

import re
import warnings
from pathlib import Path

from attrs import define

from t4_devkit import Tier4
from t4_devkit import Tier4, load_metadata

__all__ = ["DBException", "sanity_check"]

Expand All @@ -30,17 +29,6 @@ def sanity_check(db_root: str | Path, *, include_warning: bool = False) -> DBExc
Returns:
Exception or warning if exits, otherwise returns None.
"""
db_root_path = Path(db_root)

version_pattern = re.compile(r".*/\d+$")
versions = [d.name for d in db_root_path.iterdir() if version_pattern.match(str(d))]

if versions:
version = sorted(versions)[-1]
data_root = db_root_path.joinpath(version).as_posix()
else:
version = None
data_root = db_root_path.as_posix()

with warnings.catch_warnings():
if include_warning:
Expand All @@ -49,12 +37,14 @@ def sanity_check(db_root: str | Path, *, include_warning: bool = False) -> DBExc
warnings.filterwarnings("ignore")

try:
_ = Tier4("annotation", data_root=data_root, verbose=False)
_ = Tier4(data_root=db_root, verbose=False)
exception = None
except Exception as e:
metadata = load_metadata(db_root)

exception = DBException(
dataset_id=db_root_path.name,
version=version,
dataset_id=metadata.dataset_id,
version=metadata.version,
message=str(e),
)
return exception
13 changes: 4 additions & 9 deletions t4_devkit/helper/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def _init_viewer(

def render_scene(
self,
scene_token: str,
*,
max_time_seconds: float = np.inf,
future_seconds: float = 0.0,
Expand All @@ -106,7 +105,6 @@ def render_scene(
"""Render specified scene.

Args:
scene_token (str): Unique identifier of scene.
max_time_seconds (float, optional): Max time length to be rendered [s].
future_seconds (float, optional): Future time in [s].
save_dir (str | None, optional): Directory path to save the recording.
Expand All @@ -132,7 +130,7 @@ def render_scene(
render3d = len(first_lidar_tokens) > 0 or len(first_radar_tokens) > 0
render2d = len(first_camera_tokens) > 0

app_id = f"scene@{scene_token}"
app_id = f"scene@{self._t4.dataset_id}"
viewer = self._init_viewer(
app_id,
render3d=render3d,
Expand All @@ -141,7 +139,7 @@ def render_scene(
save_dir=save_dir,
)

scene: Scene = self._t4.get("scene", scene_token)
scene: Scene = self._t4.scene[0]
first_sample: Sample = self._t4.get("sample", scene.first_sample_token)
max_timestamp_us = first_sample.timestamp + sec2us(max_time_seconds)

Expand Down Expand Up @@ -212,7 +210,6 @@ def render_instance(
if last_sample is None or current_last_sample.timestamp > last_sample.timestamp:
last_sample = current_last_sample

scene_token = first_sample.scene_token
max_timestamp_us = last_sample.timestamp

# search first sample data tokens
Expand All @@ -235,7 +232,7 @@ def render_instance(
render3d = len(first_lidar_tokens) > 0 or len(first_radar_tokens) > 0
render2d = len(first_camera_tokens) > 0

app_id = f"instance@{scene_token}"
app_id = f"instance@{self._t4.dataset_id}"
viewer = self._init_viewer(
app_id,
render3d=render3d,
Expand Down Expand Up @@ -279,7 +276,6 @@ def render_instance(

def render_pointcloud(
self,
scene_token: str,
*,
max_time_seconds: float = np.inf,
ignore_distortion: bool = True,
Expand All @@ -288,7 +284,6 @@ def render_pointcloud(
"""Render pointcloud on 3D and 2D view.

Args:
scene_token (str): Scene token.
max_time_seconds (float, optional): Max time length to be rendered [s].
ignore_distortion (bool, optional): Whether to ignore distortion parameters.
save_dir (str | None, optional): Directory path to save the recording.
Expand All @@ -298,7 +293,7 @@ def render_pointcloud(
Add an option of rendering radar channels.
"""
# initialize viewer
app_id = f"pointcloud@{scene_token}"
app_id = f"pointcloud@{self._t4.dataset_id}"
viewer = self._init_viewer(app_id, render_ann=False, save_dir=save_dir)

# search first lidar sample data token
Expand Down
Loading
Loading