bark-simulator / bark

Open-Source Framework for Development, Simulation and Benchmarking of Behavior Planning Algorithms for Autonomous Driving
https://bark-simulator.github.io/
MIT License
287 stars 69 forks source link

spawn agents #521

Closed tinmodeHuang closed 3 years ago

tinmodeHuang commented 3 years ago

a road with two lane, self._ds_min, self._ds_max = 7, 12 for left lane, self._s_min, self._s_max = 3, 44 for other one, self._s_min, self._s_max = 3, 26 there should are only 8 agents generated in observation of the world, but it is learned from the simplified output printed that 9 agents were generated.

{0: bark.agent.Agent, 1: bark.agent.Agent, 2: bark.agent.Agent, 3: bark.agent.Agent, 4: bark.agent.Agent, 6: bark.agent.Agent, 7: bark.agent.Agent}
{0: bark.agent.Agent, 1: bark.agent.Agent, 2: bark.agent.Agent, 3: bark.agent.Agent, 4: bark.agent.Agent, 5: bark.agent.Agent, 7: bark.agent.Agent, 8: bark.agent.Agent, 9: bark.agent.Agent}
Traceback (most recent call last):
  File "/home/tinmode/.cache/bazel/_bazel_tinmode/0534ffbce5f0177dc35c2eb30e06c204/execroot/bark_ml/bazel-out/k8-fastbuild/bin/examples/tfa_gnn.runfiles/bark_ml/examples/tfa_gnn.py", line 88, in <module>

...

  File "/home/tinmode/.cache/bazel/_bazel_tinmode/0534ffbce5f0177dc35c2eb30e06c204/execroot/bark_ml/bazel-out/k8-fastbuild/bin/examples/tfa_gnn.runfiles/bark_ml/bark_ml/environments/single_agent_runtime.py", line 56, in reset
    return self._observer.Observe(observed_world)
  File "/home/tinmode/.cache/bazel/_bazel_tinmode/0534ffbce5f0177dc35c2eb30e06c204/execroot/bark_ml/bazel-out/k8-fastbuild/bin/examples/tfa_gnn.runfiles/bark_ml/bark_ml/observers/graph_observer.py", line 122, in Observe
    edge_features[index, target_index, :] = self._extract_edge_features(agent, nearby_agent)
IndexError: index 8 is out of bounds for axis 1 with size 8

I have been confused about it after checked out the config_with_ease.pyto generate agents several times. I'll appreciate it if you could make it clear.

patrickhart commented 3 years ago

Sampling is applied in the ConfigWithEase scenario generation.

In these two spots sampling is being applied:

If you want a deterministic scenario, I would recommend you to overwrite the def position(self, world): function with one that does not make use of sampling and that has no call to self.ds(). However, in terms of training a behavior policy a varying number of vehicles might avoid overfitting.

tinmodeHuang commented 3 years ago

I have already checked the scenario generation quite many times, the maximum number of agents generated shoule be 8 by calculating instead of 9, I wonder what was omitted

patrickhart commented 3 years ago

how did you calculate this? I think only the rear point of the vehicle is used in the simple scenario generation (config with ease).

For more elaborate uses I would recommend using the ConfigurableScenarioGeneration.

tinmodeHuang commented 3 years ago

the function position() of theLaneCorridorConfigclass define calculation of the number of agents to generate. for left lane, self._s_min, self._s_max = 3, 44, with the minimum spacing self._ds_min=7, the number of agents which can be generated in the range (3, 44) is 5. (44-3)//7=5 for right lane, self._s_min, self._s_max = 3, 26, with the minimum spacing self._ds_min=7, the number of agents which can be generated in the range (3, 26) is 5. (26-3)//7=3

patrickhart commented 3 years ago

I assume you are talking about https://github.com/bark-simulator/bark-ml/blob/b9b42ab8124ab31781573b6a804e762271ca4ce6/bark_ml/environments/blueprints/merging/merging.py#L65

Have a look at the values in the blueprint. The ranges have been slightly changed in the latest push to make the traffic more realitistic.

tinmodeHuang commented 3 years ago

Yeap, the value of sef._ds_minabove is from ds_min in densemode

patrickhart commented 3 years ago

So we have 40//7=5 and 20//7=2. each can have a starting position at zero. Thus, 5+1and 2+1 equals 9. So I think this should be correct, but in case you find a fix for it can also create a pull request.

tinmodeHuang commented 3 years ago

here starting positions is at self._s_min, namely three, this is reason why the subtracter is 3 in the expression (26-3)//7=3 instead of zero


  def position(self, world):
...
    if self._current_s == None:
      self._current_s = np.random.uniform(self._s_min, self._ds_max)
    xy_point =  GetPointAtS(centerline, self._current_s)
    angle = GetTangentAngleAtS(centerline, self._current_s)
    if self._current_s > self._s_max:
      return None
    self._current_s += self.ds()
    return (xy_point.x(), xy_point.y(), angle)
patrickhart commented 3 years ago

I cannot follow your calculation exactly. However, does it really matter if there are 8 or 9 vehicles generated? Traffic also varies in reality by number and order. To trace the number during training and evaluation you could implement a vehicle count evaluator.

Will close this for now.