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

Object Heights #305

Closed
wants to merge 13 commits into from
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,41 @@ We are open-sourcing a policy trained on 1,000 randomly sampled scenarios. You c

### Download the dataset

Two versions of the dataset are available:
- Two versions of the dataset are available, a [mini version](https://huggingface.co/datasets/EMERGE-lab/GPUDrive_mini) with a 1000 training files and 300 test/validation files, and the [full sized dataset](https://huggingface.co/datasets/EMERGE-lab/GPUDrive) with over a 100k unique scenes.
- Replace 'GPUDrive_mini' with 'GPUDrive' below if you wish to download the full dataset.
- To download the dataset you need the huggingface_hub library:
```bash
pip install huggingface_hub
```
Then you can download the dataset using python or just `huggingface-cli`.

Option 1: Using Python:
```python
>>> from huggingface_hub import snapshot_download
>>> snapshot_download(repo_id="EMERGE-lab/GPUDrive_mini", repo_type="dataset", local_dir="data/processed")
```
Option 2: Use the huggingface-cli:

1. Log in to your Hugging Face account:
```bash
huggingface-cli login
```

2. Download the dataset:
nadarenator marked this conversation as resolved.
Show resolved Hide resolved
```bash
huggingface-cli download EMERGE-lab/GPUDrive_mini --local-dir data/processed --repo-type "dataset"
```

Option 3: Manual Download:

- a mini-one that is about 1 GB and consists of 1000 training files and 100 validation / test files at: [Dropbox Link](https://www.dropbox.com/sh/8mxue9rdoizen3h/AADGRrHYBb86pZvDnHplDGvXa?dl=0).
- the full dataset (150 GB) and consists of 134453 training files and 12205 validation / test files: [Dropbox Link](https://www.dropbox.com/sh/wv75pjd8phxizj3/AABfNPWfjQdoTWvdVxsAjUL_a?dl=0)
1. Visit https://huggingface.co/datasets/EMERGE-lab/GPUDrive_mini
2. Navigate to the Files and versions tab.
3. Download the desired files/directories.

The simulator supports initializing scenes from the `Nocturne` dataset. The input parameter for the simulator `json_path` takes in a path to a directory containing the files in the Nocturne format. The `SceneConfig` dataclass in `pygpudrive/env/config.py` dataclass is used to configure how scenes are selected from a folder with traffic scenarios.

### Re-building the dataset

GPUDrive is compatible with the complete [Waymo Open Motion Dataset](https://github.com/waymo-research/waymo-open-dataset), which contains over 100,000 scenarios. To download new files and create scenarios for the simulator, follow these three steps.
If you wish to manually generate the dataset, GPUDrive is compatible with the complete [Waymo Open Motion Dataset](https://github.com/waymo-research/waymo-open-dataset), which contains over 100,000 scenarios. To download new files and create scenarios for the simulator, follow these three steps.

1. First, head to [https://waymo.com/open/](https://waymo.com/open/) and click on the "download" button a the top. After registering, click on the files from `v1.2.1 March 2024`, the newest version of the dataset at the time of wrting (10/2024). This will lead you a Google Cloud page. From here, you should see a folder structure like this:

Expand Down
24 changes: 16 additions & 8 deletions pygpudrive/datatypes/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class LocalEgoState:
speed: Speed of the agent in relative coordinates.
vehicle_length: Length of the agent's bounding box.
vehicle_width: Width of the agent's bounding box.
vehicle_height: Height of the agent's bounding box.
rel_goal_x: Relative x-coordinate to the goal.
rel_goal_y: Relative y-coordinate to the goal.
is_collided: Whether the agent is in collision with another object.
Expand All @@ -25,10 +26,11 @@ def __init__(self, self_obs_tensor: torch.Tensor):
self.speed = self_obs_tensor[:, :, 0]
self.vehicle_length = self_obs_tensor[:, :, 1]
self.vehicle_width = self_obs_tensor[:, :, 2]
self.rel_goal_x = self_obs_tensor[:, :, 3]
self.rel_goal_y = self_obs_tensor[:, :, 4]
self.is_collided = self_obs_tensor[:, :, 5]
self.id = self_obs_tensor[:, :, 6]
self.vehicle_height = self_obs_tensor[:, :, 3]
nadarenator marked this conversation as resolved.
Show resolved Hide resolved
self.rel_goal_x = self_obs_tensor[:, :, 4]
self.rel_goal_y = self_obs_tensor[:, :, 5]
self.is_collided = self_obs_tensor[:, :, 6]
self.id = self_obs_tensor[:, :, 7]

@classmethod
def from_tensor(
Expand All @@ -48,6 +50,7 @@ def normalize(self):
self.speed = self.speed / constants.MAX_SPEED
self.vehicle_length = self.vehicle_length / constants.MAX_VEH_LEN
self.vehicle_width = self.vehicle_width / constants.MAX_VEH_WIDTH
self.vehicle_height = self.vehicle_height / constants.MAX_VEH_HEIGHT
self.rel_goal_x = normalize_min_max(
tensor=self.rel_goal_x,
min_val=constants.MIN_REL_GOAL_COORD,
Expand All @@ -70,7 +73,7 @@ def shape(self) -> tuple[int, ...]:
class GlobalEgoState:
"""A class to represent the ego state of the agent in global coordinates.
Initialized from abs_self_obs_tensor (src/bindings). For details, see
`AbsoluteSelfObservation` in src/types.hpp. Shape: (num_worlds, max_agents, 13).
`AbsoluteSelfObservation` in src/types.hpp. Shape: (num_worlds, max_agents, 14).

Attributes:
pos_x: Global x-coordinate of the agent.
Expand All @@ -82,6 +85,7 @@ class GlobalEgoState:
goal_y: Global y-coordinate of the goal.
vehicle_length: Length of the agent's bounding box.
vehicle_width: Width of the agent's bounding box.
vehicle_height: Height of the agent's bounding box.
id: Unique identifier of the agent.
"""

Expand All @@ -96,7 +100,8 @@ def __init__(self, abs_self_obs_tensor: torch.Tensor):
self.goal_y = abs_self_obs_tensor[:, :, 9]
self.vehicle_length = abs_self_obs_tensor[:, :, 10]
self.vehicle_width = abs_self_obs_tensor[:, :, 11]
self.id = abs_self_obs_tensor[:, :, 12]
self.vehicle_height = abs_self_obs_tensor[:, :, 12]
self.id = abs_self_obs_tensor[:, :, 13]

@classmethod
def from_tensor(
Expand Down Expand Up @@ -130,6 +135,7 @@ class PartnerObs:
orientation: torch.Tensor
vehicle_length: torch.Tensor
vehicle_width: torch.Tensor
vehicle_height: torch.Tensor
agent_type: torch.Tensor
ids: torch.Tensor

Expand All @@ -148,8 +154,9 @@ def __init__(self, partner_obs_tensor: torch.Tensor):
self.orientation = partner_obs_tensor[:, :, :, 3].unsqueeze(-1)
self.vehicle_length = partner_obs_tensor[:, :, :, 4].unsqueeze(-1)
self.vehicle_width = partner_obs_tensor[:, :, :, 5].unsqueeze(-1)
self.agent_type = partner_obs_tensor[:, :, :, 6].unsqueeze(-1)
self.ids = partner_obs_tensor[:, :, :, 7].unsqueeze(-1)
self.vehicle_height = partner_obs_tensor[:, :, :, 6].unsqueeze(-1)
self.agent_type = partner_obs_tensor[:, :, :, 7].unsqueeze(-1)
self.ids = partner_obs_tensor[:, :, :, 8].unsqueeze(-1)

@classmethod
def from_tensor(
Expand Down Expand Up @@ -180,6 +187,7 @@ def normalize(self):
self.orientation = self.orientation / constants.MAX_ORIENTATION_RAD
self.vehicle_length = self.vehicle_length / constants.MAX_VEH_LEN
self.vehicle_width = self.vehicle_width / constants.MAX_VEH_WIDTH
self.vehicle_heights = self.vehicle_heights / constants.MAX_VEH_HEIGHT
self.agent_type = self.agent_type.long()
self.ids = self.ids

Expand Down
1 change: 1 addition & 0 deletions pygpudrive/env/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MAX_SPEED = 100
MAX_VEH_LEN = 30
MAX_VEH_WIDTH = 10
MAX_VEH_HEIGHT = 3
MIN_REL_GOAL_COORD = -1000
MAX_REL_GOAL_COORD = 1000
MIN_REL_AGENT_POS = -1000
Expand Down
3 changes: 1 addition & 2 deletions src/init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ namespace gpudrive
struct MapObject
{
MapVector2 position[MAX_POSITIONS];
float width;
float length;
VehicleSize vehicle_size;
float heading[MAX_POSITIONS];
MapVector2 velocity[MAX_POSITIONS];
bool valid[MAX_POSITIONS];
Expand Down
5 changes: 3 additions & 2 deletions src/json_serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ namespace gpudrive
}
}
obj.numPositions = i;
j.at("width").get_to(obj.width);
j.at("length").get_to(obj.length);
j.at("width").get_to(obj.vehicle_size.width);
j.at("length").get_to(obj.vehicle_size.length);
j.at("height").get_to(obj.vehicle_size.height);

i = 0;
for (const auto &h : j.at("heading"))
Expand Down
4 changes: 2 additions & 2 deletions src/level_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ static inline Entity createAgent(Engine &ctx, const MapObject &agentInit) {
auto agent = ctx.makeRenderableEntity<Agent>();
auto agent_iface = ctx.get<AgentInterfaceEntity>(agent).e = ctx.makeEntity<AgentInterface>();

ctx.get<VehicleSize>(agent) = {.length = agentInit.length, .width = agentInit.width};
ctx.get<Scale>(agent) = Diag3x3{.d0 = agentInit.length/2, .d1 = agentInit.width/2, .d2 = 1};
ctx.get<VehicleSize>(agent) = agentInit.vehicle_size;
ctx.get<Scale>(agent) = Diag3x3{.d0 = agentInit.vehicle_size.length/2, .d1 = agentInit.vehicle_size.width/2, .d2 = 1};
ctx.get<Scale>(agent) *= consts::vehicleLengthScale;
ctx.get<ObjectID>(agent) = ObjectID{(int32_t)SimObject::Agent};
ctx.get<EntityType>(agent) = agentInit.type;
Expand Down
62 changes: 32 additions & 30 deletions src/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ namespace gpudrive
NUM_TYPES = 21,
};

struct AgentID {
int32_t id;
};
struct AgentID
{
int32_t id;
};

struct VehicleSize
{
float length;
float width;
float height;
};

struct Goal
Expand Down Expand Up @@ -179,19 +181,19 @@ struct AgentID {
VehicleSize vehicle_size;
Goal goal;
float collisionState;
float id;
float id;
static inline SelfObservation zero()
{
return SelfObservation{
.speed = 0,
.vehicle_size = {0, 0},
.vehicle_size = {0, 0, 0},
.goal = {.position = {0, 0}},
.collisionState = 0,
.id = -1};
.id = -1};
}
};

const size_t SelfObservationExportSize = 7;
const size_t SelfObservationExportSize = 8; // 1 + 3 + 2 + 1 + 1

static_assert(sizeof(SelfObservation) == sizeof(float) * SelfObservationExportSize);

Expand All @@ -217,7 +219,7 @@ struct AgentID {
}
};

const size_t MapObservationExportSize = 9;
const size_t MapObservationExportSize = 9; // 2 + 3 + 1 + 1 + 1 + 1

static_assert(sizeof(MapObservation) == sizeof(float) * MapObservationExportSize);

Expand All @@ -228,37 +230,37 @@ struct AgentID {
float heading;
VehicleSize vehicle_size;
float type;
float id;

static inline PartnerObservation zero() {
return PartnerObservation{
.speed = 0,
.position = {0, 0},
.heading = 0,
.vehicle_size = {0, 0},
.type = static_cast<float>(EntityType::None),
.id = -1};
}
};
float id;

struct RoadMapId{
int32_t id;
static inline PartnerObservation zero() {
return PartnerObservation{
.speed = 0,
.position = {0, 0},
.heading = 0,
.vehicle_size = {0, 0, 0},
.type = static_cast<float>(EntityType::None),
.id = -1};
}
};

const size_t RoadMapIdExportSize = 1;

static_assert(sizeof(RoadMapId) == sizeof(int) * RoadMapIdExportSize);

// Egocentric observations of other agents
struct PartnerObservations
{
PartnerObservation obs[consts::kMaxAgentCount - 1];
};

const size_t PartnerObservationExportSize = 8;
const size_t PartnerObservationExportSize = 9; // 1 + 2 + 1 + 3 + 1 + 1

static_assert(sizeof(PartnerObservations) == sizeof(float) *
(consts::kMaxAgentCount - 1) * PartnerObservationExportSize);
(consts::kMaxAgentCount - 1) * PartnerObservationExportSize);

struct RoadMapId{
int32_t id;
};

const size_t RoadMapIdExportSize = 1;

static_assert(sizeof(RoadMapId) == sizeof(int) * RoadMapIdExportSize);

struct AgentMapObservations
{
Expand Down Expand Up @@ -340,7 +342,7 @@ struct AgentID {

struct AbsoluteRotation
{
Rotation rotationAsQuat;
Rotation rotationAsQuat; // x, y, z, w
float rotationFromAxis;
};

Expand All @@ -353,7 +355,7 @@ struct AgentID {
float id;
};

const size_t AbsoluteSelfObservationExportSize = 13; // 3 + 4 + 1 + 2 + 2
const size_t AbsoluteSelfObservationExportSize = 14; // 3 + 5 + 2 + 3 + 1

static_assert(sizeof(AbsoluteSelfObservation) == sizeof(float) * AbsoluteSelfObservationExportSize);

Expand Down
Loading