Skip to content

Commit

Permalink
Merge pull request #143 from inverted-ai/develop
Browse files Browse the repository at this point in the history
Fixed a link in README pointing to correct Colab notebook
  • Loading branch information
KieranRatcliffeInvertedAI committed Nov 27, 2023
2 parents 15bcf47 + 6a37db5 commit 2279b41
Show file tree
Hide file tree
Showing 25 changed files with 1,660 additions and 27 deletions.
17 changes: 17 additions & 0 deletions docs/source/cppapi/cpp-blame.md
@@ -0,0 +1,17 @@
# BLAME (C++)


```{eval-rst}
.. doxygenfunction:: invertedai::blame
:project: InvertedAI-CPP
```

---
```{eval-rst}
.. doxygenclass:: invertedai::BlameRequest
:members:
:undoc-members:
.. doxygenclass:: invertedai::BlameResponse
:members:
:undoc-members:
```
1 change: 1 addition & 0 deletions docs/source/cppapi/index.md
Expand Up @@ -7,6 +7,7 @@ accessed directly. Below are the key functions of the library, along with some c
```{toctree}
:maxdepth: 1
cpp-blame
cpp-drive
cpp-initialize
cpp-location-info
Expand Down
6 changes: 3 additions & 3 deletions docs/source/pythonapi/index.md
Expand Up @@ -7,13 +7,13 @@ accessed directly. Below are the key functions of the library, along with some c
```{toctree}
:maxdepth: 1
sdk-blame
sdk-drive
sdk-initialize
sdk-location-info
sdk-light
sdk-blame
sdk-simulation
sdk-location-info
sdk-common
sdk-simulation
sdk-env-var
```

Expand Down
11 changes: 7 additions & 4 deletions examples/carla/region_drive.py
@@ -1,6 +1,9 @@
import sys
sys.path.append('../')

import argparse
import invertedai as iai
from invertedai.simulation.simulator import Simulation, SimulationConfig
from simulation.simulator import Simulation, SimulationConfig
import pathlib
import pygame
from tqdm import tqdm
Expand All @@ -17,7 +20,7 @@
parser.add_argument("-cap", "--quadtree_capacity", type=int, default=15)
parser.add_argument("-ad", "--agent_density", type=int, default=10)
parser.add_argument("-ri", "--re_initialization", type=int, default=30)
parser.add_argument("-len", "--simulation_length", type=int, default=10000)
parser.add_argument("-len", "--simulation_length", type=int, default=600)
args = parser.parse_args()


Expand All @@ -29,12 +32,12 @@

cfg = SimulationConfig(location=args.location, map_center=(response.map_center.x, response.map_center.y),
map_fov=response.map_fov, rendered_static_map=rendered_static_map,
map_width=response.map_fov+200, map_height=response.map_fov+200, agent_density=args.agent_density,
map_width=response.map_fov, map_height=response.map_fov, agent_density=args.agent_density,
initialize_stride=50, quadtree_capacity=args.quadtree_capacity,
re_initialization_period=args.re_initialization)
simulation = Simulation(cfg=cfg)

fps = 100
fps = 60
clock = pygame.time.Clock()
run = True
start = perf_counter()
Expand Down
2 changes: 1 addition & 1 deletion examples/simulation/regions.py
Expand Up @@ -2,7 +2,7 @@
from simulation.utils import Rectangle, RE_INITIALIZATION_PERIOD, DEBUG
from typing import List, Optional, Callable
from random import randint
from invertedai import drive, async_drive
from invertedai.api.drive import drive, async_drive
from simulation.car import Car


Expand Down
14 changes: 11 additions & 3 deletions invertedai/api/drive.py
Expand Up @@ -41,7 +41,7 @@ class DriveResponse(BaseModel):
is_inside_supported_area: List[
bool
] #: For each agent, indicates whether the predicted state is inside supported area.

model_version: str # Model version used for this API call

@validate_arguments
def drive(
Expand All @@ -55,6 +55,7 @@ def drive(
rendering_fov: Optional[float] = None,
get_infractions: bool = False,
random_seed: Optional[int] = None,
model_version: Optional[str] = None
) -> DriveResponse:
"""
Parameters
Expand Down Expand Up @@ -99,6 +100,8 @@ def drive(
random_seed:
Controls the stochastic aspects of agent behavior for reproducibility.
model_version:
Optionally specify the version of the model. If None is passed which is by default, the best model will be used.
See Also
--------
:func:`initialize`
Expand Down Expand Up @@ -144,7 +147,8 @@ def _tolist(input_data: List):
get_infractions=get_infractions,
random_seed=random_seed,
rendering_center=rendering_center,
rendering_fov=rendering_fov
rendering_fov=rendering_fov,
model_version=model_version
)
start = time.time()
timeout = TIMEOUT
Expand All @@ -170,6 +174,7 @@ def _tolist(input_data: List):
if response["infraction_indicators"]
else [],
is_inside_supported_area=response["is_inside_supported_area"],
model_version=response["model_version"]
)

return response
Expand All @@ -193,6 +198,7 @@ async def async_drive(
rendering_fov: Optional[float] = None,
get_infractions: bool = False,
random_seed: Optional[int] = None,
model_version: Optional[str] = None
) -> DriveResponse:
"""
A light async version of :func:`drive`
Expand All @@ -216,7 +222,8 @@ def _tolist(input_data: List):
get_infractions=get_infractions,
random_seed=random_seed,
rendering_center=rendering_center,
rendering_fov=rendering_fov
rendering_fov=rendering_fov,
model_version=model_version,
)
response = await iai.session.async_request(model="drive", data=model_inputs)

Expand All @@ -237,6 +244,7 @@ def _tolist(input_data: List):
if response["infraction_indicators"]
else [],
is_inside_supported_area=response["is_inside_supported_area"],
model_version=response["model_version"]
)

return response
10 changes: 10 additions & 0 deletions invertedai/api/initialize.py
Expand Up @@ -41,6 +41,7 @@ class InitializeResponse(BaseModel):
infractions: Optional[
List[InfractionIndicators]
] #: If `get_infractions` was set, they are returned here.
model_version: str # Model version used for this API call


@validate_arguments
Expand All @@ -56,6 +57,7 @@ def initialize(
get_infractions: bool = False,
agent_count: Optional[int] = None,
random_seed: Optional[int] = None,
model_version: Optional[str] = None # Model version used for this API call
) -> InitializeResponse:
"""
Initializes a simulation in a given location.
Expand Down Expand Up @@ -104,6 +106,9 @@ def initialize(
random_seed:
Controls the stochastic aspects of initialization for reproducibility.
model_version:
Optionally specify the version of the model. If None is passed which is by default, the best model will be used.
See Also
--------
:func:`drive`
Expand Down Expand Up @@ -152,6 +157,7 @@ def initialize(
location_of_interest=location_of_interest,
get_infractions=get_infractions,
random_seed=random_seed,
model_version=model_version
)
start = time.time()
timeout = TIMEOUT
Expand Down Expand Up @@ -182,6 +188,7 @@ def initialize(
]
if response["infraction_indicators"]
else [],
model_version=response["model_version"]
)
return response
except TryAgain as e:
Expand All @@ -203,6 +210,7 @@ async def async_initialize(
get_infractions: bool = False,
agent_count: Optional[int] = None,
random_seed: Optional[int] = None,
model_version: Optional[str] = None
) -> InitializeResponse:
"""
The async version of :func:`initialize`
Expand All @@ -228,6 +236,7 @@ async def async_initialize(
location_of_interest=location_of_interest,
get_infractions=get_infractions,
random_seed=random_seed,
model_version=model_version
)

response = await iai.session.async_request(model="initialize", data=model_inputs)
Expand Down Expand Up @@ -255,5 +264,6 @@ async def async_initialize(
]
if response["infraction_indicators"]
else [],
model_version=response["model_version"]
)
return response
2 changes: 1 addition & 1 deletion invertedai_cpp/Dockerfile
@@ -1,4 +1,4 @@
FROM ubuntu:22.10
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
&& apt-get install -y build-essential \
Expand Down
15 changes: 15 additions & 0 deletions invertedai_cpp/examples/BUILD
Expand Up @@ -30,3 +30,18 @@ cc_binary(
"@opencv",
],
)

cc_binary(
name = "fps_control_demo",
srcs = ["fps_control_demo.cc"],
data = [
"drive_body.json",
"initialize_body.json",
"location_info_body.json",
],
deps = [
"//invertedai:api",
"@boost//:beast",
"@opencv",
],
)
26 changes: 26 additions & 0 deletions invertedai_cpp/examples/conditional_initialize_body.json
@@ -0,0 +1,26 @@
{
"location": "iai:ubc_roundabout",
"num_agents_to_spawn": 10,
"states_history": null,
"agent_attributes": null,
"traffic_light_state_history": null,
"get_birdview": true,
"get_infractions": false,
"random_seed": null,
"location_of_interest": null,
"conditional_agent_states": [
[
-4.79,
-18.32,
-1.35,
6.62
]
],
"conditional_agent_attributes": [
[
4.4,
1.94,
1.41
]
]
}
2 changes: 1 addition & 1 deletion invertedai_cpp/examples/drive_body.json
@@ -1,5 +1,5 @@
{
"location": "canada:vancouver:ubc_roundabout",
"location": "iai:ubc_roundabout",
"agent_states": [
[
33.8,
Expand Down

0 comments on commit 2279b41

Please sign in to comment.