Skip to content

Commit

Permalink
remove torch and numpy dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirezaMorsali committed Oct 4, 2022
1 parent 3bbbd5d commit 977d6ad
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 36 deletions.
7 changes: 3 additions & 4 deletions examples/Carla_Examples/Carla-Demo-Script-Birdview.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from PIL import Image as PImage
import cv2
import imageio
import torch
from dotenv import load_dotenv

load_dotenv()
Expand Down Expand Up @@ -50,9 +49,9 @@

for i in range(carla_cfg.episode_length * carla_cfg.fps):
response = iai.drive(
agent_attributes=torch.tensor(dimensions).unsqueeze(0).tolist(),
states=torch.tensor(states).unsqueeze(0).tolist(),
recurrent_states=torch.tensor(recurrent_states).unsqueeze(0).tolist(),
agent_attributes=[dimensions],
states=[states],
recurrent_states=[recurrent_states],
get_birdviews=True,
location=args.scene_name,
steps=1,
Expand Down
9 changes: 3 additions & 6 deletions examples/Carla_Examples/Carla-Demo-Script.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import json
import pygame
import os
import sys
import numpy as np
import torch
from dotenv import load_dotenv

load_dotenv()
Expand Down Expand Up @@ -60,9 +57,9 @@

for i in range(carla_cfg.episode_length * carla_cfg.fps):
response = iai.drive(
agent_attributes=torch.tensor(dimensions).unsqueeze(0).tolist(),
states=torch.tensor(states).unsqueeze(0).tolist(),
recurrent_states=torch.tensor(recurrent_states).unsqueeze(0).tolist(),
agent_attributes=[dimensions],
states=[states],
recurrent_states=[recurrent_states],
location=args.scene_name,
steps=1,
traffic_states_id=response["traffic_states_id"],
Expand Down
18 changes: 9 additions & 9 deletions examples/Carla_Examples/Carla-Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 6,
"id": "911445d4-8b61-49a1-9620-d1f3eb0c4199",
"metadata": {},
"outputs": [],
Expand All @@ -36,14 +36,14 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 7,
"id": "069cf9cb-30eb-4378-b4f9-9cb7d9038620",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "dc706e042b09483395f47909abf289cb",
"model_id": "b967787e62ed43a7a536d3c075250bce",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -57,7 +57,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5dcc117e197c47f3821da0049c88ad9b",
"model_id": "3064400f5dd54fdc8754b9745f459be5",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -95,7 +95,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 8,
"id": "94506da0-9a15-4dc0-9d57-5ac30bc36d72",
"metadata": {},
"outputs": [],
Expand All @@ -114,9 +114,9 @@
"\n",
"for i in range(carla_cfg.episode_length * carla_cfg.fps):\n",
" response = iai.drive(\n",
" agent_attributes=torch.tensor(dimensions).unsqueeze(0).tolist(),\n",
" states=torch.tensor(states).unsqueeze(0).tolist(),\n",
" recurrent_states=torch.tensor(recurrent_states).unsqueeze(0).tolist(),\n",
" agent_attributes=[dimensions],\n",
" states=[states],\n",
" recurrent_states=[recurrent_states],\n",
" get_birdviews=True,\n",
" location=scene_name,\n",
" steps=1,\n",
Expand All @@ -132,7 +132,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 9,
"id": "adaf461b-b846-40bc-835d-171466aaf508",
"metadata": {},
"outputs": [],
Expand Down
8 changes: 3 additions & 5 deletions examples/Carla_Examples/Carla-Scenario.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import json
import pygame
import os
import sys
import numpy as np
import torch
from dotenv import load_dotenv

load_dotenv()
Expand Down Expand Up @@ -60,9 +58,9 @@
states, recurrent_states, dimensions = sim.reset()
for i in range(carla_cfg.episode_length * carla_cfg.fps):
response = iai.drive(
agent_attributes=torch.tensor(dimensions).unsqueeze(0).tolist(),
states=torch.tensor(states).unsqueeze(0).tolist(),
recurrent_states=torch.tensor(recurrent_states).unsqueeze(0).tolist(),
agent_attributes=[dimensions],
states=[states],
recurrent_states=[recurrent_states],
location=args.scene_name,
steps=1,
traffic_states_id=response["traffic_states_id"],
Expand Down
Binary file modified examples/Carla_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.
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.
15 changes: 6 additions & 9 deletions invertedai/api_resources.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from invertedai.error import TryAgain
from dataclasses import dataclass
import numpy as np
from typing import List, Union, Optional
import math
from typing import List, Optional
import time
import invertedai as iai


TIMEOUT = 10

InputDataType = Union[np.ndarray, np.ndarray, List]


def initialize(
location="CARLA:Town03:Roundabout",
Expand All @@ -27,8 +24,8 @@ def initialize(
"location": location,
"num_agents_to_spawn": agent_count,
"num_samples": batch_size,
"spawn_min_speed": min_speed and np.ceil(min_speed / 3.6).astype(int),
"spawn_max_speed": max_speed and np.ceil(max_speed / 3.6).astype(int),
"spawn_min_speed": min_speed and int(math.ceil(min_speed / 3.6)),
"spawn_max_speed": max_speed and int(math.ceil(max_speed / 3.6)),
}
initial_states = iai.session.request(model="initialize", params=params)
response = {
Expand All @@ -48,15 +45,15 @@ def initialize(
def drive(
states: dict,
agent_attributes: dict,
recurrent_states: Optional[InputDataType] = None,
recurrent_states: Optional[List] = None,
get_birdviews: bool = False,
location="CARLA:Town03:Roundabout",
steps: int = 1,
get_infractions: bool = False,
traffic_states_id: str = "000:0",
exclude_ego_agent: bool = True,
) -> dict:
def _tolist(input_data: InputDataType):
def _tolist(input_data: List):
if not isinstance(input_data, list):
return input_data.tolist()
else:
Expand Down
1 change: 0 additions & 1 deletion invertedai/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from dataclasses import dataclass
from typing import List
from torch import Tensor


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion invertedai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import re
from typing import Dict, Optional
import numpy as np
from requests.auth import AuthBase
import invertedai as iai
from invertedai import error
Expand Down Expand Up @@ -183,6 +182,7 @@ def __call__(self, r):
def Jupyter_Render():
import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np

class Jupyter_Render(widgets.HBox):
def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.7,<3.11"
python-dotenv = "^0.21.0"
numpy = "^1.17.0"

[tool.poetry.group.dev.dependencies]
numpy = "^1.17.0"
matplotlib = "^3.5"
ipython = "^7.34"
ipywidgets = "^8.0.2"
Expand Down

0 comments on commit 977d6ad

Please sign in to comment.