Open zhangdongkun98 opened 1 year ago
Hi @christopher-motional , can you help me fix this?
Hi @zhangdongkun98, yes, sorry for the delay --thanks for the catch, those do indeed sound like bugs, will confirm and aim to get a fix up shortly.
Hi @zhangdongkun98, yes, sorry for the delay --thanks for the catch, those do indeed sound like bugs, will confirm and aim to get a fix up shortly.
Thanks for your reply!
@christopher-motional I was curious to learn if you managed to confirm / deny these are indeed bugs.
I think the vy you calculated is in the local frame at the initial iteration. However, the EgoState stores dynamic states in the local frame at each iteration. Therefore, the lateral velocity of the ego vehicle is small even when changing lanes. Remind the non-holonomic constraint of vehicles. But the vy in the dataset still seems wrong because it is always negative (-0.15~-0.20).
Describe the bug
Bug1: Ego past velocity and acceleration are transformed into local frame.
Bug2: Ego velocity vy is wrong, while vx seems correct.
Setup
Steps To Reproduce
Steps to reproduce the behavior:
test_data.py
(put it intutorials
folder) for reproducing this bug is following:Useful imports
import os from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Type
import hydra from omegaconf import DictConfig, OmegaConf import tempfile
import numpy as np import torch np.set_printoptions(precision=6, linewidth=65536, suppress=True, threshold=np.inf) torch.set_printoptions(precision=6, threshold=1000, edgeitems=None, linewidth=65536, profile=None, sci_mode=False)
from nuplan.planning.script.builders.model_builder import build_torch_module_wrapper from nuplan.planning.script.builders.worker_pool_builder import build_worker
from nuplan.planning.script.builders.splitter_builder import build_splitter from nuplan.planning.script.builders.scenario_builder import build_scenarios from nuplan.planning.training.preprocessing.feature_preprocessor import FeaturePreprocessor
from nuplan.planning.scenario_builder.abstract_scenario import AbstractScenario from nuplan.planning.scenario_builder.nuplan_db.nuplan_scenario import NuPlanScenario from nuplan.planning.training.data_augmentation.abstract_data_augmentation import AbstractAugmentor from nuplan.planning.training.data_loader.scenario_dataset import ScenarioDataset from nuplan.planning.training.preprocessing.feature_preprocessor import FeaturePreprocessor from nuplan.planning.training.modeling.types import FeaturesType, ScenarioListType, TargetsType
from nuplan.planning.training.preprocessing.features.generic_agents import GenericAgents from nuplan.planning.training.preprocessing.features.vector_set_map import VectorSetMap from nuplan.planning.training.preprocessing.features.trajectory import Trajectory
from nuplan.planning.scenario_builder.abstract_scenario import AbstractScenario from nuplan.planning.simulation.trajectory.trajectory_sampling import TrajectorySampling from nuplan.planning.training.preprocessing.utils.agents_preprocessing import EgoInternalIndex from nuplan.common.actor_state.ego_state import EgoState
from nuplan.planning.training.preprocessing.target_builders import ego_trajectory_target_builder
Location of path with all training configs
CONFIG_PATH = '../nuplan/planning/script/config/training' CONFIG_NAME = 'default_training'
Create a temporary directory to store the cache and experiment artifacts
SAVE_DIR = Path(tempfile.gettempdir()) / 'dataset' # optionally replace with persistent dir EXPERIMENT = 'training_vector_experiment' JOB_NAME = 'train' LOG_DIR = SAVE_DIR / EXPERIMENT / JOB_NAME
Initialize configuration management system
hydra.core.global_hydra.GlobalHydra.instance().clear() hydra.initialize(config_path=CONFIG_PATH)
cfg = hydra.compose(config_name=CONFIG_NAME, overrides=[ f'group={str(SAVE_DIR)}', f'cache.cache_path={str(SAVE_DIR)}/cache', f'experiment_name={EXPERIMENT}', f'job_name={JOB_NAME}', 'py_func=train', '+training=training_urban_driver_open_loop_model', 'scenario_builder=nuplan_mini', # use nuplan mini database 'scenario_filter=one_continuous_log', 'scenario_filter.limit_total_scenarios=3', 'lightning.trainer.params.accelerator=ddp_spawn', 'lightning.trainer.params.max_epochs=10', 'data_loader.params.batch_size=8', 'data_loader.params.num_workers=8',
])
@hydra.main(config_path=CONFIG_PATH, config_name=CONFIG_NAME) def train(cfg: DictConfig): """ Main entrypoint for training/validation experiments. :param cfg: omegaconf dictionary """
def create_dataset(cfg, worker, model): """ only support dataset_fraction=1.0 """ feature_builders = model.get_list_of_required_feature() target_builders = model.get_list_of_computed_target()
class NuplanDataset(ScenarioDataset): def init(self, cfg, scenarios: List[AbstractScenario], feature_preprocessor: FeaturePreprocessor, augmentors: Optional[List[AbstractAugmentor]] = None) -> None: super().init(scenarios, feature_preprocessor, augmentors) self.cfg = cfg
class EgoTrajectoryTargetBuilder(ego_trajectory_target_builder.EgoTrajectoryTargetBuilder): def get_targets(self, scenario: AbstractScenario) -> Trajectory: """ ego pose is global, ego velocity is local https://github.com/motional/nuplan-devkit/issues/227 """
def world2local(state, state0): ''' state (array): (n, 3), 3 -> (x, y, heading) state0: (3,), 3 -> (x, y, heading) '''
def pi2pi_numpy(theta): return (theta + np.pi) % (2 * np.pi) - np.pi
train(cfg)