Python gym.error.InvalidFrame() Examples
The following are 20
code examples of gym.error.InvalidFrame().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gym.error
, or try the search function
.
Example #1
Source File: video_recorder.py From DQN-DDPG_Stock_Trading with MIT License | 8 votes |
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()
Example #2
Source File: video_recorder.py From DRL_DeliveryDuel with MIT License | 7 votes |
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()
Example #3
Source File: video_recorder.py From ia-course with MIT License | 7 votes |
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()
Example #4
Source File: utils.py From parasol with MIT License | 7 votes |
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()
Example #5
Source File: video_recorder.py From DRL_DeliveryDuel with MIT License | 6 votes |
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)
Example #6
Source File: video_recorder.py From DQN-DDPG_Stock_Trading with MIT License | 6 votes |
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)
Example #7
Source File: video.py From rl-teacher with MIT License | 6 votes |
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())
Example #8
Source File: video_recorder.py From ia-course with MIT License | 6 votes |
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)
Example #9
Source File: utils.py From parasol with MIT License | 6 votes |
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)
Example #10
Source File: video_recorder.py From ia-course with MIT License | 5 votes |
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
Example #11
Source File: utils.py From parasol with MIT License | 5 votes |
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())
Example #12
Source File: video_recorder.py From ia-course with MIT License | 5 votes |
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())
Example #13
Source File: recorder_wrapper.py From cherry with Apache License 2.0 | 5 votes |
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
Example #14
Source File: utils.py From parasol with MIT License | 5 votes |
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
Example #15
Source File: multi_walker.py From multiagent-gail with MIT License | 5 votes |
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
Example #16
Source File: __init__.py From MADRL with MIT License | 5 votes |
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
Example #17
Source File: video_recorder.py From DQN-DDPG_Stock_Trading with MIT License | 5 votes |
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
Example #18
Source File: video_recorder.py From DRL_DeliveryDuel with MIT License | 5 votes |
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())
Example #19
Source File: video_recorder.py From DRL_DeliveryDuel with MIT License | 5 votes |
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
Example #20
Source File: video_recorder.py From DQN-DDPG_Stock_Trading with MIT License | 5 votes |
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())