Skip to content

Commit

Permalink
major changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirezaMorsali committed Oct 15, 2022
1 parent 754fe15 commit 01df2b2
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 193 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 8 additions & 2 deletions docs/source/examples/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Examples
Several examples are provided [here](https://github.com/inverted-ai/invertedai/tree/master/examples).
## Demo
- **Goolge Colab**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/inverted-ai/invertedai-drive/blob/develop/examples/Colab-Demo.ipynb)
- Running a demo on **Goolge Colab**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/inverted-ai/invertedai-drive/blob/develop/examples/Colab-Demo.ipynb)

- **Locally**: Download the
- Running a demo **Locally**: Download the
<a href="https://minhaskamal.github.io/DownGit/#/home?url=https://github.com/inverted-ai/invertedai/tree/master/examples" target="_blank">examples directory</a>, navigate to the unzipped directory in terminal and run

```
Expand All @@ -14,5 +14,11 @@ pip install -r requirements.txt
.venv/bin/jupyter notebook Drive-Demo.ipynb
```

---
```{toctree}
:maxdepth: 2
```



13 changes: 6 additions & 7 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Get Started


```{toctree}
:maxdepth: 4
:maxdepth: 2
getstarted/index
pythonapi/index
Expand All @@ -47,12 +47,12 @@ apireference
carlasim
```

```{toctree}
:caption: Python SDK Library
:maxdepth: 2
<!-- ```{toctree} -->
<!-- :caption: Python SDK Library -->
<!-- :maxdepth: 2 -->

modules/modules
```
<!-- modules/modules -->
<!-- ``` -->


```{eval-rst}
Expand All @@ -62,4 +62,3 @@ REFERENCES
* :ref:`modindex`
* :ref:`search`
```

