Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulation problem: predicted trajectory is not smooth #36

Closed
shubaozhang opened this issue Mar 16, 2022 · 9 comments
Closed

Simulation problem: predicted trajectory is not smooth #36

shubaozhang opened this issue Mar 16, 2022 · 9 comments
Assignees

Comments

@shubaozhang
Copy link

shubaozhang commented Mar 16, 2022

Problem:
The simulation result on frame 0 looks normal, but the trajectory predicted on frame 1 is abnormal.

image

### train.py
import os
import hydra
import tempfile
from pathlib import Path
from nuplan.planning.script.run_training import main as main_train

CONFIG_PATH = '../nuplan-devkit/nuplan/planning/script/config/training'
CONFIG_NAME = 'default_training'

SAVE_DIR = Path(tempfile.gettempdir()) / 'tutorial_nuplan_framework' # optionally replace with persistent dir
EXPERIMENT = 'vector' # vector or raster or others
#LOG_DIR = str(SAVE_DIR / EXPERIMENT)
LOG_DIR = str(SAVE_DIR + '/' + EXPERIMENT)

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_dir={str(SAVE_DIR)}/cache',
f'experiment_name={EXPERIMENT}',
'log_config=true',
'py_func=train',
'+training=training_vector_model', # vector model that consumes ego, agents and map vector layers and regresses the ego's trajectory
'resume_training=false', # load the model from the last epoch and resume training
'worker=single_machine_thread_pool', # ray_distributed, sequential, single_machine_thread_pool
'scenario_builder=nuplan_mini', # use nuplan or nuplan_mini database
'scenario_builder.nuplan.scenario_filter.limit_scenarios_per_type=500000', # Choose 500 scenarios to train with
'scenario_builder.nuplan.scenario_filter.subsample_ratio=1', # subsample scenarios from 20Hz (1.0) to 0.2Hz (0.01), 10Hz (0.5), 5Hz (0.25)
'lightning.trainer.params.accelerator=ddp', # ddp is not allowed in interactive environment, using ddp_spawn instead - this can bottleneck the data pipeline, it is recommended to run training outside the notebook
'lightning.trainer.params.precision=16',
'lightning.trainer.params.auto_scale_batch_size=false',
'lightning.trainer.params.auto_lr_find=false',
'lightning.trainer.params.gradient_clip_val=0.0',
'lightning.trainer.params.gradient_clip_algorithm=norm',
'lightning.trainer.params.accumulate_grad_batches=64',
'lightning.trainer.overfitting.enable=false', # run an overfitting test instead of traning
'lightning.optimization.optimizer.learning_rate=2e-4',
'lightning.trainer.params.max_epochs=25',
'lightning.trainer.params.gpus=8',
'data_loader.params.batch_size=3',
'data_loader.params.num_workers=48',
])

main_train(cfg)

simulation.py

import os
import hydra
import tempfile
from pathlib import Path
from nuplan.planning.script.run_simulation import main as main_simulation

CONFIG_PATH = '../nuplan-devkit/nuplan/planning/script/config/simulation'
CONFIG_NAME = 'default_simulation'

SAVE_DIR = Path(tempfile.gettempdir()) / 'tutorial_nuplan_framework' # optionally replace with persistent dir

EXPERIMENT = 'vector'

last_experiment = sorted(os.listdir(LOG_DIR))[-1]
train_experiment_dir = sorted(Path(LOG_DIR).iterdir())[-1]
checkpoint = sorted((train_experiment_dir / 'checkpoints').iterdir())[-1]

MODEL_PATH = str(checkpoint).replace("=", "=")

PLANNER = 'ml_planner' # [simple_planner, ml_planner]
#CHALLENGE = 'challenge_1_open_loop_boxes' # [challenge_1_open_loop_boxes, challenge_3_closed_loop_nonreactive_agents, challenge_4_closed_loop_reactive_agents]
CHALLENGE = 'challenge_3_closed_loop_nonreactive_agents' # [challenge_1_open_loop_boxes, challenge_3_closed_loop_nonreactive_agents, challenge_4_closed_loop_reactive_agents]
#CHALLENGE = 'challenge_4_closed_loop_reactive_agents' # [challenge_1_open_loop_boxes, challenge_3_closed_loop_nonreactive_agents, challenge_4_closed_loop_reactive_agents]
DATASET_PARAMS = [
'scenario_builder=nuplan_mini', # use nuplan mini database
'scenario_builder/nuplan/scenario_filter=all_scenarios', # initially select all scenarios in the database
'scenario_builder.nuplan.scenario_filter.scenario_types=[nearby_dense_vehicle_traffic, ego_at_pudo, ego_starts_unprotected_cross_turn, ego_high_curvature]', # select scenario types
'scenario_builder.nuplan.scenario_filter.limit_scenarios_per_type=10', # use 10 scenarios per scenario type
'scenario_builder.nuplan.scenario_filter.subsample_ratio=0.5', # subsample 20s scenario from 20Hz to 1Hz (0.05)
]

