Open DMarcelAM opened 5 years ago
hi @DMarcelAM I feel like the issue might have something to do with your definition of the observation_space
or action_space
variables in your environment. In order to help me reproduce your bug, would you be able to share these methods as well? Thank you!
Hi @AboudyKreidieh , the network I am importing is an intersection too, so I didn't change these methods from green_wave_env. Thanks for answer.
@property
def action_space(self):
"""See class definition."""
if self.discrete:
return Discrete(2 ** self.num_traffic_lights)
else:
return Box(
low=-1,
high=1,
shape=(self.num_traffic_lights,),
dtype=np.float32)
@property
def observation_space(self):
"""See class definition."""
speed = Box(
low=0,
high=1,
shape=(self.scenario.vehicles.num_vehicles,),
dtype=np.float32)
dist_to_intersec = Box(
low=0.,
high=np.inf,
shape=(self.scenario.vehicles.num_vehicles,),
dtype=np.float32)
edge_num = Box(
low=0.,
high=1,
shape=(self.scenario.vehicles.num_vehicles,),
dtype=np.float32)
traffic_lights = Box(
low=0.,
high=1,
shape=(3 * self.rows * self.cols,),
dtype=np.float32)
return Tuple((speed, dist_to_intersec, edge_num, traffic_lights))
Ah, I see. I believe that since you are using a template, and thereby not originating the network with a set number of vehicles, self.scenario.vehicles.num_vehicles
is initialized to 0, resulting in the (0,) shape bug. You can consider replacing these variables with a fixed (non-zero) number and that should do the trick.
Let me know if it doesn't work and I'll be happy to iterate through this with you.
I was trying with different numbers but I'm obtaining similar errors,
I set self.scenario.vehicles.num_vehicles = 1
I get ValueError: cannot reshape array of size 2 into shape (1,).
I set self.scenario.vehicles.num_vehicles = 2
I get ValueError: cannot reshape array of size 1 into shape (2,).
I set self.scenario.vehicles.num_vehicles = 3
I get ValueError: cannot reshape array of size 1 into shape (3,).
When I set self.scenario.vehicles.num_vehicles = X
I get ValueError: cannot reshape array of size 1 into shape (X,).
except with X=1
I set num_vehicles=0 in green_wave example (tot_cars=0) and there's no error. But when I add inflows to green_wave_example I get the same error: ValueError: cannot reshape array of size 1 into shape (0,)
By the way, when I don't use inflows and set num_vehicles=0 in my code it runs good. What can I do if I want to use inflows ?
I think the environment you are using may include a get_state
method that doesn't take into account variability in the number of vehicles, hence the shape error when you turn on inflows. You can probably debug this by printing self.state.shape
or len(self.state)
and seeing if the number changes. If so, I wont recommend padding the observations (see flow/envs/merge.py as an example).
Hi @AboudyKreidieh and thanks for answer my questions, When you say that my get_state method should not take into account variability in the number of vehicles, how can I use the speed of each vehicle (the number of vehicles is still variable) as a state ?
Hi @DMarcelAM, the tricky thing is that unless you use something special, a neural network takes in a fixed number of states as its input. If the number of states is variable, you either have to: (1) Figure out how to select a fixed number of vehicle states from the total number of vehicle states (2) Use a neural net architecture that can adapt to the number of vehicles in the system like a transformer (3) Convert the problem into some other format where the number of vehicle states is fixed.
So, for example, you could imagine you only include the states of the 10 vehicles closest to the intersection or something like that.
Hi @DMarcelAM, the tricky thing is that unless you use something special, a neural network takes in a fixed number of states as its input. If the number of states is variable, you either have to: (1) Figure out how to select a fixed number of vehicle states from the total number of vehicle states (2) Use a neural net architecture that can adapt to the number of vehicles in the system like a transformer (3) Convert the problem into some other format where the number of vehicle states is fixed.
So, for example, you could imagine you only include the states of the 10 vehicles closest to the intersection or something like that.
Hi, I got a similar error when testing flow_mappdg on singleagent_traffic_light_grid, the error is
~/git/flow/flow/envs/base.py", line 334 in step
self.observed_ids.update(self.k.vehicle.get_ids())
AttributeError: 'list' object has no attribute 'update'
Letting it print out observed_ids and its type and it really is a list instead of a supposed dict.
['idm_3', 'idm_16', 'idm_10', 'idm_4', 'idm_12', 'idm_2', 'idm_0', 'idm_15', 'idm_11', 'idm_19', 'idm_9', 'idm_6', 'idm_7', 'idm_5', 'idm_8', 'idm_13', 'idm_18', 'idm_17', 'idm_14', 'idm_1']
EDIT:
KeyError: 'idm_X'
came up after manually converting _observedids and _observerd_rlids to "set", will keep looking into this, appreciate if you could give a test on light grid scripts :) @eugenevinitsky
Hello, I have imported a sumo network file (net.xml) and I want to train RL traffic lights in this scenario. In order to do this I have create a custom scenario (with the routes) and a custom enviroment (based on green_wave_env) to train the RL traffic lights. But I am getting some errors.
Here is the code I used (based on green_wave example):
Here are the errors I get:
I have been trying with differentes sumo networks files but I always get the first error and the " shape (0,) " in the second error.
Thanks for your time and regards.