1 change: 1 addition & 0 deletions docs/source/pythonapi/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sdk-drive
sdk-initialize
sdk-available-locations
sdk-location-info
sdk-dataclasses
```


14 changes: 14 additions & 0 deletions docs/source/pythonapi/sdk-dataclasses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# DataClasses


```{eval-rst}
.. automodule:: invertedai.models
:members:
:undoc-members:
:show-inheritance:
```

<!-- .. autoclass:: invertedai.api_resources.TestReturn -->



2 changes: 0 additions & 2 deletions docs/source/pythonapi/sdk-drive.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
```{eval-rst}
.. autofunction:: invertedai.api_resources.drive
```


2 changes: 0 additions & 2 deletions docs/source/pythonapi/sdk-location-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
```{eval-rst}
.. autofunction:: invertedai.api_resources.location_info
```


34 changes: 17 additions & 17 deletions examples/Colab-Demo.ipynb

Large diffs are not rendered by default.

33 changes: 17 additions & 16 deletions examples/Demo_Drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,44 @@
iai.add_apikey("")

response = iai.available_locations("carla", "roundabout")
breakpoint()
response = iai.location_info(location=args.location)

file_name = args.location.replace(":", "_")
if response["lanelet_map_source"] is not None:
if response.lanelet_map_source is not None:
file_path = f"{file_name}.osm"
with open(file_path, "w") as f:
f.write(response["lanelet_map_source"])
if response["rendered_map"] is not None:
f.write(response.lanelet_map_source)
if response.rendered_map is not None:
file_path = f"{file_name}.jpg"
rendered_map = np.array(response["rendered_map"], dtype=np.uint8)
rendered_map = np.array(response.rendered_map, dtype=np.uint8)
image = cv2.imdecode(rendered_map, cv2.IMREAD_COLOR)
cv2.imwrite(file_path, image)

response = iai.initialize(
location=args.location,
agent_count=10,
)
agent_attributes = response["attributes"]
agent_sizes = response.agent_sizes
frames = []
for i in tqdm(range(50)):
pbar = tqdm(range(50))
for i in pbar:
response = iai.drive(
agent_attributes=agent_attributes,
states=response["states"],
recurrent_states=response["recurrent_states"],
agent_sizes=agent_sizes,
agent_states=response.agent_states,
recurrent_states=response.recurrent_states,
get_birdviews=True,
location=args.location,
steps=1,
traffic_states_id=response["traffic_states_id"],
traffic_states_id=response.traffic_states_id,
get_infractions=True,
)
print(
f"Collision rate: {100*np.array(response['collision'])[-1, :].mean():.2f}% | "
+ f"Off-road rate: {100*np.array(response['offroad'])[-1, :].mean():.2f}% | "
+ f"Wrong-way rate: {100*np.array(response['wrong_way'])[-1, :].mean():.2f}%"
pbar.set_description(
f"Collision rate: {100*np.array(response.collision)[-1, :].mean():.2f}% | "
+ f"Off-road rate: {100*np.array(response.offroad)[-1, :].mean():.2f}% | "
+ f"Wrong-way rate: {100*np.array(response.wrong_way)[-1, :].mean():.2f}%"
)

birdview = np.array(response["bird_view"], dtype=np.uint8)
birdview = np.array(response.bird_view, dtype=np.uint8)
image = cv2.imdecode(birdview, cv2.IMREAD_COLOR)
frames.append(image)
im = PImage.fromarray(image)
Expand Down
32 changes: 16 additions & 16 deletions examples/Drive-Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 1,
"id": "911445d4-8b61-49a1-9620-d1f3eb0c4199",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib widget\n",
"# import sys\n",
"# sys.path.append('../')\n",
"import sys\n",
"sys.path.append('../')\n",
"# !pip install invertedai==0.0.3rc0\n",
"from IPython.display import clear_output\n",
"from invertedai import Jupyter_Render\n",
Expand All @@ -29,7 +29,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 2,
"id": "d6b93c9a-a972-4c40-9d6d-2b21f3215b39",
"metadata": {},
"outputs": [
Expand All @@ -49,14 +49,14 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 3,
"id": "069cf9cb-30eb-4378-b4f9-9cb7d9038620",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0299dc9be2d546cfa8126756ec8722f7",
"model_id": "96720695a1a74d45aea3100d5df4f957",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -70,7 +70,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "789d889962b1437b9bd9d650f7a66a2b",
"model_id": "3d93a85cac944aca9b48e3ee5a784338",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -102,41 +102,41 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 5,
"id": "94506da0-9a15-4dc0-9d57-5ac30bc36d72",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Unable to spawn a scenario for 10 agents, 1 spawned instead.\n"
"Unable to spawn a scenario for 10 agents, 8 spawned instead.\n"
]
}
],
"source": [
"rendered_map = iai.location_info(location=location)['rendered_map']\n",
"rendered_map = iai.location_info(location=location).rendered_map\n",
"rendered_map = cv2.imdecode(np.array(rendered_map, dtype=np.uint8), cv2.IMREAD_COLOR)\n",
"renderer.add_frame(rendered_map)\n",
"\n",
"response = iai.initialize(\n",
" location=location,\n",
" agent_count=10,\n",
")\n",
"agent_attributes = response[\"attributes\"]\n",
"agent_sizes = response.agent_sizes\n",
"frames = []\n",
"for t in range(simulation_length):\n",
" response = iai.drive(\n",
" agent_attributes=agent_attributes,\n",
" states=response[\"states\"],\n",
" recurrent_states=response[\"recurrent_states\"],\n",
" agent_sizes=agent_sizes,\n",
" agent_states=response.agent_states,\n",
" recurrent_states=response.recurrent_states,\n",
" get_birdviews=True,\n",
" location=location,\n",
" steps=1,\n",
" exclude_ego_agent=1,\n",
" traffic_states_id=response[\"traffic_states_id\"],\n",
" traffic_states_id=response.traffic_states_id,\n",
" )\n",
" birdview = cv2.imdecode(np.array(response[\"bird_view\"], dtype=np.uint8), cv2.IMREAD_COLOR)\n",
" birdview = cv2.imdecode(np.array(response.bird_view, dtype=np.uint8), cv2.IMREAD_COLOR)\n",
" renderer.add_frame(birdview)"
]
},
Expand Down
Binary file modified examples/iai-drive.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 01df2b2

Please sign in to comment.