Closed philipp-seidel1 closed 2 years ago
The memory leak has been fixed in merged PRs
@philipp-seidel1 , however, with the latest gym(v0.22.0)
, there is still a black window even user doesn't call render()
.
I found some workaround:https://stackoverflow.com/questions/10466590/hiding-pygame-display. But if doing this way, then all Box2D envrionment can not render correctly.
Hi all,
I had problems running car_racing.py on an old laptop with Windows 7. RAM would accumulate to the point that the rendering of the track and grass would disappear. I figured a way of improving the implementation so it is more efficient. It avoids regenerating the pyglet vertex list of track and grass at every step, by making the vertex list an attribute of the CarRacing class. In fact, now it is just generated once, but still drawn at every step. The visual update of a track tile having been passed occurs by a method that just updates the color of the given tile in the vertex list. Works equivalent to the old code, but much faster and without bumps on my old laptop.
`""" Easiest continuous control task to learn from pixels, a top-down racing environment. Discrete control is reasonable in this environment as well, on/off discretization is fine.
State consists of STATE_W x STATE_H pixels.
The reward is -0.1 every frame and +1000/N for every track tile visited, where N is the total number of tiles visited in the track. For example, if you have finished in 732 frames, your reward is 1000 - 0.1*732 = 926.8 points.
The game is solved when the agent consistently gets 900+ points. The generated track is random every episode.
The episode finishes when all the tiles are visited. The car also can go outside of the PLAYFIELD - that is far off the track, then it will get -100 and die.
Some indicators are shown at the bottom of the window along with the state RGB buffer. From left to right: the true speed, four ABS sensors, the steering wheel position and gyroscope.
To play yourself (it's rather fast for humans), type:
python gym/envs/box2d/car_racing.py
Remember it's a powerful rear-wheel drive car - don't press the accelerator and turn at the same time.
Created by Oleg Klimov. Licensed on the same terms as the rest of OpenAI Gym. """ import sys import math import numpy as np
import Box2D from Box2D.b2 import fixtureDef from Box2D.b2 import polygonShape from Box2D.b2 import contactListener
import gym from gym import spaces from gym.envs.box2d.car_dynamics import Car from gym.utils import seeding, EzPickle
import pyglet
pyglet.options["debug_gl"] = False from pyglet import gl
STATE_W = 96 # less than Atari 160x192 STATE_H = 96 VIDEO_W = 600 VIDEO_H = 400 WINDOW_W = 1000 WINDOW_H = 800
SCALE = 6.0 # Track scale TRACK_RAD = 900 / SCALE # Track is heavily morphed circle with this radius PLAYFIELD = 2000 / SCALE # Game over boundary FPS = 50 # Frames per second ZOOM = 2.7 # Camera zoom ZOOM_FOLLOW = True # Set to False for fixed view (don't use zoom)
TRACK_DETAIL_STEP = 21 / SCALE TRACK_TURN_RATE = 0.31 TRACK_WIDTH = 40 / SCALE BORDER = 8 / SCALE BORDER_MIN_COUNT = 4
ROAD_COLOR = [0.4, 0.4, 0.4]
class FrictionDetector(contactListener): def init(self, env): contactListener.init(self) self.env = env
class CarRacing(gym.Env, EzPickle): metadata = { "render.modes": ["human", "rgb_array", "state_pixels"], "video.frames_per_second": FPS, }
if name == "main": from pyglet.window import key
`