本文整理匯總了Python中gym.wrappers.monitoring.video_recorder.VideoRecorder方法的典型用法代碼示例。如果您正苦於以下問題:Python video_recorder.VideoRecorder方法的具體用法?Python video_recorder.VideoRecorder怎麽用?Python video_recorder.VideoRecorder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gym.wrappers.monitoring.video_recorder
的用法示例。
在下文中一共展示了video_recorder.VideoRecorder方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ResetPoseExample
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def ResetPoseExample(steps):
"""An example that the minitaur stands still using the reset pose."""
environment = pybullet_sim_gym_env.PyBulletSimGymEnv(
pybullet_sim_factory=boxstack_pybullet_sim,
debug_visualization=False,
render=True, action_repeat=30)
action = [math.pi / 2] * 8
vid = video_recorder.VideoRecorder(env=environment,path="vid.mp4")
for _ in range(steps):
print(_)
startsim = time.time()
_, _, done, _ = environment.step(action)
stopsim = time.time()
startrender = time.time()
#environment.render(mode='rgb_array')
vid.capture_frame()
stoprender = time.time()
print ("env.step " , (stopsim - startsim))
print ("env.render " , (stoprender - startrender))
if done:
environment.reset()
示例2: _reset_video_recorder
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def _reset_video_recorder(self):
"""Called at the start of each episode (by _reset). Always creates a video recorder
if one does not already exist. When a video recorder is already present, it will only
create a new one if `self.single_video == False`."""
if self.video_recorder is not None:
# Video recorder already started.
if not self.single_video:
# We want a new video for each episode, so destroy current recorder.
self.video_recorder.close()
self.video_recorder = None
if self.video_recorder is None:
# No video recorder -- start a new one.
self.video_recorder = VideoRecorder(
env=self.env,
base_path=osp.join(self.directory, "video.{:06}".format(self.episode_id)),
metadata={"episode_id": self.episode_id},
)
示例3: reset_video_recorder
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def reset_video_recorder(self):
# Close any existing video recorder
if self.video_recorder:
self._close_video_recorder()
# Start recording the next video.
#
# TODO: calculate a more correct 'episode_id' upon merge
rec_name = 'cherry.recording.ep{:06}'.format(self.episode_id)
base_path = os.path.join(self.directory, rec_name)
self.video_recorder = VideoRecorder(
env=self.env,
base_path=base_path,
metadata={'episode_id': self.episode_id},
enabled=True,
format=self.format,
)
self.output_files.append(os.path.relpath(self.video_recorder.path))
self.video_recorder.capture_frame()
示例4: reset_video_recorder
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def reset_video_recorder(self):
# Close any existing video recorder
if self.video_recorder:
self._close_video_recorder()
# Start recording the next video.
#
# TODO: calculate a more correct 'episode_id' upon merge
self.video_recorder = VideoRecorder(
env=self.env,
base_path=self.episode_base_path,
metadata={'episode_id': self.episode_id},
enabled=self._video_enabled(),
)
self._create_video_logger()
self.video_recorder.capture_frame()
示例5: reset_video_recorder
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def reset_video_recorder(self):
# Close any existing video recorder
if self.video_recorder:
self._close_video_recorder()
# Start recording the next video.
self.video_recorder = video_recorder.VideoRecorder(
env=self.env,
base_path=os.path.join(self.directory,
'{}.video.{}.video{:06}'.format(self.file_prefix, self.file_infix, self.episode_id)),
metadata={'episode_id': self.episode_id},
enabled=self._video_enabled(),
)
# Instead of capturing just one frame, allow the environment to send all render frames when a step is ongoing
if self._video_enabled() and hasattr(self.env.unwrapped, 'automatic_rendering_callback'):
self.env.unwrapped.automatic_rendering_callback = self.video_recorder.capture_frame
示例6: _reset_video_recorder
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def _reset_video_recorder(self):
"""Close the current video recorder and open a new one. Automatically stops the
current video and starts a new one
"""
# Close any existing video recorder
if self.video_recorder:
self._close_video_recorder()
ep_id = self.episode_id
mode = self.stats_recorder.mode
video_file = "{}_video_episode_{:06}".format("train" if mode == 't' else "eval", ep_id)
video_file = os.path.join(self.video_dir, video_file)
# Start recording the next video
self.video_recorder = VideoRecorder(
env=self.env,
base_path=video_file,
metadata={'episode_id': ep_id},
enabled=self.enable_video(ep_id),
)
self.video_recorder.capture_frame()
示例7: start_video_recorder
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def start_video_recorder(self):
self.close_video_recorder()
video_name = '{}-step-{}-to-step-{}'.format(self.name_prefix, self.step_id,
self.step_id + self.video_length)
base_path = os.path.join(self.video_folder, video_name)
self.video_recorder = video_recorder.VideoRecorder(
env=self.env,
base_path=base_path,
metadata={'step_id': self.step_id}
)
self.video_recorder.capture_frame()
self.recorded_frames = 1
self.recording = True
示例8: reset_video_recorder
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def reset_video_recorder(self):
# Close any existing video recorder
if self.video_recorder:
self._close_video_recorder()
# Start recording the next video.
#
# TODO: calculate a more correct 'episode_id' upon merge
self.video_recorder = video_recorder.VideoRecorder(
env=self.env,
base_path=os.path.join(self.directory, '{}.video.{}.video{:06}'.format(self.file_prefix, self.file_infix, self.episode_id)),
metadata={'episode_id': self.episode_id},
enabled=self._video_enabled(),
)
self.video_recorder.capture_frame()
示例9: test_record_simple
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def test_record_simple():
env = gym.make("CartPole-v1")
rec = VideoRecorder(env)
env.reset()
rec.capture_frame()
rec.close()
assert not rec.empty
assert not rec.broken
assert os.path.exists(rec.path)
f = open(rec.path)
assert os.fstat(f.fileno()).st_size > 100
示例10: test_no_frames
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def test_no_frames():
env = BrokenRecordableEnv()
rec = VideoRecorder(env)
rec.close()
assert rec.empty
assert rec.functional
assert not os.path.exists(rec.path)
示例11: test_record_unrecordable_method
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def test_record_unrecordable_method():
env = UnrecordableEnv()
rec = VideoRecorder(env)
assert not rec.enabled
rec.close()
示例12: test_record_breaking_render_method
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def test_record_breaking_render_method():
env = BrokenRecordableEnv()
rec = VideoRecorder(env)
rec.capture_frame()
rec.close()
assert rec.empty
assert rec.broken
assert not os.path.exists(rec.path)
示例13: start_video_recorder
# 需要導入模塊: from gym.wrappers.monitoring import video_recorder [as 別名]
# 或者: from gym.wrappers.monitoring.video_recorder import VideoRecorder [as 別名]
def start_video_recorder(self):
self.close_video_recorder()
base_path = os.path.join(self.directory, '{}.video.{}.video{:06}'.format(self.file_prefix, self.file_infix, self.step_id))
self.video_recorder = video_recorder.VideoRecorder(
env=self.venv,
base_path=base_path,
metadata={'step_id': self.step_id}
)
self.video_recorder.capture_frame()
self.recorded_frames = 1
self.recording = True