Ejemplo n.º 1
0
def create_flash_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)

    reg = universe.runtime_spec('flashgames').server_registry
    height = reg[env_id]["height"]
    width = reg[env_id]["width"]
    env = CropScreen(env, height, width, 84, 18)
    env = FlashRescale(env)

    keys = ['left', 'right', 'up', 'down', 'x']
    if env_id == 'flashgames.NeonRace-v0':
        # Better key space for this game.
        keys = ['left', 'right', 'up', 'left up', 'right up', 'down', 'up x']
    logger.info('create_flash_env(%s): keys=%s', env_id, keys)

    env = DiscreteToFixedKeysVNCActions(env, keys)
    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)
    env.configure(fps=5.0, remotes=remotes, start_timeout=15 * 60, client_id=client_id,
                  vnc_driver='go', vnc_kwargs={
                    'encoding': 'tight', 'compress_level': 0,
                    'fine_quality_level': 50, 'subsample_level': 3})
    return env
Ejemplo n.º 2
0
def create_flash_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = BlockingReset(env)

    reg = universe.runtime_spec('flashgames').server_registry
    height = reg[env_id]["height"]
    width = reg[env_id]["width"]
    env = CropScreen(env, height, width, 84, 18)
    env = FlashRescale(env)

    keys = ['left', 'right', 'up', 'down', 'x']
    if env_id == 'flashgames.NeonRace-v0':
        # Better key space for this game.
        keys = ['left', 'right', 'up', 'left up', 'right up', 'down', 'up x']
    print('Create Flash Game [{}]: keys={}'.format(env_id, keys))

    env = DiscreteToFixedKeysVNCActions(env, keys)
    env = Unvectorize(env)
    env.configure(fps=5.0,
                  remotes=remotes,
                  start_timeout=15 * 60,
                  client_id=client_id,
                  vnc_driver='go',
                  vnc_kwargs={
                      'encoding': 'tight',
                      'compress_level': 0,
                      'fine_quality_level': 50,
                      'subsample_level': 3
                  })
    return env
Ejemplo n.º 3
0
def create_vncatari_env(env_id, client_id, remotes, **_):
    """Create an Atari (rescaled) environment by passing environment id.

    Parameters
    ----------
    env_id : str
        environment id to be registered in Gym
    client_id : str
        Client ID
    remotes : str
        BLANK
    kwargs : dict
        BLANK
    """
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)
    env = GymCoreAction(env)
    env = AtariRescale42x42(env)
    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)

    logger.info('Connecting to remotes: %s', remotes)
    fps = env.metadata['video.frames_per_second']
    env.configure(remotes=remotes,
                  start_timeout=15 * 60,
                  fps=fps,
                  client_id=client_id)
    return env
Ejemplo n.º 4
0
    def make_env(self):
        """spawn a new environment instance"""
        print(self.env_id)
        env = gym.make(self.env_id)
        env = Vision(env)  # observation is an image
        env = BlockingReset(
            env)  # when env.reset will freeze until env is ready

        #convert from env.step(('KeyEvent', 'ArrowUp', True)) to env.step(2)
        env = DiscreteToFixedKeysVNCActions(env, list(self.keys))
        env = Unvectorize(
            env)  #now it's actually a single env instead of a batch

        # crop, grayscale and rescale to 64x64
        env = PreprocessImage(env,
                              64,
                              64,
                              grayscale=True,
                              crop=lambda img: img[84:84 + 480, 18:18 + 640])

        env.configure(fps=5.0,
                      remotes=1,
                      start_timeout=15 * 60,
                      client_id=self.client_id,
                      vnc_driver='go',
                      vnc_kwargs={
                          'encoding': 'tight',
                          'compress_level': 0,
                          'fine_quality_level': 50,
                          'subsample_level': 3
                      })

        return env
Ejemplo n.º 5
0
def setup(env, args):
    # setting up dir to store monitor output
    monitor_dir = os.path.join(args.output_dir, "monitor")
    if not os.path.exists(monitor_dir):
        os.mkdir(monitor_dir)

    # setting up dir to store model weights
    args.snapshot_dir = os.path.join(args.output_dir, "weights")
    if not os.path.exists(args.snapshot_dir):
        os.mkdir(args.snapshot_dir)

    args.log_file = args.output_dir + "train.log"

    if args.task == "DuskDrive":
        env = Logger(env)
        env = Monitor(env, monitor_dir, force=True)
        env = Vision(env)
        env = CropObservations(env)
        env = SafeActionSpace(env)

    if args.model == "BaseDQN":
        args.q_func = dqn_base
    elif args.model == "DQNFullyConnected":        
        args.q_func = dqn_fullyconnected
    else:
        raise NotImplementedError("Add support for different Q network models")

    args.exploration_schedule = PiecewiseSchedule(
    [
        (0, 1.0),
        (1e6, 0.1),
        (args.dqn_iters / 2, 0.01),
        ], outside_value=0.01
    )
    return env
