Beispiel #1
0
from Environments.env_utils import make_env_utils
from NeuralNetwork.neural_net import NeuralNet
from PPO_trainer import PPO_trainer, evaluate

# Create parser and parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('--parameters', type=str)
parser.add_argument('--logdir', type=str, default=None)
args = parser.parse_args()

# Open the json parameters file
with open(args.parameters) as f:
    parameters = json.load(f)

# Create env and env_utils
env_utils, env = make_env_utils(**parameters)

# Get network kwargs from env_utils
network_kwargs = env_utils.get_network_kwargs()
# Add additional kwargs from parameter file
network_kwargs.update(parameters['neural_network'])

ac = NeuralNet(**network_kwargs)

if parameters['mode'] == 'training':
    # Create the directories for logs and saved models
    parent_dir = os.path.dirname(args.logdir)
    if not os.path.exists(parent_dir):
        os.makedirs(parent_dir)
    models_dir = os.path.dirname(args.logdir + 'saved_models/')
    if not os.path.exists(models_dir):
Beispiel #2
0
    def __init__(
        self,
        starting_map_size=(10., 10., 2.),
        cell_scale=(1., 1., 1.),
        starting_position=(0., 0., 0.),
        buffer_distance=(10., 10., 0.),
        local_map_dim=(16, 16, 1),
        vision_range=1,
        fov_angle=np.pi / 2,
        map_keys=[
            'unknown', 'visible', 'visited', 'obstacle', 'object', 'position'
        ],
        thresholds={
            'visible': 1,
            'visited': 1,
            'obstacle': 1,
            'object': 1
        },
        map_idx=0,
        interactive_plot=False,
        REWARD_FAILURE=-10,
        REWARD_STEP=-0.5,
        **parameters,
    ):

        super().__init__(
            starting_map_size=starting_map_size,
            cell_scale=cell_scale,
            starting_position=starting_position,
            buffer_distance=buffer_distance,
            local_map_dim=local_map_dim,
            vision_range=vision_range,
            fov_angle=fov_angle,
            map_keys=map_keys,
            thresholds=thresholds,
            map_idx=map_idx,
            interactive_plot=interactive_plot,
            REWARD_FAILURE=REWARD_FAILURE,
            REWARD_STEP=REWARD_STEP,
        )

        parameters_airsim = {'env_str': 'AirSim'}
        parameters_airsim['AirSim'] = parameters['AirSim']
        self.env_utils_airsim, self.env_airsim = make_env_utils(
            **parameters_airsim)
        network_kwargs = self.env_utils_airsim.get_network_kwargs()
        network_kwargs.update(
            parameters['Exploration']['local_navigation']
            ['neural_network'])  # add additional kwargs from parameter file

        self.local_navigator = NeuralNet(**network_kwargs)
        self.local_navigator.load_state_dict(
            torch.load(
                parameters['Exploration']['local_navigation']['weights']))

        self.navigator_max_steps = parameters['navigator_max_steps']
        self.object_detection_frequency = parameters[
            'object_detection_frequency']
        self.obstacle_detection_frequency = parameters[
            'obstacle_detection_frequency']
        self.env_airsim.setup_object_detection(
            **parameters['object_detection'])

        self.reward_scaling = (self.vision_range / self.cell_scale[0]) * \
                              (self.vision_range / self.cell_scale[1]) * \
                              (self.vision_range / self.cell_scale[2]) * fov_angle / 2  # divide by area