-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:decisionforce/pgdrive into release-…
…0.1.2
- Loading branch information
Showing
10 changed files
with
136 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import json | ||
|
||
from pgdrive.envs.pgdrive_env import PGDriveEnv | ||
from pgdrive.scene_creator.map import Map, MapGenerateMethod | ||
from pgdrive.scene_manager import TrafficMode | ||
from pgdrive.utils import setup_logger | ||
|
||
|
||
class TestEnv(PGDriveEnv): | ||
def __init__(self, save_episode=True, vis=True): | ||
super(TestEnv, self).__init__( | ||
{ | ||
"environment_num": 1, | ||
"traffic_density": 0.1, | ||
"start_seed": 5, | ||
"manual_control": vis, | ||
"use_render": vis, | ||
"traffic_mode": TrafficMode.Reborn, | ||
"record_episode": save_episode, | ||
"map_config": { | ||
Map.GENERATE_METHOD: MapGenerateMethod.BIG_BLOCK_SEQUENCE, | ||
Map.GENERATE_PARA: "XTXTXTXTXT", | ||
Map.LANE_WIDTH: 3.5, | ||
Map.LANE_NUM: 3, | ||
} | ||
} | ||
) | ||
|
||
|
||
def test_save_episode(vis=False): | ||
setup_logger(True) | ||
|
||
test_dump = False | ||
|
||
env = TestEnv(vis=vis) | ||
try: | ||
o = env.reset() | ||
epi_info = None | ||
for i in range(1, 100000 if vis else 2000): | ||
o, r, d, info = env.step([0, 1]) | ||
if vis: | ||
env.render() | ||
if d: | ||
epi_info = env.scene_manager.dump_episode() | ||
|
||
# test dump json | ||
if test_dump: | ||
with open("test.json", "w") as f: | ||
json.dump(epi_info, f) | ||
break | ||
finally: | ||
env.close() | ||
|
||
del env | ||
env = TestEnv(False, vis=vis) | ||
try: | ||
o = env.reset(epi_info) | ||
for i in range(1, 100000 if vis else 2000): | ||
o, r, d, info = env.step([0, 1]) | ||
if vis: | ||
env.render() | ||
if d: | ||
break | ||
finally: | ||
env.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_save_episode(vis=True) |
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
pgdrive/tests/test_top_down_rendering/test_top_down_rendering.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pgdrive.envs.pgdrive_env import PGDriveEnv | ||
import pygame | ||
|
||
|
||
def test_top_down_rendering(): | ||
env = PGDriveEnv(dict(environment_num=20, start_seed=0, map=10, use_topdown=True, use_render=False)) | ||
try: | ||
env.reset() | ||
for i in range(5): | ||
env.step(env.action_space.sample()) | ||
env.render(mode="human") | ||
env.render(mode="rgb_array") | ||
finally: | ||
pygame.image.save(env.pg_world.highway_render.frame_surface, "save_offscreen.jpg") | ||
env.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_top_down_rendering() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.