Example #1
0
def main():

    # Make a command-line parser
    parser = make_parser_3d()
    parser.add_argument('filename', metavar='FILENAME', help='input file')
    args = parser.parse_args()
    viewangles = parse_view_angles(args)

    # Load net and environment name from pickled file
    net, env_name = pickle.load(open(args.filename, 'rb'))

    # Make environment from name
    env = gym.make(env_name)

    movie_name = None

    if args.movie:
        print('Running episode ...')
        movie_name = 'movie.mp4'

    # Begin 3D rendering on main thread
    # render, report = True, True
    renderer = ThreeDLanderRenderer(env,
                                    eval_with_movie, (net, args.seed),
                                    viewangles=viewangles,
                                    outfile=movie_name)
    renderer.start()
Example #2
0
    def render(self, mode='human'):

        from gym_copter.rendering.threed import ThreeDLanderRenderer

        # Create renderer if not done yet
        if self.renderer is None:
            self.renderer = ThreeDLanderRenderer(self, self.LANDING_RADIUS)

        return self.renderer.render()
Example #3
0
def run(env, radius):

    from gym_copter.rendering.threed import ThreeDLanderRenderer
    import threading

    viewer = ThreeDLanderRenderer(env, radius)

    thread = threading.Thread(target=heuristic_lander,
                              args=(env, heuristic, viewer))
    thread.daemon = True
    thread.start()

    # Begin 3D rendering on main thread
    viewer.start()
Example #4
0
def main():

    # Parse command-line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('filename', metavar='FILENAME', help='input file')
    parser.add_argument('--record',
                        default=None,
                        help='If specified, sets the recording dir')
    parser.add_argument('--seed',
                        default=None,
                        type=int,
                        help='Sets Gym, PyTorch and Numpy seeds')
    args = parser.parse_args()

    # Load network, environment name, and number of hidden units from pickled file
    parts, env_name, nhid = torch.load(open(args.filename, 'rb'))

    # Make a gym environment from the name
    env = gym.make(env_name)

    # Set random seed if indicated
    if args.seed is not None:
        env.seed(args.seed)
        torch.manual_seed(args.seed)
        np.random.seed(args.seed)

    # Support recordinga  movie
    if args.record:
        env = wrappers.Monitor(env, args.record, force=True)

    # We use a different evaluator functions for TD3 vs. other algorithms
    fun = run_td3 if 'td3' in args.filename else run_other

    # Create a three-D renderer
    renderer = ThreeDLanderRenderer(env)

    # Start the network-evaluation episode on a separate thread
    thread = threading.Thread(target=fun, args=(parts, env, nhid, args.record))
    thread.daemon = True
    thread.start()

    # Begin 3D rendering on main thread
    renderer.start()
Example #5
0
def main():

    # Make a command-line parser with --view enabled
    parser = make_parser()
    parser.add_argument('filename', metavar='FILENAME', help='input file')
    parser.add_argument('--movie',
                        default=None,
                        help='If specified, sets the output movie file name')
    parser.add_argument('--seed',
                        default=None,
                        type=int,
                        help='Sets Gym, PyTorch and Numpy seeds')
    args, viewangles = parse(parser)

    # Load network, environment name, and number of hidden units from pickled
    # file
    parts, env_name, nhid = torch.load(open(args.filename, 'rb'))

    # Make a gym environment from the name
    env = gym.make(env_name)

    # Set random seed if indicated
    if args.seed is not None:
        env.seed(args.seed)
        torch.manual_seed(args.seed)
        np.random.seed(args.seed)

    # We use a different evaluator functions for TD3 vs. other algorithms
    fun = run_td3 if 'td3' in args.filename else run_other

    if args.movie is not None:
        print('Running episode ...')

    # Start the network-evaluation episode on a separate thread
    thread = threading.Thread(target=fun, args=(parts, env, nhid, args.movie))
    thread.start()

    # Begin 3D rendering on main thread
    renderer = ThreeDLanderRenderer(env,
                                    viewangles=viewangles,
                                    outfile=args.movie)
    renderer.start()
Example #6
0
def main():

    # Make a command-line parser
    parser = make_parser_3d()
    parser.add_argument('filename', metavar='FILENAME', help='input file')
    args = parser.parse_args()
    viewangles = parse_view_angles(args)

    # Load network, environment name, and number of hidden units from pickled
    # file
    parts, env_name, nhid = torch.load(open(args.filename, 'rb'))

    # Make a gym environment from the name
    env = gym.make(env_name)

    # Set random seed if indicated
    if args.seed is not None:
        env.seed(args.seed)
        torch.manual_seed(args.seed)
        np.random.seed(args.seed)

    # We use a different evaluator functions for TD3 vs. other algorithms
    fun = run_td3 if 'td3' in args.filename else run_other

    movie_name = None

    if args.movie:
        print('Running episode ...')
        movie_name = 'movie.mp4'

    # Begin 3D rendering on main thread
    renderer = ThreeDLanderRenderer(env,
                                    fun, (parts, nhid, movie_name),
                                    viewangles=viewangles,
                                    outfile=movie_name)
    renderer.start()
Example #7
0
import gym
from neat_gym import read_file, eval_net
from gym_copter.rendering.threed import ThreeDLanderRenderer
import threading


def _eval_net(net, env):

    print('Reward = %+03.f' % eval_net(net, env, render=True))


if __name__ == '__main__':

    # Load network and environment name from pickled file
    net, env_name, _, _ = read_file()

    # Make environment from name
    env = gym.make(env_name)

    # Create a three-D renderer
    renderer = ThreeDLanderRenderer(env)

    # Start the network-evaluation episode on a separate thread
    thread = threading.Thread(target=_eval_net, args=(net, env_name))
    thread.daemon = True
    thread.start()

    # Begin 3D rendering on main thread
    renderer.start()