Example #1
0
def main(args):
    maze_id = args.maze_id
    GazeboMaze = env.GazeboMaze(maze_id=maze_id, continuous=True)
    print("Generating data for env maze{}".format(maze_id))
    file_number = args.file_number
    total_episodes = args.total_episodes
    # random_generated_int = np.random.randint(0, 2 ** 31 - 1)
    # np.random.seed(random_generated_int)
    time_steps = args.time_steps
    for i in range(file_number):
        total_frames = 0
        obs_data = []
        action_data = []
        episode = 0
        while episode < total_episodes:
            print('---------------------------')
            obs_sequence = []
            action_sequence = []

            observation = GazeboMaze.reset()
            done = False
            t = 0

            while t < time_steps:
                action = dict()
                action['linear_vel'] = np.random.uniform(0, 1)
                action['angular_vel'] = np.random.uniform(-1, 1)
                # print(action)
                obs_sequence.append(observation)
                action_sequence.append(
                    [action['linear_vel'], action['angular_vel']])
                t += 1

                observation, done, reward = GazeboMaze.execute(action)

            total_frames += t
            episode += 1
            obs_data.append(obs_sequence)
            action_data.append(action_sequence)
            print("{}th collections".format(i))
            print("Episode {} finished after {} timesteps".format(episode, t))
            print("Current dataset contains {} observations".format(
                total_frames))

        print("Saving dataset ...")
        np.save(dir_name + '/observation' + str(i), obs_data)
        np.save(dir_name + '/action' + str(i), action_data)
    GazeboMaze.close()
Example #2
0
from tensorforce.agents import PPOAgent

import os
import itertools

import config
import env
import worldModels.VAE

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

maze_id = config.maze_id
deterministic = config.deterministic
restore = False

GazeboMaze = env.GazeboMaze(maze_id=maze_id, continuous=True)

record_dir = 'record'
if not os.path.exists(record_dir):
    os.makedirs(record_dir)

saver_dir = './models/nav{}'.format(maze_id)
if not os.path.exists(saver_dir):
    os.makedirs(saver_dir)

summarizer_dir = './record/PPO_remap/nav{}'.format(maze_id)
if not os.path.exists(summarizer_dir):
    os.makedirs(summarizer_dir)

vae = worldModels.VAE.VAE()
vae.set_weights(config.vae_weight)
Example #3
0
from tensorforce.agents import DQNAgent
import os
import env
import config

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

maze_id = config.maze_id
restore = False

GazeboMaze = env.GazeboMaze(maze_id=maze_id, continuous=False)

record_dir = 'record'
if not os.path.exists(record_dir):
    os.makedirs(record_dir)

saver_dir = './models/nav{}'.format(maze_id)
if not os.path.exists(saver_dir):
    os.makedirs(saver_dir)

summarizer_dir = './record/E2E_DQN/nav{}'.format(maze_id)
if not os.path.exists(summarizer_dir):
    os.makedirs(summarizer_dir)

states = dict(image=GazeboMaze.states,
              previous_act=dict(shape=(2, ), type='float'),
              relative_pos=dict(shape=(2, ), type='float'))

network_spec = [[
    dict(type='input', names=['image']),
    dict(type='conv2d',