Beispiel #1
0
from ifqi import envs
import argparse, random
import numpy as np

parser = argparse.ArgumentParser()
parser.add_argument('--path',
                    type=str,
                    default='data/breakout/model.h5',
                    help='path to the hdf5 weights file for the autoencoder')
parser.add_argument('--original', action='store_true')
parser.add_argument('--rebuilt', action='store_true')
parser.add_argument('--convmap', action='store_true')
args = parser.parse_args()

env = envs.Atari('BreakoutDeterministic-v3')
AE = Autoencoder((4 * 84 * 84, ), load_path=args.path)

state0 = env.reset()

# Move base to the left
state0, reward, done, info = env.step(3)
state00, reward, done, info = env.step(3)  # Base moves one step wrt state 0

# Start the game
state1, reward, done, info = env.step(1)

# Keep base to the left and move only the ball
for i in range(10):
    state1, reward, done, info = env.step(3)
state2, reward, done, info = env.step(3)  # Ball moves one step wrt state 1
Beispiel #2
0
args = parser.parse_args()
logger = Logger(
    debug=args.debug,
    output_folder='../ifqi/algorithms/selection/feature_extraction/output/',
)
# Redirect stdout
if args.log:
    old_stdout = sys.stdout
    sys.stdout = open(logger.path + 'output_dump.txt', 'w', 0)

# Create environment
# TODO Enduro, MsPacman, Qbert
mdp = envs.Atari(name=args.env)

# Feature extraction model (used for collecting episodes and evaluation)
AE = Autoencoder((4 * 84 * 84, ), load_path=args.path)

# Read or collect dataset
if args.dataset is not None:
    # Load from disk if dataset was provided
    print('Loading dataset at %s' % args.dataset)
    dataset = np.loadtxt(args.dataset, delimiter=',', skiprows=1)
else:
    print('Collecting episodes using model at %s' % args.path)
    collection_params = {
        'episodes': args.episodes,
        'env_name': args.env,
        'header': None,
        'minimum_score': args.min_score,
        'onehot': args.onehot,
        'video': False,
Beispiel #3
0
from ifqi.envs.gridworld import GridWorldEnv
from helpers import crop_state
from PIL import Image
from ifqi import envs
import argparse, random
import numpy as np

parser = argparse.ArgumentParser()
parser.add_argument('--path', type=str, default='data/breakout/model.h5', help='path to the hdf5 weights file for the autoencoder')
parser.add_argument('--original', action='store_true')
parser.add_argument('--rebuilt', action='store_true')
parser.add_argument('--convmap', action='store_true')
args = parser.parse_args()

env = envs.Atari('BreakoutDeterministic-v3')
AE = Autoencoder((4 * 84 * 84,), load_path=args.path)

state0 = env.reset()

# Move base to the left
state0, reward, done, info = env.step(3)
state00, reward, done, info = env.step(3)  # Base moves one step wrt state 0

# Start the game
state1, reward, done, info = env.step(1)

# Keep base to the left and move only the ball
for i in range(10):
    state1, reward, done, info = env.step(3)
state2, reward, done, info = env.step(3)  # Ball moves one step wrt state 1
Beispiel #4
0
    parser.add_argument('-d', '--debug', action='store_true', help='run in debug mode (no output files)')
    parser.add_argument('-v', '--video', action='store_true', help='display video output')
    parser.add_argument('--njobs', type=int, default=1, help='number of processes to use. Don\'t set this flag w/ GPU.')
    parser.add_argument('--env', type=str, default='BreakoutDeterministic-v3', help='Atari environment to run')
    parser.add_argument('--episodes', type=int, default=1000, help='number of episodes to run')
    parser.add_argument('--path', type=str, default='data/model.h5', help='path to the hdf5 weights file for the AE')
    parser.add_argument('-e', '--encode', action='store_true', help='save a SARS dataset with the encoded features')
    parser.add_argument('-i', '--images', action='store_true', help='save images of states and a SARS csv with ids')
    parser.add_argument('--min-score', type=int, default=0, help='keep episode only if it got more than this score')
    parser.add_argument('--onehot', action='store_true', help='save actions in the dataset with onehot encoding')
    args = parser.parse_args()

    logger = Logger(debug=args.debug)

    if args.encode:
        AE = Autoencoder((4 * 84 * 84,), load_path=args.path)

        # Automatically generate headers from the output length of AE.flat_encode
        nb_states = AE.flat_encode(np.expand_dims(np.ones(AE.input_shape), axis=0)).shape[0]
        nb_actions = envs.Atari(args.env).action_space.n
        actions_header = ['A%s' % i for i in xrange(nb_actions)] if args.onehot else ['A0']
        header = ['S%s' % i for i in xrange(nb_states)] + actions_header + ['R'] + \
                        ['SS%s' % i for i in xrange(nb_states)] + ['Absorbing', 'Finished']

        # Collect episodes
        dataset = collect_encoded_dataset(AE,
                                episodes=args.episodes,
                                env_name=args.env,
                                header=header,
                                onehot=args.onehot,
                                minimum_score=args.min_score,