# Path: rlvision/utils.py
# def load_grid_selection(path):
# def process_map_data(path, return_full=False):
# def mask_grid(pos, grid, radius, one_is_free=True):
# def accumulate_map(source_grid, new_grid, one_is_free=True):
# def plot_grid(data, imsize, start=None, pos=None, goal=None, title=None):
# def process_gridworld_data(data_in, imsize):
# def load_mat_data(file_path):
# def find_layout(data, verbose=0):
# def init_h5_db(db_name, save_dir):
# def add_h5_group(group_name, db, db_path=None):
# def add_h5_ds(data, ds_name, db, group_name=None, data_type=np.uint8,
#               renew=False):
# def create_grid_8_dataset(mat_file_path, db_name, save_dir):
# def create_ds_from_splits(mat_file_prefix, db, splits):
# def create_grid_16_dataset(mat_file_prefix, db_name, save_dir, splits=5):
# def create_grid_28_dataset(mat_file_prefix, db_name, save_dir, splits=20):
# def create_grid_40_dataset(mat_file_prefix, db_name, save_dir, splits=100):
# def load_grid8(return_imsize=True):
# def load_grid16(split=None, return_imsize=True):
# def load_grid28(split=None, return_imsize=True):
# def load_grid40(split=None, return_imsize=True):


import numpy as np
import keras.backend as K
from keras.models import Model
from keras.layers import Input, Conv2D, merge, Reshape, Dense, Lambda, add
from rlvision import utils
    res = model.predict([im_ary,
                         np.array([pos])])

    action = np.argmax(res)
    reward = get_layer_output(model, 'reward', im_ary)
    value = get_layer_output(model, 'value{}'.format(k), im_ary)
    reward = np.reshape(reward, im.shape[1:])
    value = np.reshape(value, im.shape[1:])

    return res, action, reward, value


class Game(object):
    """Define a game."""
    def __init__(self, grid, state, label, goal):
        self.grid = grid
        self.step_map = np.zeros((2, 16, 16))
        self.step_map[0] = np.ones((16, 16))
        self.step_map[1] = grid[1]

        self.state = state
        self.label = label
        self.goal = goal

        self.pos = [state[0, 0], state[0, 1]]
        self.path = [(self.pos[0], self.pos[1])]

    def update_step_map(self, pos):
        masked_img = utils.mask_grid((pos[1], pos[0]),
                                     self.grid[0], 3, one_is_free=False)

# Path: rlvision/utils.py
# def load_grid_selection(path):
# def process_map_data(path, return_full=False):
# def mask_grid(pos, grid, radius, one_is_free=True):
# def accumulate_map(source_grid, new_grid, one_is_free=True):
# def plot_grid(data, imsize, start=None, pos=None, goal=None, title=None):
# def process_gridworld_data(data_in, imsize):
# def load_mat_data(file_path):
# def find_layout(data, verbose=0):
# def init_h5_db(db_name, save_dir):
# def add_h5_group(group_name, db, db_path=None):
# def add_h5_ds(data, ds_name, db, group_name=None, data_type=np.uint8,
#               renew=False):
# def create_grid_8_dataset(mat_file_path, db_name, save_dir):
# def create_ds_from_splits(mat_file_prefix, db, splits):
# def create_grid_16_dataset(mat_file_prefix, db_name, save_dir, splits=5):
# def create_grid_28_dataset(mat_file_prefix, db_name, save_dir, splits=20):
# def create_grid_40_dataset(mat_file_prefix, db_name, save_dir, splits=100):
# def load_grid8(return_imsize=True):
# def load_grid16(split=None, return_imsize=True):
# def load_grid28(split=None, return_imsize=True):
# def load_grid40(split=None, return_imsize=True):


# Path: rlvision/vin.py
import numpy as np
import keras.backend as K
from keras.models import Model
from keras.layers import Input, Conv2D, merge, Reshape, Dense, Lambda, add
from rlvision import utils

    res = model.predict([im_ary,
                         np.array([pos])])

    action = np.argmax(res)
    reward = get_layer_output(model, 'reward', im_ary)
    value = get_layer_output(model, 'value{}'.format(k), im_ary)
    reward = np.reshape(reward, im.shape[1:])
    value = np.reshape(value, im.shape[1:])

    return res, action, reward, value


class Game(object):
    """Define a game."""
    def __init__(self, grid, state, label, goal):
        self.grid = grid
        self.step_map = np.zeros((2, 16, 16))
        self.step_map[0] = np.ones((16, 16))
        self.step_map[1] = grid[1]

        self.state = state
        self.label = label
        self.goal = goal

        self.pos = [state[0, 0], state[0, 1]]
        self.path = [(self.pos[0], self.pos[1])]

    def update_step_map(self, pos):
        masked_img = utils.mask_grid((pos[1], pos[0]),
                                     self.grid[0], 3, one_is_free=False)

        self.step_map[0] = utils.accumulate_map(