Ejemplo n.º 6
0
def create_vncatari_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)
    env = GymCoreAction(env)
    env = AtariRescale42x42(env)

    #env = NormalizedEnv(env)

    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    if "multi_obs_settings" in _.keys():
        _multi = [env] + list(_["multi_obs_settings"])
        env = [env, SplitScreen(*_multi)]

    #env = Unvectorize(env)
    logger.info('Connecting to remotes: %s', remotes)
    fps = env.metadata['video.frames_per_second']
    if not "no_config" in _.keys():
        env.configure(remotes=remotes,
                      start_timeout=15 * 60,
                      fps=fps,
                      client_id=client_id)
    return env
Ejemplo n.º 7
0
def create_vncatari_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)
    env = GymCoreAction(env)
    env = AtariRescale(env)
    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)

    logger.info('Connecting to remotes: %s', remotes)
    fps = env.metadata['video.frames_per_second']
    env.configure(remotes=remotes, start_timeout=15 * 60, fps=fps, client_id=client_id)
    return env
Ejemplo n.º 8
0
def create_slither_env(state_type):
    env = gym.make('internet.SlitherIO-v0')
    env = Vision(env)

    #Because logging is annoying
    #env = Logger(env)

    env = BlockingReset(env)

    env = CropScreen(env, 300, 500, 85, 20)
    #env = DiscreteToFixedKeysVNCActions(env, ['left', 'right', 'space', 'left space', 'right space'])
    env = EpisodeID(env)
    env = RenderWrapper(env, state_type)
    return env
def setup(env, args):
   if args.task == "DuskDrive":
       env = Logger(env)
       env = Monitor(env, monitor_dir, force=True)
       env = Vision(env)
       env = CropObservations(env)
       env = SafeActionSpace(env)

   if args.model == "BaseDQN":
       args.q_func = dqn_base
   elif args.model == "DQNFullyConnected":
       args.q_func = dqn_fullyconnected
   else:
   	   raise NotImplementedError("Add support for different Q network models")
   return env
Ejemplo n.º 10
0
def createEnv(env_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)  # extracts the vision modality and discards all others
    env = Logger(env)
    env = CropScreen(
        env, height=300, width=500, top=84, left=18
    )  # Crops out a [height]x[width] area from screen starting from (top,left)
    env = EpisodeID(env)
    env.configure(remotes=remotes)
    return env
Ejemplo n.º 11
0
def create_vncatari_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = BlockingReset(env)
    env = GymCoreAction(env)
    env = AtariRescale(env)
    env = Unvectorize(env)

    print('Connecting to remotes: {}'.format(remotes))
    env.configure(remotes=remotes,
                  start_timeout=15 * 60,
                  fps=env.metadata['video.frames_per_second'],
                  client_id=client_id)
    return env
Ejemplo n.º 12
0
def setup(args):
    np.random.seed(args.seed)
    env = gym.make(args.task)

    # Only needed for universe tasks, whole script can be applied to any task
    env = Vision(env)
    env = CropObservations(env)
    env = SafeActionSpace(env)
    env.configure(remotes=1)
    pygame.init()
    return env
Ejemplo n.º 13
0
def create_vncatari_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)
    env = GymCoreAction(env)
    env = AtariRescale42x42(env)
    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)

    logger.info('Connecting to remotes: %s', remotes)
    fps = env.metadata['video.frames_per_second']
    env.configure(remotes=remotes, start_timeout=15 * 60, fps=fps, client_id=client_id)
    return env
Ejemplo n.º 14
0
def create_snake_env(env_id):
    env = gym.make(env_id)
    env.configure(remotes=1, docker_image="quay.io/openai/universe.flashgames:0.20.14-heavy")  # automatically creates a local docker container
    env.action_space = SnakeActionSpace()
    env = Vision(env) # Remove vision from dicts.

    # env = Vectorize(env)
    # env = AtariRescale42x42(env)

    x1, y1 = (20,85)   # top left
    x2, y2 = (521,383) # bottom right

    env = CropScreen(env, y2-y1, x2-x1, y1, x1)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)

    # Override observation space size. Cropped/resized later after rotating.
    env.observation_space = Box(0, 255, shape=(42, 42, 3))

    return env
