def main(): args, agent_args = get_args() c.MAIN_ARGS = vars(args) # For documenting runs if args.verbose: logs.set_level(logging.DEBUG) if args.update_sim: ensure_sim(update=True) return if args.public and not c.PUBLIC: answer = input('Please confirm you want to make the results ' 'of this evaluation public? ') args.public = answer.lower() in ['y', 'yes'] if not args.public: print('Answer was not "y" or "yes", not making public') if args.recording_dir.startswith('~'): args.recording_dir = os.path.expanduser(args.recording_dir) if args.hdf5_2_tfrecord: from agents.dagger.train import hdf5_to_tfrecord hdf5_to_tfrecord.encode(hdf5_path=args.recording_dir, experiment=args.experiment) return elif args.server or args.json_server: from deepdrive_api import server sim_args = None log.info('Starting Deepdrive server') if len(sys.argv) > 2: # More than just --server was passed, # so sim will be configured purely on the server side, # vs purely from the client in order to prevent # cheating / clients that change their environment in evals. sim_args = get_sim_args_from_command_args(args) if sim_args is not None: sim_args = sim_args.to_dict() ensure_sim() server.start(sim, json_mode=args.json_server, sim_path=get_sim_path(), sim_args=sim_args) return else: camera_rigs = get_camera_rigs(args) driving_style = DrivingStyle.from_str(args.driving_style) from install import check_tensorflow_gpu if args.path_follower: run_path_follower(args, camera_rigs) elif not check_tensorflow_gpu(): log.info('Tensorflow not installed, falling back to PID path ' 'follower agent as mnet2 baseline agent requires ' 'Tensorflow') run_path_follower(args, camera_rigs) else: run_tf_based_models(args, camera_rigs, driving_style)
def main(): parser = argparse.ArgumentParser(description=None) parser.add_argument('-e', '--env-id', nargs='?', default='DeepDrive-v0', help='Select the environment to run') parser.add_argument( '-r', '--record', action='store_true', default=False, help='Records game driving, including recovering from random actions') parser.add_argument('--baseline', action='store_true', default=False, help='Runs pretrained imitation learning based agent') parser.add_argument('-t', '--train', action='store_true', default=False, help='Trains tensorflow agent on stored driving data') parser.add_argument('--use-last-model', action='store_true', default=False, help='Run the most recently trained model') parser.add_argument('--recording-dir', nargs='?', default=c.RECORDING_DIR, help='Where to store and read recorded ' 'environment data from') parser.add_argument( '--render', action='store_true', default=False, help= 'SLOW: render of camera data in Python - Use Unreal for real time camera rendering' ) parser.add_argument( '--record-recovery-from-random-actions', action='store_true', default=False, help= 'Whether to occasionally perform random actions and record recovery from them' ) parser.add_argument('--path-follower', action='store_true', default=False, help='Whether to let the in-game path follower drive') parser.add_argument( '--net-path', nargs='?', default=None, help='Path to the tensorflow checkpoint you want to test drive. ' 'i.e. /home/a/DeepDrive/tensorflow/2018-01-01__11-11-11AM_train/model.ckpt-98331' ) parser.add_argument( '--resume-train', nargs='?', default=None, help='Path to the tensorflow training session you want to resume, ' 'i.e. /home/a/DeepDrive/tensorflow/2018-01-01__11-11-11AM_train') parser.add_argument('-v', '--verbose', help='Increase output verbosity', action='store_true') parser.add_argument('--camera-rigs', nargs='?', default=None, help='Name of camera rigs to use') parser.add_argument('-n', '--experiment-name', nargs='?', default=None, help='Name of your experiment') parser.add_argument('--fps', type=int, default=c.DEFAULT_FPS, help='Frames / steps per second') args = parser.parse_args() if args.verbose: logs.set_level(logging.DEBUG) if args.camera_rigs: camera_rigs = camera_config.rigs[args.camera_rigs] else: camera_rigs = camera_config.rigs['baseline_rigs'] if args.use_last_model: if args.train: args.resume_train = get_latest_model() else: args.net_path = get_latest_model() if args.train: from tensorflow_agent.train import train # TODO: Add experiment name here as well, and integrate it into Tensorflow runs, recording names, model checkpoints, etc... train.run(resume_dir=args.resume_train, recording_dir=args.recording_dir) elif args.path_follower: done = False render = False episode_count = 1 gym_env = None try: gym_env = deepdrive.start(args.experiment_name, args.env_id, fps=args.fps) log.info('Path follower drive mode') for episode in range(episode_count): if done: gym_env.reset() while True: action = deepdrive.action(has_control=False) obz, reward, done, _ = gym_env.step(action) if render: gym_env.render() if done: gym_env.reset() except KeyboardInterrupt: log.info('keyboard interrupt detected, closing') except Exception as e: log.error('Error running agent. %s', e) if gym_env: gym_env.close() raise e if gym_env: gym_env.close() log.info('Last episode complete, closing') else: from tensorflow_agent import agent if args.record and not args.record_recovery_from_random_actions: args.path_follower = True agent.run(args.experiment_name, should_record=args.record, net_path=args.net_path, env_id=args.env_id, run_baseline_agent=args.baseline, render=args.render, camera_rigs=camera_rigs, should_record_recovery_from_random_actions=args. record_recovery_from_random_actions, path_follower=args.path_follower, fps=args.fps)