示例#1
0
def load_replay_pulls_from_file():
    if os.path.isfile(REPLAY_PULLS_FILE_NAME):
        # TODO (9) write numpy allow pickle version reminder
        return np.load(REPLAY_PULLS_FILE_NAME)
    else:
        logger.critical(f'File {REPLAY_PULLS_FILE_NAME} not found for ReplayEnvironment')
        return None
示例#2
0
def main():
    logger.debug('main starting')

    if ENVIRONMENT_TYPE is EnvironmentTypes.CARLA:
        env = CarlaEnvironment()
    elif ENVIRONMENT_TYPE is EnvironmentTypes.Replay:
        env = ReplayEnvironment()
    else:
        logger.critical('Unknown environment type in main, raising error')
        raise RuntimeError('Unknown environment type in main')

    dashboard = DashboardThread()

    log_settings(env)

    try:
        env.setup()
        env.start()
        dashboard.start()

        # normal_main_loop(env, dashboard)
        train_multiple_main_loop(env, dashboard)

    finally:
        if env is not None:
            for actor in env.actors:
                actor.destroy()
            del env  # Make sure to forget env after we cleaned up it's actors
        logger.debug('Cleaned up')
 def __set_conditions(self):
     current_map_name = self.connection.world.get_map().name
     # Loading correct map
     if current_map_name != MAP_NAME:
         logger.info(f'Loading map: {MAP_NAME} <- {current_map_name}')
         try:
             self.connection.world = self.connection.client.load_world(
                 MAP_NAME)
         except RuntimeError as r:
             logger.critical(f'{r}')
             raise r
     else:
         # Destroying old actors
         actors = self.connection.world.get_actors()
         for actor in actors.filter('vehicle.*.*'):
             actor.destroy()
         for actor in actors.filter('sensor.*.*'):
             actor.destroy()
         if len(actors.filter('vehicle.*.*')) > 0 and len(
                 actors.filter('sensor.*.*')) > 0:
             logger.debug('Cleaned up old actors')
         else:
             logger.warning('Issues while cleaning up old actors')
     # Setting nice weather
     self.__set_weather()
示例#4
0
def normal_main_loop(env, dashboard):
    if AGENT_TYPE is AgentTypes.Network:
        agent = NetworkAgent(NETWORK_AGENT_MODEL_TYPE)
    elif AGENT_TYPE is AgentTypes.Keras:
        agent = KerasAgent()
    elif AGENT_TYPE is AgentTypes.Omniscient:
        agent = OmniscientAgent()
    else:
        logger.critical('Unknown agent type in main, raising error')
        raise RuntimeError('Unknown agent type in main')
    agent.load()

    statefilters = [ImageNoiseFilter(st_dev=0.001)]  # st_dev = 0.02 is alright
    outputfilters = [MotorNoiseFilter(st_dev=0.001)
                     ]  # st_dev = 0.05 is alright

    memory = []
    i = 0
    while True:
        env.load_path(i)

        traveled = do_run(agent, env, dashboard, statefilters, outputfilters,
                          memory)
        logger.info(f'Agent finished, traveled {traveled} meters')

        dashboard.clear()
        env.reset()

        train(agent, memory)
        logger.info('Continuing...')
        i += 1
示例#5
0
    def __init__(self):
        self.i = 0
        self.pulls = load_replay_pulls_from_file()
        self.statuses = load_replay_statuses_from_file()

        if self.pulls is None or self.statuses is None or len(self.pulls) < 1 or len(self.statuses) < 1:
            logger.critical('Critical data issues in ReplayEnvironment')
            raise RuntimeError('Critical data issues in ReplayEnvironment')
示例#6
0
 def load(self, path=NETWORKAGENT_MODEL_PATH):
     logger.info(f'Loading model from {path}')
     try:
         self.model.load_model(path,
                               dim_features=get_feature_dimension,
                               image_height=AGENT_IM_HEIGHT,
                               image_width=AGENT_IM_WIDTH,
                               n_actions=choices_count,
                               model=self.model_class)
     except FileNotFoundError as f:
         logger.error(f'Failed to find file at {path} - {f}')
     except RuntimeError as r:
         logger.critical(f'Failed to load agent from {path} - {r}')
示例#7
0
import glob
import os
import sys
import time
import numpy as np

from support.logger import logger

try:
    sys.path.append(glob.glob('files/carla-*%d.%d-%s.egg' % (
        sys.version_info.major,
        sys.version_info.minor,
        'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
    logger.critical('IndexError while trying to find carla egg')
    logger.info('Place carla egg into files directory')
    sys.exit()
try:
    import carla  # Carla package uses the egg from Carla - Python installed package doesn't work
except ModuleNotFoundError:
    logger.critical('ModuleNotFoundError while importing carla from egg')
    sys.exit()

# TODO (8) hide ICarla with a proper interface or smth


def client(host, port):
    return carla.Client(host, port)


def transform(x=0.0, y=0.0, z=0.0, pitch=0.0, yaw=0.0, roll=0.0):
示例#8
0
def load_replay_statuses_from_file():
    if os.path.isfile(REPLAY_STATUSES_FILE_NAME):
        return np.load(REPLAY_STATUSES_FILE_NAME)
    else:
        logger.critical(f'File {REPLAY_STATUSES_FILE_NAME} not found for ReplayEnvironment')
        return None
示例#9
0
 def optimize(self, new_state, prev_state=None, action=None):
     logger.critical('Optimize unsupported for this agent.')