Ejemplo n.º 15
0
def create_flash_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)

    reg = universe.runtime_spec('flashgames').server_registry
    height = reg[env_id]["height"]
    width = reg[env_id]["width"]
    env = CropScreen(env, height, width, 84, 18)
    env = FlashRescale(env)

    #env = NormalizedEnv(env)

    keys = ['left', 'right', 'up', 'down', 'x']
    if env_id == 'flashgames.NeonRace-v0':
        # Better key space for this game.
        keys = ['left', 'right', 'up', 'left up', 'right up', 'down', 'up x']
    if env_id == 'flashgames.LuxUltimate-v0':
        keys = ['a', 's', 'd']
    if env_id == 'flashgames.RetroRunner-v0':
        keys = ['up', 'right']
    if env_id == 'flashgames.RunRamRun-v0-v0':
        keys = ['up', 'down']
    logger.info('create_flash_env(%s): keys=%s', env_id, keys)

    env = DiscreteToFixedKeysVNCActions(env, keys)
    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    if "multi_obs_settings" in _.keys():
        _multi = [env] + list(_["multi_obs_settings"])
        #env = SplitScreen(*_multi)
        env = SplitScreen(*_multi)

    #env = Unvectorize(env)
    if not "no_config" in _.keys():
        env.configure(fps=5.0,
                      remotes=remotes,
                      start_timeout=15 * 60,
                      client_id=client_id,
                      vnc_driver='go',
                      vnc_kwargs={
                          'encoding': 'tight',
                          'compress_level': 0,
                          'fine_quality_level': 50,
                          'subsample_level': 3
                      },
                      replace_on_crash=True)
    return env
Ejemplo n.º 16
0
    # setting up dir to store monitor output
    monitor_dir = os.path.join(args.output_dir, "monitor")
    if not os.path.exists(monitor_dir):
        os.mkdir(monitor_dir)

    # setting up dir to store model weights
    args.snapshot_dir = os.path.join(args.output_dir, "weights")
    if not os.path.exists(args.snapshot_dir):
        os.mkdir(args.snapshot_dir)

    args.log_file = args.output_dir + "train.log"

    if args.task == "DuskDrive":
        env = Logger(env)
        env = Monitor(env, monitor_dir, force=True)
        env = Vision(env)
        env = CropObservations(env)
        env = SafeActionSpace(env)

    if args.model == "BaseDQN":
        args.q_func = dqn_base
    elif args.model == "DQNFullyConnected":        
        args.q_func = dqn_fullyconnected
    else:
        raise NotImplementedError("Add support for different Q network models")

    args.exploration_schedule = PiecewiseSchedule(
    [
        (0, 1.0),
        (1e6, 0.1),
        (args.dqn_iters / 2, 0.01),
Ejemplo n.º 17
0
def create_miniwob_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)

    env = CropScreen(env, 160, 160, 125, 10)
    if (env_id == 'wob.mini.NumberCheckboxes-v0') or (
            env_id == 'wob.mini.ChaseCircle-v0') or (
                env_id == 'wob.mini.BisectAngle-v0') or (
                    env_id == 'wob.mini.FindMidpoint-v0') or (
                        env_id == 'wob.mini.CircleCenter-v0'):
        # These tasks won't need a sharp resolution to perform well; therefore 80x80 pixels should be enough
        obs_height = 80
        obs_width = 80
    else:
        obs_height = 100
        obs_width = 100
    env = WobRescale(env, obs_height, obs_width)

    logger.info('create_miniwob_env(%s): ', env_id)

    noAgent = False  # if True; no Agent will perform

    if env_id == 'wob.mini.NumberCheckboxes-v0':
        # there are exact 29 possible actions to click at: the 28 checkboxes and 1 for the submit button
        env = ac_space.SoftmaxClickTask(
            env,
            active_region=(10 + 14, 75 + 57, 24 + 55, 132 + 102 + 11 + 22),
            noclick_regions=[(24 + 11 + 2, 42, 132 + 102 + 9, 28)],
            discrete_mouse_step=17,
            noAgent=noAgent)
    elif (env_id == 'wob.mini.BisectAngle-v0') or (
            env_id == 'wob.mini.FindMidpoint-v0') or (
                env_id == 'wob.mini.CircleCenter-v0') or (
                    env_id == 'wob.mini.RightAngle-v0'):
        env = ac_space.SoftmaxClickTask(env,
                                        discrete_mouse_step=8,
                                        noAgent=noAgent)
    elif env_id == 'wob.mini.CopyPaste-v0':
        # makes use of a special SoftmaxCopyPasteTask class that offers the actions of ctrl+a, ctrl+c, ctrl+v and mouse clicks
        env = ac_space.SoftmaxCopyPasteTask(env,
                                            discrete_mouse_step=20,
                                            noAgent=noAgent)
    elif (env_id == 'wob.mini.SimpleAlgebra-v0') or (
            env_id == 'wob.mini.SimpleArithmetic-v0') or (
                env_id == 'wob.mini.VisualAddition-v0'):
        # these tasks make use of the SoftmaxMathTask class which defines special action_space handling
        env = ac_space.SoftmaxMathTask(env, noAgent=noAgent)
    elif (env_id == 'wob.mini.DragBox-v0'):
        # makes use of a special SoftmaxDragTask class that unclicks when clicked and vice versa, the active_region is adapted to the task
        env = ac_space.SoftmaxDragTask(env,
                                       active_region=(10, 75 + 50, 10 + 160,
                                                      75 + 50 + 105),
                                       discrete_mouse_step=16,
                                       noAgent=noAgent)
    elif (env_id == 'wob.mini.HighlightText-v0'):
        # makes use of a special SoftmaxDragTask class that unclicks when clicked and vice versa, the active_region is adapted to the task
        env = ac_space.SoftmaxDragTask(env,
                                       active_region=(10, 75 + 50, 10 + 155,
                                                      75 + 50 + 50),
                                       discrete_mouse_step=16,
                                       noAgent=noAgent)
    elif (env_id == 'wob.mini.TextTransform-v0'):
        # makes use of all keyboard letters and mouse clicks
        env = ac_space.SoftmaxFullLettersAndMouse(env,
                                                  discrete_mouse_step=16,
                                                  noAgent=noAgent)
    elif (env_id == 'wob.mini.TicTacToe-v0'):
        # allows just 9 fields to click in
        env = ac_space.SoftmaxClickTask(env,
                                        discrete_mouse_step=55,
                                        noAgent=noAgent)
    else:
        # the dimension of the action_space for all other tasks are 20x20 = 400
        env = ac_space.SoftmaxClickTask(env,
                                        discrete_mouse_step=8,
                                        noAgent=noAgent)

    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)
    if (env_id == 'wob.mini.SimpleAlgebra-v0') or (
            env_id == 'wob.mini.SimpleArithmetic-v0') or (
                env_id == 'wob.mini.VisualAddition-v0'):
        # a fps rate above 3.0 on these tasks leads to instability issues due to the asynchronity between the browser inside of the docker image and the agent
        env.configure(fps=3.0,
                      remotes=remotes,
                      start_timeout=15 * 60,
                      client_id=client_id,
                      vnc_driver='go',
                      vnc_kwargs={
                          'encoding': 'tight',
                          'compress_level': 0,
                          'fine_quality_level': 100,
                          'subsample_level': 0
                      })
    else:
        # all regular tasks perform on 5.0 fps
        env.configure(fps=5.0,
                      remotes=remotes,
                      start_timeout=15 * 60,
                      client_id=client_id,
                      vnc_driver='go',
                      vnc_kwargs={
                          'encoding': 'tight',
                          'compress_level': 0,
                          'fine_quality_level': 100,
                          'subsample_level': 0
                      })
    return env