hydra.core.global_hydra.GlobalHydra.instance().clear() # reinitialize hydra if already initialized
hydra.initialize(config_path=CONFIG_PATH)

cfg = hydra.compose(config_name=CONFIG_NAME, overrides=[
f'experiment_name={EXPERIMENT}',
f'group={SAVE_DIR}',
'log_config=true',
'planner=ml_planner',
'model=vector_model',
'planner.model_config=${model}', # hydra notation to select model config
f'planner.checkpoint_path={MODEL_PATH}', # this path can be replaced by the checkpoint of the model trained in the previous section
f'+simulation={CHALLENGE}',
*DATASET_PARAMS,
])

main_simulation(cfg)

parent_dir = Path(SAVE_DIR) / EXPERIMENT
results_dir = list(parent_dir.iterdir())[0] # get the child dir
nuboard_file_2 = [str(file) for file in results_dir.iterdir() if file.is_file() and file.suffix == '.nuboard'][0]

Question:
I found that subsample_ratio affects the simulation. What does subsample_ratio means? What are the proper values of subsample_ratio during training and simulation?

@kokseang-motional
Copy link
Contributor

Hi @shubaozhang , thanks for reporting this to us. May I know which scenario token is this? Thanks

@kokseang-motional
Copy link
Contributor

Also, what happens to other frames. Do they look normal?

@kokseang-motional
Copy link
Contributor

kokseang-motional commented Mar 23, 2022

Subsample a scenario relative to the database frequency (e.g. nominal freq @ 20Hz means 400 examples for 20s -> 2.5% subsample_ratio means 10 examples for 20s)
By default, it should be null/None, means we use all 400 frames for each scenario.

@shubaozhang
Copy link
Author

Also, what happens to other frames. Do they look normal?

The frames after frame 0 are all abnormal, like frame 1 in the above fig.

@shubaozhang
Copy link
Author

Also, what happens to other frames. Do they look normal?

All scenarios have the same problem: only frame 0 looks like normal

@shubaozhang
Copy link
Author

shubaozhang commented Mar 23, 2022

Subsample a scenario relative to the database frequency (e.g. nominal freq @ 20Hz means 400 examples for 20s -> 2.5% subsample_ratio means 10 examples for 20s) By default, it should be null/None, means we use all 400 frames for each scenario.

If we setting the subsample_ratio=1, the following error happens for all 27 scenarios.

image

simulation code:

import os
import hydra
import tempfile
from pathlib import Path
from nuplan.planning.script.run_simulation import main as main_simulation

CONFIG_PATH = '../nuplan-devkit/nuplan/planning/script/config/simulation'
CONFIG_NAME = 'default_simulation'

#SAVE_DIR = Path(tempfile.gettempdir()) / 'tutorial_nuplan_framework' # optionally replace with persistent dir
SAVE_DIR = '/home/qcraft/nuplan/simulation/' # optionally replace with persistent dir

EXPERIMENT = 'vector'

#LOG_DIR = '/home/qcraft/nuplan/experiments/'
#last_experiment = sorted(os.listdir(LOG_DIR))[-1]
#train_experiment_dir = sorted(Path(LOG_DIR).iterdir())[-1]
#checkpoint = sorted((train_experiment_dir / 'checkpoints').iterdir())[-1]

checkpoint = '/home/qcraft/nuplan/experiment/vector/2022.03.15.10.25.09/best_model/epoch=10-step=890.ckpt'
#checkpoint = '/home/qcraft/nuplan/experiment/vector/2022.03.13.12.01.29/best_model/epoch=16-step=1352.ckpt'

MODEL_PATH = str(checkpoint).replace("=", "=")

PLANNER = 'ml_planner' # [simple_planner, ml_planner]
#CHALLENGE = 'challenge_1_open_loop_boxes' # [challenge_1_open_loop_boxes, challenge_3_closed_loop_nonreactive_agents, challenge_4_closed_loop_reactive_agents]
CHALLENGE = 'challenge_3_closed_loop_nonreactive_agents' # [challenge_1_open_loop_boxes, challenge_3_closed_loop_nonreactive_agents, challenge_4_closed_loop_reactive_agents]
#CHALLENGE = 'challenge_4_closed_loop_reactive_agents' # [challenge_1_open_loop_boxes, challenge_3_closed_loop_nonreactive_agents, challenge_4_closed_loop_reactive_agents]
DATASET_PARAMS = [
'scenario_builder=nuplan_mini', # use nuplan mini database
'scenario_builder/nuplan/scenario_filter=all_scenarios', # initially select all scenarios in the database
'scenario_builder.nuplan.scenario_filter.scenario_types=[nearby_dense_vehicle_traffic, ego_at_pudo, ego_starts_unprotected_cross_turn, ego_high_curvature]', # select scenario types
'scenario_builder.nuplan.scenario_filter.limit_scenarios_per_type=10', # use 10 scenarios per scenario type
'scenario_builder.nuplan.scenario_filter.subsample_ratio=1', # subsample 20s scenario from 20Hz to 1Hz (0.05)
]

hydra.core.global_hydra.GlobalHydra.instance().clear() # reinitialize hydra if already initialized
hydra.initialize(config_path=CONFIG_PATH)

cfg = hydra.compose(config_name=CONFIG_NAME, overrides=[
f'experiment_name={EXPERIMENT}',
f'group={SAVE_DIR}',
'log_config=true',
'planner=ml_planner',
'model=vector_model',
'planner.model_config=${model}', # hydra notation to select model config
f'planner.checkpoint_path={MODEL_PATH}', # this path can be replaced by the checkpoint of the model trained in the previous section
f'+simulation={CHALLENGE}',
*DATASET_PARAMS,
])

main_simulation(cfg)

parent_dir = Path(SAVE_DIR) / EXPERIMENT
results_dir = list(parent_dir.iterdir())[0] # get the child dir
nuboard_file_2 = [str(file) for file in results_dir.iterdir() if file.is_file() and file.suffix == '.nuboard'][0]

Tokens of all 27 simulated scenarios:

2022-03-23 16:13:17,122 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/utils/multithreading/worker_pool.py:107} Submitting 27 tasks!
2022-03-23 16:13:17,123 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 168fbafc3f75591f8e81fd6df4a570a8!
2022-03-23 16:13:17,123 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: a893e3a25fef52899f5da64c952fdc3b!
2022-03-23 16:13:17,123 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 8b1a8a569bb557d2a9c52066f5ca0db3!
2022-03-23 16:13:17,123 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: c44e3326dc765b648c7998416d564336!
2022-03-23 16:13:17,124 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 1e307609a66e5a3689f5fe37e6aa1c9a!
2022-03-23 16:13:17,124 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: d700fd9dd0835c0486ef778d7e18038e!
2022-03-23 16:13:17,124 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: d548ccbb4f485e3e909c2ef1c08ec463!
2022-03-23 16:13:17,125 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 19efe622ebca5dc6b292256262e370f2!
2022-03-23 16:13:17,125 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 15adef31b356566a8ac04476ac36b549!
2022-03-23 16:13:17,127 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 883e15a78fe85bb9a28094d524ddd85b!
2022-03-23 16:13:17,127 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: bd3a5e26736a514daaa2578adfd97cdc!
2022-03-23 16:13:17,128 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 4fd5892847d655f2bd83cff575da72fd!
2022-03-23 16:13:17,129 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 9f144ba21f505b568cd531bbe409e6f2!
2022-03-23 16:13:17,130 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 4ba45c834ad9521dbdc3a23bfdab7e06!
2022-03-23 16:13:17,131 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 248db069905951e183077e8e60b31cb3!
2022-03-23 16:13:17,131 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 2869c06d987f54f79d3b62386bd83dda!
2022-03-23 16:13:17,133 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 703a10e3ceb05b1889a47476b326b893!
2022-03-23 16:13:17,134 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: e06c611312c35fb7a705165e8d65aa4e!
2022-03-23 16:13:17,134 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 92a1c31291d15200b144897759cee3fb!
2022-03-23 16:13:17,135 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: b06b6d62a9b85f528f1e300df3dbc9e0!
2022-03-23 16:13:17,135 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 6c096142d2f8529d997176098013d769!
2022-03-23 16:13:17,136 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 95a76deab8305706992041a26c4aaf0a!
2022-03-23 16:13:17,136 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 9557cdb45f4b5f4d9053f81e5d9c07c6!
2022-03-23 16:13:17,137 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: e2ee4264e4635ba4accccefa430dc231!
2022-03-23 16:13:17,137 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: 8572947abcea54b298e7371b7b3252c8!
2022-03-23 16:13:17,138 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: a2ea335b69c55dd290804d090625db82!
2022-03-23 16:13:17,138 INFO {/home/qcraft/nuplan-devkit/nuplan/planning/simulation/simulation.py:178} Starting simulation with scenario name: ca6982e586765eccb362025cca5357b4!

@yangchentao-common
Copy link

i have the same problem.have you resolve it?

@kokseang-motional
Copy link
Contributor

Hey @shubaozhang @yangchentao-common
Do u still experience the same issue with the latest update?

@kokseang-motional
Copy link
Contributor

Close the issue now. Please feel free to open another issue if you experience the same issue again
Thanks

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

No branches or pull requests

3 participants