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

Remove vehicles with invalid positions and invalid goals from controlled vehicles #24

Merged
merged 2 commits into from
Jan 20, 2024

Conversation

daphne-cornelisse
Copy link
Collaborator

@daphne-cornelisse daphne-cornelisse commented Jan 7, 2024

Problem description

In the env.reset() function, vehicles in invalid positions are removed from the scene but are still added to self.controlled_vehicles. This leads to invalid samples (invalid observations) that cause three issues:

  1. We attempt to control vehicles that remain in invalid states, which happens every time env.step(.) is called.
  2. An extra vehicle is counted when calculating the goal rate.
  3. Invalid observations have an unrealistically large speed and distance to goal value, which introduces noise in the training data.

NOTE: these are vehicles that are not included in the valid_files.json, and so they are not set to be expert-controlled.

This fix (details below) reduces the number of invalid samples from 4.62% to 0.34% (the total number of scenes is 1000). The variable "self.invalid_samples" tracks the number of invalid samples.

Steps to reproduce

  1. Download the nocturne mini dataset
  2. Set the data_path: ./data_full/train in env_config
  3. Comment out the fix
  4. Run the code below
  5. This should show the logs below

Code:

# Load environment variables and config
env_config = load_config("env_config")
  
# Initialize an environment
env = BaseEnv(config=env_config)

# This is an example scene that can be used to reproduce this error 
filename = "tfrecord-00703-of-01000_46.json"

# Reset to this specific scene
obs_dict = env.reset(filename)

# Step
env.step({})

Logs

DEBUG:root:(IN RESET) selecting vehicles to control, current list: []
DEBUG:root:looking at veh_id 26...
DEBUG:root:updated self.controlled_vehicles: [26]
DEBUG:root:looking at veh_id 17...
DEBUG:root:updated self.controlled_vehicles: [26, 17]
DEBUG:root:looking at veh_id 3...
DEBUG:root:veh_id 3 is INVALID!
DEBUG:root:updated self.controlled_vehicles: [26, 17, 3]

INFO:root:(IN STEP) t = 1 | tfrecord-00703-of-01000_46.json
INFO:root:veh_id = 3 | pos: -10000.0
INFO:root:controlled_vehs: [26, 17, 3] 

Solution

Added booleans to make sure vehicles at invalid positions and with invalid goals are not included in self.controlled_vehicles

# Otherwise the vehicle is valid and we add it to the list of controlled vehicles
if not vehicle.expert_control \
and not veh_at_invalid_pos \
and not veh_has_invalid_goal_pos \
and curr_index < self.config.max_num_vehicles:
	self.controlled_vehicles.append(vehicle)
	logging.debug(f'updated self.controlled_vehicles: {[veh.id for veh in self.controlled_vehicles]}')
	curr_index += 1

Questions

  • Check: Would you mind reviewing this and checking if it does not introduce any new bugs?
  • Open question: 0.34% of the samples are still invalid (with 1000 scenes, so it could increase/decrease with the full data set). This issue occurs in the env.step() function, where a vehicle's position is sometimes invalid (the position is -10,000), but then becomes normal again in the next step. Do you have any idea where this issue could be coming from?

@daphne-cornelisse daphne-cornelisse changed the title Remove vehicles with invalid positions and invalid goals from the scene Remove vehicles with invalid positions and invalid goals from controlled vehicles Jan 7, 2024
@@ -149,6 +158,15 @@ def step( # pylint: disable=arguments-renamed,too-many-locals,too-many-branches
veh_id = veh_obj.getID()
if veh_id in self.done_ids:
continue

# Remove vehicle from the scene if position is invalid (but not collided or goal achieved?)

Choose a reason for hiding this comment

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

I'm guessing that this condition, which is post reset, is only getting triggered for vehicles that are expert controlled. The expert controlled vehicles will occasionally pop to the invalid position

@daphne-cornelisse daphne-cornelisse changed the base branch from main to hr_rl January 20, 2024 18:27
@daphne-cornelisse daphne-cornelisse marked this pull request as ready for review January 20, 2024 18:29
@daphne-cornelisse daphne-cornelisse merged commit 2c0cb9b into hr_rl Jan 20, 2024
1 of 4 checks passed
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