Ejemplo n.º 18
0
def create_flash_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)

    reg = universe.runtime_spec('flashgames').server_registry
    height = reg[env_id]["height"]
    width = reg[env_id]["width"]
    env = CropScreen(env, height, width, 84, 18)
    env = FlashRescale(env)

    keys = ['left', 'right', 'up', 'down', 'x']
    env = DiscreteToFixedKeysVNCActions(env, keys)
    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)
    env.configure(fps=5.0,
                  remotes=remotes,
                  start_timeout=15 * 60,
                  client_id=client_id,
                  vnc_driver='go',
                  vnc_kwargs={
                      'encoding': 'tight',
                      'compress_level': 0,
                      'fine_quality_level': 50,
                      'subsample_level': 3
                  })
    return env
Ejemplo n.º 19
0
def create_flash_env(env_id, client_id, remotes, **_):
    """
    Create a Flash environment by passing environment id.

    Parameters
    ----------
    env_id : str
        environment id to be registered in Gym
    client_id : str
        Client ID
    remotes : str
        BLANK
    kwargs : dict
        BLANK
    """
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)

    reg = universe.runtime_spec('flashgames').server_registry
    height = reg[env_id]["height"]
    width = reg[env_id]["width"]
    env = CropScreen(env, height, width, 84, 18)
    env = FlashRescale(env)

    keys = ['left', 'right', 'up', 'down', 'x']
    if env_id == 'flashgames.NeonRace-v0':
        # Better key space for this game.
        keys = ['left', 'right', 'up', 'left up', 'right up', 'down', 'up x']
    logger.info('create_flash_env(%s): keys=%s', env_id, keys)

    env = DiscreteToFixedKeysVNCActions(env, keys)
    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)
    env.configure(fps=5.0,
                  remotes=remotes,
                  start_timeout=15 * 60,
                  client_id=client_id,
                  vnc_driver='go',
                  vnc_kwargs={
                      'encoding': 'tight',
                      'compress_level': 0,
                      'fine_quality_level': 50,
                      'subsample_level': 3
                  })
    return env