Skip to content

Commit

Permalink
fix requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycaisy committed May 21, 2024
1 parent 431c599 commit 5cf3673
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 78 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export PYTHONPATH="${CARLA_ROOT}/PythonAPI/carla":${PYTHONPATH}
Install the package using flit. The ``--symlink`` flag is used to create a symlink to the package in the Python environment, so that changes to the package are immediately available without reinstallation. (``--pth-file`` also works, as an alternative to ``--symlink``.)

```bash
conda create python=3.10 --name cardreamer
conda activate cardreamer
pip install flit
flit install --symlink
```
Expand Down
4 changes: 3 additions & 1 deletion docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Then, install the package using flit. The ``--symlink`` flag is used to create a

.. code-block:: console
conda create python=3.10 --name cardreamer
conda activate cardreamer
pip install flit
flit install --symlink
Expand Down Expand Up @@ -58,7 +60,7 @@ After creating the task, the visualization is automatically started if ``env.dis
import car_dreamer
import time
task, _ = car_dreamer.create_task('carla_four_lane', argv)
task, _ = car_dreamer.create_task('carla_four_lane')
task.reset()
while True:
_, _, is_terminal, _ = task.step(12) # 12 is the action of going straight and accelerating
Expand Down
6 changes: 3 additions & 3 deletions dreamerv3/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def main(argv=None):
config = embodied.Config({'dreamerv3': model_configs['defaults']})
config = config.update({'dreamerv3': model_configs['small']})

parsed, other = embodied.Flags(scenario=['carla_navigation']).parse_known(argv)
for name in parsed.scenario:
print("Using scenario: ", name)
parsed, other = embodied.Flags(task=['carla_navigation']).parse_known(argv)
for name in parsed.task:
print("Using task: ", name)
env, env_config = car_dreamer.create_task(name, argv)
config = config.update(env_config)
config = embodied.Flags(config).parse(other)
Expand Down
74 changes: 2 additions & 72 deletions dreamerv3/eval_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,7 @@
import argparse
from pathlib import Path


def compute_metrics_distance_based(episode_stats, task_success_distance_thresholds, task):
metrics = {}

travel_distances = np.array(episode_stats['sum_travel_distance'])
destination_reached = np.array(episode_stats['sum_destination_reached'])
time_exceeded = np.array(episode_stats['sum_time_exceeded'])
is_collision = np.array(episode_stats['sum_is_collision'])
out_of_lane = np.array(episode_stats['sum_out_of_lane'])
ttc = np.array(episode_stats['mean_ttc'])
wpt_dis = np.array(episode_stats['mean_wpt_dis'])
speed_norm = np.array(episode_stats['mean_speed_norm'])
lengths = np.array(episode_stats['lengths'])
scores = np.array(episode_stats['scores'])

num_episodes = len(travel_distances)
task_threshold = task_success_distance_thresholds.get(task, 0)

success_mask = travel_distances >= task_threshold
success_rate = np.mean(success_mask)

# Filter out failures after the tasks are successful
# is_collision[success_mask] = False
# time_exceeded[success_mask] = False
#out_of_lane[success_mask] = False

metrics['task'] = task
metrics['num_episodes'] = num_episodes
metrics['success_rate'] = success_rate
metrics['avg_travel_distance'] = np.mean(travel_distances)
metrics['avg_destination_reached'] = np.mean(destination_reached)
metrics['avg_destination_reached_ratio'] = np.sum(destination_reached) / num_episodes
metrics['avg_time_exceeded'] = np.mean(time_exceeded)
metrics['avg_time_exceeded_ratio'] = np.sum(time_exceeded) / num_episodes
metrics['avg_is_collision'] = np.mean(is_collision)
metrics['avg_is_collision_ratio'] = np.sum(is_collision) / num_episodes
metrics['avg_out_of_lane'] = np.mean(out_of_lane)
metrics['avg_out_of_lane_ratio'] = np.sum(out_of_lane) / num_episodes
metrics['avg_ttc'] = np.mean(ttc)
metrics['avg_wpt_dis'] = np.mean(wpt_dis)
metrics['avg_speed_norm'] = np.mean(speed_norm)
metrics['avg_length'] = np.mean(lengths)
metrics['avg_score'] = np.mean(scores)

return metrics


def compute_metrics_destination_based(episode_stats, task):
def compute_metrics_destination_based(episode_stats):
metrics = {}

travel_distances = np.array(episode_stats['sum_travel_distance'])
Expand All @@ -74,7 +27,6 @@ def compute_metrics_destination_based(episode_stats, task):
time_exceeded[destination_reached > 0] = False
out_of_lane[destination_reached > 0] = False

metrics['task'] = task
metrics['num_episodes'] = num_episodes
metrics['success_rate'] = success_rate
metrics['avg_travel_distance'] = np.mean(travel_distances)
Expand All @@ -96,24 +48,8 @@ def compute_metrics_destination_based(episode_stats, task):


def main(args):
task_success_distance_thresholds = {
'carla_left_turn_simple': 43,
'carla_left_turn_medium': 43,
'carla_left_turn_hard': 43,
'carla_right_turn_simple': 32,
'carla_right_turn_medium': 32,
'carla_right_turn_hard': 32,
'carla_navigation': 50,
'carla_lane_merge': 92,
'carla_four_lane': 70,
'carla_roundabout': 60,
'carla_overtake': 20,
'carla_message': 115,
}

jsonl_file = Path(args.logdir) / 'metrics.jsonl'
task = args.task
method = args.method

episode_stats = {
'sum_travel_distance': [],
Expand Down Expand Up @@ -152,15 +88,9 @@ def main(args):
if 'episode/score' in data:
episode_stats['scores'].append(data['episode/score'])

if method == 'distance':
final_metrics = compute_metrics_distance_based(episode_stats, task_success_distance_thresholds, task)
elif method == 'destination':
final_metrics = compute_metrics_destination_based(episode_stats, task)
else:
raise ValueError("Method should be either 'distance' or 'destination'")
final_metrics = compute_metrics_destination_based(episode_stats)

table = [
["Task", final_metrics['task']],
["Number of Episodes", final_metrics['num_episodes']],
["Success Rate", f"{final_metrics['success_rate']:.2%}"],
["Avg. Travel Distance", f"{final_metrics['avg_travel_distance']:.2f}"],
Expand Down
4 changes: 2 additions & 2 deletions dreamerv3/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cloudpickle==3.0.0
crafter==1.8.3
gym==0.26.2
gym==0.12.5
dm_control==1.0.18
jax==0.4.26
jaxlib==0.4.26+cuda12.cudnn89
numpy==1.24.3
optax==0.2.2
rich==13.7.1
ruamel.yaml==0.18.5
ruamel.yaml==0.18.6
tensorflow[and-cuda]==2.13.0
tensorflow_probability==0.21.0
scikit-image==0.23.2
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ dependencies = [
"typing_extensions==4.5.0",
"networkx==3.1",
"Shapely==1.8.4",
"pyyaml==6.0.1",
]

0 comments on commit 5cf3673

Please sign in to comment.