Skip to content

feat: generating npz files using only C++#151

Open
yhisaki wants to merge 1 commit into
tier4:tier4-mainfrom
yhisaki:convert-data-by-cpp
Open

feat: generating npz files using only C++#151
yhisaki wants to merge 1 commit into
tier4:tier4-mainfrom
yhisaki:convert-data-by-cpp

Conversation

@yhisaki

@yhisaki yhisaki commented Jun 18, 2026

Copy link
Copy Markdown

By using cnpy, it is now possible to generate npz files using only C++.

@yhisaki yhisaki force-pushed the convert-data-by-cpp branch from 00cb7b3 to 665bb4b Compare June 18, 2026 06:42
- Updated `frame_processor.cpp` to include NPZ frame writing capabilities.
- Modified the `process_sequence` function to utilize `ConverterPaths` for directory management.
- Enhanced frame data saving logic to support NPZ format.
- Introduced `cnpy.cpp` for handling NPZ file operations, including loading and parsing.
- Cleaned up `neighbor_processor.cpp` by removing unused includes and defining constants.
- Simplified tests in `test_converter_options.cpp` to validate default options and removed redundant tests.
- Streamlined `test_frame_writer.cpp` by removing unnecessary helper functions and tests.
- Removed bin file processing from `parse_rosbag_by_cpp.py` to focus on NPZ generation.

Signed-off-by: Y.Hisaki <yhisaki31@gmail.com>
@yhisaki yhisaki force-pushed the convert-data-by-cpp branch from 665bb4b to 5b5e969 Compare June 18, 2026 08:46
@yhisaki yhisaki changed the title Refactor ConverterOptions and Update Rosbag Parsing Scripts feat: generating npz files using only C++ Jun 18, 2026
@yhisaki yhisaki requested a review from SakodaShintaro June 18, 2026 08:59
@yhisaki yhisaki marked this pull request as ready for review June 18, 2026 08:59
@SakodaShintaro

Copy link
Copy Markdown

NPZ Diff Summary

Comparison of the same frame written by two different test_cpp runs:

  • f1 = 20260619_092309_test_cpp/2025-06-12/10-19-35/10-19-35_00000000_00003015.npz (53881 bytes)
  • f2 = 20260619_092530_test_cpp/2025-06-12/10-19-35/10-19-35_00000000_00003015.npz (53499 bytes)

Both files contain the same 18 keys. No key is missing on either side.

1. dtype / shape differences

key f1 (09:23:09) f2 (09:25:30) logical value
version int64 scalar array(2) uint32 shape (1,) [2] same (2)
lanes_has_speed_limit bool int32 same (equal as int, sum = 51)
route_lanes_has_speed_limit bool int32 same (equal as int, sum = 1)

2. float value differences (numerical, epsilon-level)

key max abs diff n differing elements
ego_agent_future 2.98e-08 19 / 240
ego_agent_past 5.96e-08 7 / 93
neighbor_agents_future 1.19e-07 91 / 76800

All differences are at the float32 epsilon level (~1.2e-7), consistent with floating-point ordering / rounding differences rather than logic differences.

The other 14 float keys are bitwise identical:
ego_current_state, ego_shape, goal_pose, lanes, lanes_speed_limit, line_strings, neighbor_agents_past, polygons, route_lanes, route_lanes_speed_limit, static_objects (and turn_indicators as int32, exactly equal).

@SakodaShintaro

Copy link
Copy Markdown
[rank0]: Traceback (most recent call last):
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/Diffusion-Planner/diffusion_planner/train_predictor.py", line 185, in <module>
[rank0]:     main()
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/Diffusion-Planner/diffusion_planner/train_predictor.py", line 181, in main
[rank0]:     model_training(train_config)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/Diffusion-Planner/diffusion_planner/diffusion_planner/train.py", line 236, in model_training
[rank0]:     valid_dict = validate_model(diffusion_planner, valid_loader, args)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 124, in decorate_context
[rank0]:     return func(*args, **kwargs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/Diffusion-Planner/diffusion_planner/diffusion_planner/validate_model.py", line 74, in validate_model
[rank0]:     _, outputs = model(inputs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1778, in _wrapped_call_impl
[rank0]:     return self._call_impl(*args, **kwargs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1789, in _call_impl
[rank0]:     return forward_call(*args, **kwargs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/nn/parallel/distributed.py", line 1832, in forward
[rank0]:     else self._run_ddp_forward(*inputs, **kwargs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/nn/parallel/distributed.py", line 1657, in _run_ddp_forward
[rank0]:     return self.module(*inputs, **kwargs)  # type: ignore[index]
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1778, in _wrapped_call_impl
[rank0]:     return self._call_impl(*args, **kwargs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1789, in _call_impl
[rank0]:     return forward_call(*args, **kwargs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/Diffusion-Planner/diffusion_planner/diffusion_planner/model/diffusion_planner.py", line 18, in forward
[rank0]:     encoder_outputs = self.encoder(inputs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1778, in _wrapped_call_impl
[rank0]:     return self._call_impl(*args, **kwargs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1789, in _call_impl
[rank0]:     return forward_call(*args, **kwargs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/Diffusion-Planner/diffusion_planner/diffusion_planner/model/module/encoder.py", line 224, in forward
[rank0]:     encoding_lanes, lanes_mask, lane_pos = self.lane_encoder(
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1778, in _wrapped_call_impl
[rank0]:     return self._call_impl(*args, **kwargs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1789, in _call_impl
[rank0]:     return forward_call(*args, **kwargs)
[rank0]:   File "/home/shintarosakoda/Diffusion-Planner-Meta-Repository/Diffusion-Planner/diffusion_planner/diffusion_planner/model/module/encoder.py", line 600, in forward
[rank0]:     speed_limit_embedding = torch.where(has_speed_limit, speed_limit_emb, unknown_speed_emb)
[rank0]: RuntimeError: where expected condition to be a boolean tensor, but got a tensor with dtype Int

@SakodaShintaro SakodaShintaro left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes breaks the training pipeline.

And, it seems to be too big for the purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants