本文整理汇总了Python中gym.error.InvalidFrame方法的典型用法代码示例。如果您正苦于以下问题:Python error.InvalidFrame方法的具体用法?Python error.InvalidFrame怎么用?Python error.InvalidFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gym.error
的用法示例。
在下文中一共展示了error.InvalidFrame方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: capture_frame
# 需要导入模块: from gym import error [as 别名]
# 或者: from gym.error import InvalidFrame [as 别名]
def capture_frame(self, frame):
string = None
if isinstance(frame, str):
string = frame
elif isinstance(frame, StringIO):
string = frame.getvalue()
else:
raise error.InvalidFrame('Wrong type {} for {}: text frame must be a string or StringIO'.format(type(frame), frame))
frame_bytes = string.encode('utf-8')
if frame_bytes[-1:] != six.b('\n'):
raise error.InvalidFrame('Frame must end with a newline: """{}"""'.format(string))
if six.b('\r') in frame_bytes:
raise error.InvalidFrame('Frame contains carriage returns (only newlines are allowed: """{}"""'.format(string))
self.frames.append(frame_bytes)
示例2: __init__
# 需要导入模块: from gym import error [as 别名]
# 或者: from gym.error import InvalidFrame [as 别名]
def __init__(self, output_path, frame_shape, frames_per_sec):
self.proc = None
self.output_path = output_path
# Frame shape should be lines-first, so w and h are swapped
h, w, pixfmt = frame_shape
if pixfmt != 3 and pixfmt != 4:
raise error.InvalidFrame("Your frame has shape {}, but we require (w,h,3) or (w,h,4), i.e. RGB values for a w-by-h image, with an optional alpha channl.".format(frame_shape))
self.wh = (w,h)
self.includes_alpha = (pixfmt == 4)
self.frame_shape = frame_shape
self.frames_per_sec = frames_per_sec
if distutils.spawn.find_executable('avconv') is not None:
self.backend = 'avconv'
elif distutils.spawn.find_executable('ffmpeg') is not None:
self.backend = 'ffmpeg'
else:
raise error.DependencyNotInstalled("""Found neither the ffmpeg nor avconv executables. On OS X, you can install ffmpeg via `brew install ffmpeg`. On most Ubuntu variants, `sudo apt-get install ffmpeg` should do it. On Ubuntu 14.04, however, you'll need to install avconv with `sudo apt-get install libav-tools`.""")
self.start()
示例3: __init__
# 需要导入模块: from gym import error [as 别名]
# 或者: from gym.error import InvalidFrame [as 别名]
def __init__(self, final_path, frame_shape, frames_per_sec):
self.proc = None
self.final_path = final_path
_, self.output_path = tempfile.mkstemp(suffix='.mp4')
# Frame shape should be lines-first, so w and h are swapped
h, w, pixfmt = frame_shape
if pixfmt != 3 and pixfmt != 4:
raise error.InvalidFrame("Your frame has shape {}, but we require (w,h,3) or (w,h,4), i.e. RGB values for a w-by-h image, with an optional alpha channl.".format(frame_shape))
self.wh = (w,h)
self.includes_alpha = (pixfmt == 4)
self.frame_shape = frame_shape
self.frames_per_sec = frames_per_sec
if distutils.spawn.find_executable('avconv') is not None:
self.backend = 'avconv'
elif distutils.spawn.find_executable('ffmpeg') is not None:
self.backend = 'ffmpeg'
else:
raise error.DependencyNotInstalled("""Found neither the ffmpeg nor avconv executables. On OS X, you can install ffmpeg via `brew install ffmpeg`. On most Ubuntu variants, `sudo apt-get install ffmpeg` should do it. On Ubuntu 14.04, however, you'll need to install avconv with `sudo apt-get install libav-tools`.""")
self.start()
示例4: capture_frame
# 需要导入模块: from gym import error [as 别名]
# 或者: from gym.error import InvalidFrame [as 别名]
def capture_frame(self, frame):
if not isinstance(frame, (np.ndarray, np.generic)):
raise error.InvalidFrame(
'Wrong type {} for {} (must be np.ndarray or np.generic)'.format(type(frame), frame))
if frame.shape != self.frame_shape:
raise error.InvalidFrame(
"Your frame has shape {}, but the VideoRecorder is configured for shape {}.".format(
frame.shape, self.frame_shape))
if frame.dtype != np.uint8:
raise error.InvalidFrame(
"Your frame has data type {}, but we require uint8 (i.e. RGB values from 0-255).".format(frame.dtype))
if distutils.version.LooseVersion(np.__version__) >= distutils.version.LooseVersion('1.9.0'):
self.proc.stdin.write(frame.tobytes())
else:
self.proc.stdin.write(frame.tostring())
示例5: capture_frame
# 需要导入模块: from gym import error [as 别名]
# 或者: from gym.error import InvalidFrame [as 别名]
def capture_frame(self, frame):
from six import string_types
string = None
if isinstance(frame, string_types):
string = frame
elif isinstance(frame, StringIO):
string = frame.getvalue()
else:
raise error.InvalidFrame('Wrong type {} for {}: text frame must be a string or StringIO'.format(type(frame), frame))
frame_bytes = string.encode('utf-8')
if frame_bytes[-1:] != six.b('\n'):
raise error.InvalidFrame('Frame must end with a newline: """{}"""'.format(string))
if six.b('\r') in frame_bytes:
raise error.InvalidFrame('Frame contains carriage returns (only newlines are allowed: """{}"""'.format(string))
self.frames.append(frame_bytes)
示例6: __init__
# 需要导入模块: from gym import error [as 别名]
# 或者: from gym.error import InvalidFrame [as 别名]
def __init__(self, output_path, frame_shape, frames_per_sec):
self.proc = None
self.output_path = output_path
# Frame shape should be lines-first, so w and h are swapped
h, w, pixfmt = frame_shape
if pixfmt != 3 and pixfmt != 4:
raise error.InvalidFrame("Your frame has shape {}, but we require (w,h,3) or (w,h,4), i.e., RGB values for a w-by-h image, with an optional alpha channel.".format(frame_shape))
self.wh = (w,h)
self.includes_alpha = (pixfmt == 4)
self.frame_shape = frame_shape
self.frames_per_sec = frames_per_sec
if distutils.spawn.find_executable('avconv') is not None:
self.backend = 'avconv'
elif distutils.spawn.find_executable('ffmpeg') is not None:
self.backend = 'ffmpeg'
else:
raise error.DependencyNotInstalled("""Found neither the ffmpeg nor avconv executables. On OS X, you can install ffmpeg via `brew install ffmpeg`. On most Ubuntu variants, `sudo apt-get install ffmpeg` should do it. On Ubuntu 14.04, however, you'll need to install avconv with `sudo apt-get install libav-tools`.""")
self.start()
示例7: _encode_image_frame
# 需要导入模块: from gym import error [as 别名]
# 或者: from gym.error import InvalidFrame [as 别名]
def _encode_image_frame(self, frame):
if not self.encoder:
self.encoder = ImageEncoder(self.path, frame.shape, self.frames_per_sec)
self.metadata['encoder_version'] = self.encoder.version_info
try:
self.encoder.capture_frame(frame)
except error.InvalidFrame as e:
logger.warn('Tried to pass invalid video frame, marking as broken: %s', e)
self.broken = True
else:
self.empty = False
示例8: _encode_image_frame
# 需要导入模块: from gym import error [as 别名]
# 或者: from gym.error import InvalidFrame [as 别名]
def _encode_image_frame(self, frame):
if not self.encoder:
self.encoder = ImageEncoderWithGif(self.path,
frame.shape,
self.frames_per_sec,
self.format)
self.metadata['encoder_version'] = self.encoder.version_info
try:
self.encoder.capture_frame(frame)
except error.InvalidFrame as e:
self.broken = True
else:
self.empty = False
示例9: animate
# 需要导入模块: from gym import error [as 别名]
# 或者: from gym.error import InvalidFrame [as 别名]
def animate(self, act_fn, nsteps, **kwargs):
"""act_fn could be a list of functions for each agent in the environemnt that we can control"""
if not isinstance(act_fn, list):
act_fn = [act_fn for _ in range(len(self.agents))]
assert len(act_fn) == len(self.agents)
encoder = None
vid_loc = kwargs.pop('vid', None)
obs = self.reset()
frame = self.render(**kwargs)
if vid_loc:
fps = kwargs.pop('fps', 30)
encoder = ImageEncoder(vid_loc, frame.shape, fps)
try:
encoder.capture_frame(frame)
except error.InvalidFrame as e:
print('Invalid video frame, {}'.format(e))
rew = np.zeros((len(self.agents)))
traj_info_list = []
for step in range(nsteps):
a = list(map(lambda afn, o: afn(o), act_fn, obs))
obs, r, done, info = self.step(a)
rew += r
if info:
traj_info_list.append(info)
frame = self.render(**kwargs)
if vid_loc:
try:
encoder.capture_frame(frame)
except error.InvalidFrame as e:
print('Invalid video frame, {}'.format(e))
if done:
break
traj_info = stack_dict_list(traj_info_list)
return rew, traj_info