How to use minerl - 7 common examples

To help you get started, we’ve selected a few minerl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github minerllabs / baselines / sample.py View on Github external
def step_data(environment='MineRLObtainDiamondDense-v0'):
    d = minerl.data.make(environment)

    # Iterate through batches of data
    for obs, rew, done, act in itertools.islice(d.seq_iter(1, 32), 600):
        print("Act shape:", len(act), act)
        print("Obs shape:", len(obs), [elem for elem in obs.items() if elem[0] != 'pov'])
        print("Rew shape:", len(rew), rew)
        print("Done shape:", len(done), done)
        time.sleep(0.1)
github minerllabs / competition_submission_starter_template / utility / verify_or_download_data.py View on Github external
import minerl.data
import os

if __name__ == "__main__":
    data_dir = os.getenv('MINERL_DATA_ROOT', 'data')
    data_dir = 'data' if not data_dir else data_dir

    print("Verifying (and downloading) MineRL dataset..\n"
          "\t**If you do not want to use the data**:\n\t\t run the local evaluation scripts with `--no-data`\n"
          "\t**If you want to use your existing download of the data**:\n "
          "\t\tmake sure your MINERL_DATA_ROOT is set.\n\n")

    print("Data directory is {}".format(data_dir))
    should_download = True
    try:
        data = minerl.data.make('MineRLObtainDiamondVectorObf-v0', data_dir=data_dir)
        assert len(data._get_all_valid_recordings(data.data_dir)) > 0
        should_download = False
    except FileNotFoundError:
        print("The data directory does not exist in your submission, are you running this script from"
              " the root of the repository? data_dir={}".format(data_dir))
    except RuntimeError:
        print("The data contained in your data directory is out of date! data_dir={}".format(data_dir))
    except AssertionError:
        print("No MineRLObtainDiamond-v0 data found. Did the data really download correctly?" )

    if should_download:
        print("Attempting to download the dataset...")
        minerl.data.download(data_dir)

    print("Data verified! A+!")
github minerllabs / baselines / general / chainerrl / baselines / behavioral_cloning.py View on Github external
if args.action_wrapper == 'discrete':
            action_converter = generate_discrete_converter(
                args.env, args.prioritized_elements,
                args.always_keys, args.reverse_keys,
                args.exclude_keys, args.exclude_noop,
                args.allow_pitch, args.max_camera_range,
                args.num_camera_discretize)
        elif args.action_wrapper == 'continuous':
            action_converter = generate_continuous_converter(
                args.env, args.allow_pitch, args.max_camera_range)
        elif args.action_wrapper == 'multi-dimensional-softmax':
            action_converter = generate_multi_dimensional_softmax_converter(
                args.allow_pitch, args.max_camera_range, args.num_camera_discretize)

        experts = ExpertDataset(
            original_dataset=minerl.data.make(args.env, data_dir=args.expert),
            observation_converter=observation_converter,
            action_converter=action_converter,
            frameskip=args.frame_skip, framestack=args.frame_stack,
            shuffle=False)

        # separate train data and validation data
        all_obs = []
        all_action = []
        for i in range(experts.size):
            obs, action, _, _, _ = experts.sample()
            all_obs.append(obs)
            all_action.append(action)
        if args.frame_stack > 1:
            all_obs = np.array(all_obs, dtype=LazyFrames)
        else:
            all_obs = np.array(all_obs)
github minerllabs / baselines / general / chainerrl / baselines / gail.py View on Github external
exclude_keys=args.exclude_keys, exclude_noop=args.exclude_noop,
            allow_pitch=True, max_camera_range=args.max_camera_range,
            num_camera_discretize=args.num_camera_discretize)
    elif args.action_wrapper == 'continuous':
        action_converter = generate_continuous_converter(
            env_name=args.env, allow_pitch=True,
            max_camera_range=args.max_camera_range)
    elif args.action_wrapper == 'multi-dimensional-softmax':
        action_converter = generate_multi_dimensional_softmax_converter(
            allow_pitch=True, max_camera_range=args.max_camera_range,
            num_camera_discretize=args.num_camera_discretize)
    if args.demo:
        experts = None  # dummy
    else:
        experts = ExpertDataset(
            original_dataset=minerl.data.make(args.env, data_dir=args.expert),
            observation_converter=observation_converter,
            action_converter=action_converter,
            frameskip=args.frame_skip, framestack=args.frame_stack,
            shuffle=False)

    # pretrain
    if args.pretrain:
        bc_opt = chainer.optimizers.Adam(alpha=2.5e-4)
        bc_opt.setup(policy)
        bc_agent = BehavioralCloning(policy, bc_opt,
                                     minibatch_size=1024,
                                     action_wrapper=args.action_wrapper)
        all_obs = []
        all_action = []
        for i in range(experts.size):
            obs, action, _, _, _ = experts.sample()
github minerllabs / competition_submission_starter_template / train.py View on Github external
def main():
    """
    This function will be called for training phase.
    """
    # How to sample minerl data is document here:
    # http://minerl.io/docs/tutorials/data_sampling.html
    data = minerl.data.make(MINERL_GYM_ENV, data_dir=MINERL_DATA_ROOT)

    # Sample code for illustration, add your training code below
    env = gym.make(MINERL_GYM_ENV)

#     actions = [env.action_space.sample() for _ in range(10)] # Just doing 10 samples in this example
#     xposes = []
#     for _ in range(1):
#         obs = env.reset()
#         done = False
#         netr = 0

#         # Limiting our code to 1024 steps in this example, you can do "while not done" to run till end
#         while not done:

            # To get better view in your training phase, it is suggested
            # to register progress continuously, example when 54% completed
github minerllabs / baselines / sample.py View on Github external
def download_data():
    directory = input("Where would you like to download MineRL-v0?\n")
    if input("(y)es to confirm: ").lower() in ['yes', 'y', 'yeah', 'sure', 'please']:
        minerl.data.download(directory=directory)
github minerllabs / competition_submission_starter_template / utility / verify_or_download_data.py View on Github external
should_download = True
    try:
        data = minerl.data.make('MineRLObtainDiamondVectorObf-v0', data_dir=data_dir)
        assert len(data._get_all_valid_recordings(data.data_dir)) > 0
        should_download = False
    except FileNotFoundError:
        print("The data directory does not exist in your submission, are you running this script from"
              " the root of the repository? data_dir={}".format(data_dir))
    except RuntimeError:
        print("The data contained in your data directory is out of date! data_dir={}".format(data_dir))
    except AssertionError:
        print("No MineRLObtainDiamond-v0 data found. Did the data really download correctly?" )

    if should_download:
        print("Attempting to download the dataset...")
        minerl.data.download(data_dir)

    print("Data verified! A+!")

minerl

MineRL environment and data loader for reinforcement learning from human demonstration in Minecraft

MIT
Latest version published 3 years ago

Package Health Score

58 / 100
Full package analysis

Popular minerl functions