Esempio n. 1
0
    def __init__(self, name: Optional[str] = None):
        """Creates an instance of `Network`.

        Args:
          name: A string representing the name of the network.
        """
        self._log = logger.get_logger(self.__class__.__name__)
        self._config_handler = KatherineApplication.get_application_config()
        self._serializer = KatherineApplication.get_application_factory(
        ).build_model_serializer()
        self._name = name or None
        self._load_configuration()
Esempio n. 2
0
 def __init__(self):
     """
     Default constructor.
     """
     self._log = logger.get_logger(self.__class__.__name__)
     self._config_handler = KatherineApplication.get_application_config()
     if not self._config_handler:
         raise ValueError("No config specified.")
     self._game = KatherineApplication.get_application_factory().build_game()
     self._agent = KatherineApplication.get_application_factory().build_agent()
     self._metrics = KatherineApplication.get_application_factory().build_metrics_tracer()
     self._load_configuration()
Esempio n. 3
0
 def __init__(self):
     """
     Default constructor.
     """
     self._load_configuration()
     self._work_directory = fileio.build_models_work_directory(WORKING_DIRECTORY_PREFIX)
     self._storage_driver = KatherineApplication.get_application_factory().build_model_storage_driver()
Esempio n. 4
0
 def _build_memory_access(self) -> None:
     """
     Helper function for building readonly memory.
     """
     if self._memory_access is None:
         self._memory_access = KatherineApplication.get_application_factory(
         ).build_memory_access()
         self._memory_access.init(self._replay_memory)
Esempio n. 5
0
 def __init__(self):
     """
     Default constructor.
     """
     self._config_handler = KatherineApplication.get_application_config()
     if not self._config_handler:
         raise ValueError("No config_handler specified")
     self._log = logger.get_logger(self.__class__.__name__)
Esempio n. 6
0
    def _load_configuration() -> Collection[Tuple]:
        """
        Loads the server configurations.

        :return:
            a list of tuples with server configs
        """
        return KatherineApplication.get_application_config(
        ).get_config_property(KatConfigurationProperty.CLUSTER_INFO,
                              KatConfigurationProperty.CLUSTER_INFO.prop_type)
Esempio n. 7
0
 def _load_configuration(self):
     """
     Loads necessary configurations.
     """
     self._config_handler = KatherineApplication.get_application_config()
     if not self._config_handler:
         raise ValueError("No configuration handler specified.")
     self._train_batch_size = self._config_handler.get_config_property(
         KatConfigurationProperty.TRAIN_BATCH_SIZE,
         KatConfigurationProperty.TRAIN_BATCH_SIZE.prop_type)
     self._distributed_learning_enabled = self._config_handler.get_config_property(
         AgentConfigurationProperty.DISTRIBUTED_LEARNING_ENABLED,
         AgentConfigurationProperty.DISTRIBUTED_LEARNING_ENABLED.prop_type)
     self._convert_to_monochrome = self._config_handler.get_config_property(
         AgentConfigurationProperty.CONVERT_TO_MONOCHROME,
         AgentConfigurationProperty.CONVERT_TO_MONOCHROME.prop_type)
     self._screen_channels = self._config_handler.get_config_property(
         AgentConfigurationProperty.SCREEN_CHANNELS,
         AgentConfigurationProperty.SCREEN_CHANNELS.prop_type)
     self._frame_stacking_enabled = self._config_handler.get_config_property(
         AgentConfigurationProperty.FRAME_STACKING_ENABLED,
         AgentConfigurationProperty.FRAME_STACKING_ENABLED.prop_type)
     self._number_of_stacked_frames = self._config_handler.get_config_property(
         AgentConfigurationProperty.NUMBER_OF_STACKED_FRAMES,
         AgentConfigurationProperty.NUMBER_OF_STACKED_FRAMES.prop_type)
     self._screen_size = (
         self._config_handler.get_config_property(
             AgentConfigurationProperty.SCREEN_HEIGHT,
             AgentConfigurationProperty.SCREEN_HEIGHT.prop_type),
         self._config_handler.get_config_property(
             AgentConfigurationProperty.SCREEN_WEIGHT,
             AgentConfigurationProperty.SCREEN_WEIGHT.prop_type))
     self._input_observation_name = self._config_handler.get_config_property(
         AgentConfigurationProperty.INPUT_OBSERVATION_NAME,
         AgentConfigurationProperty.INPUT_OBSERVATION_NAME.prop_type)
     self._initial_epsilon = self._config_handler.get_config_property(
         AgentConfigurationProperty.INITIAL_EXPLORATION_RATE,
         AgentConfigurationProperty.INITIAL_EXPLORATION_RATE.prop_type)
     self._final_epsilon = self._config_handler.get_config_property(
         AgentConfigurationProperty.FINAL_EXPLORATION_RATE,
         AgentConfigurationProperty.FINAL_EXPLORATION_RATE.prop_type)
     self._constant_exploration = self._config_handler.get_config_property(
         AgentConfigurationProperty.CONSTANT_EXPLORATION_PERCENTAGE,
         AgentConfigurationProperty.CONSTANT_EXPLORATION_PERCENTAGE.
         prop_type)
     self._decaying_exploration = self._config_handler.get_config_property(
         AgentConfigurationProperty.DECAYING_EXPLORATION_PERCENTAGE,
         AgentConfigurationProperty.DECAYING_EXPLORATION_PERCENTAGE.
         prop_type)
     self._max_episodes = self._config_handler.get_config_property(
         KatConfigurationProperty.MAX_EPISODES,
         KatConfigurationProperty.MAX_EPISODES.prop_type)
     self._max_observe_episodes = self._config_handler.get_config_property(
         AgentConfigurationProperty.MAX_OBSERVE_EPISODES,
         AgentConfigurationProperty.MAX_OBSERVE_EPISODES.prop_type)
Esempio n. 8
0
 def _load_configuration(self) -> None:
     """
     Loads the configuration.
     """
     config_handler = KatherineApplication.get_application_config()
     self._is_model_persistence_enabled = config_handler.get_config_property(
         ModelSerializerProperty.MODEL_PERSISTENCE_ENABLED,
         ModelSerializerProperty.MODEL_PERSISTENCE_ENABLED.prop_type)
     self._is_checkpoints_enabled = config_handler.get_config_property(
         ModelSerializerProperty.MODEL_CHECKPOINTS_ENABLED,
         ModelSerializerProperty.MODEL_CHECKPOINTS_ENABLED.prop_type)
Esempio n. 9
0
 def __init__(self):
     """
     Default constructor.
     """
     self._log = logger.get_logger(self.__class__.__name__)
     config_handler = KatherineApplication.get_application_config()
     self.enabled_metrics = config_handler.get_config_property(
         TensorBoardConfigurationProperty.ENABLED_NETWORK_METRICS,
         TensorBoardConfigurationProperty.ENABLED_NETWORK_METRICS.prop_type)
     self.is_profiler_enabled = config_handler.get_config_property(
         TensorBoardConfigurationProperty.GPU_PROFILER_ENABLED,
         TensorBoardConfigurationProperty.GPU_PROFILER_ENABLED.prop_type)
     self.work_directory = fileio.build_metrics_work_directory(WORKING_DIRECTORY_PREFIX)
     self.initialized = False
Esempio n. 10
0
def build_global_work_directory() -> str:
    """
    Helper function for building the application's global working directory.

    base_work_directory/game/agent/run_tag

    :returns
        the global work directory path (relative path)
    """
    base_work_directory = KatherineApplication.get_application_config(
    ).get_config_property(KatConfigurationProperty.WORK_DIRECTORY,
                          KatConfigurationProperty.WORK_DIRECTORY.prop_type)
    agent_name = KatherineApplication.get_application_config(
    ).get_config_property(KatConfigurationProperty.AGENT_CLASS,
                          KatConfigurationProperty.AGENT_CLASS.prop_type)
    game_name = KatherineApplication.get_application_config(
    ).get_config_property(KatConfigurationProperty.GAME_CLASS,
                          KatConfigurationProperty.GAME_CLASS.prop_type)
    run_tag = KatherineApplication.get_application_config(
    ).get_config_property(KatConfigurationProperty.RUN_TAG,
                          KatConfigurationProperty.RUN_TAG.prop_type)
    agent_name = agent_name[agent_name.rindex('.') + 1:]
    game_name = game_name[game_name.rindex('.') + 1:]
    return os.path.join(base_work_directory, game_name, agent_name, run_tag)
Esempio n. 11
0
    def _build_network(self) -> INetwork:
        """
        Helper function for building the network.

        :returns
            an initialized `INetwork` instance, based on the current configuration
        """
        self._build_memory_access()
        network = KatherineApplication.get_application_factory().build_network(
        )
        network.init(
            replay_memory_access=self._memory_access,
            input_descriptor=self._network_input_spec,
            output_descriptor=self._network_output_spec,
            is_distribution_enabled=self._distributed_learning_enabled)
        return network
Esempio n. 12
0
    def init(self, observation_space_desc: Collection[ITensorDescriptor],
             action_space_descriptor: ITensorDescriptor) -> None:
        """
        Object initialization.

        #see: IAgent.init(observation_space_desc: Collection[ITensorDescriptor],
                          action_space_desc: ITensorDescriptor)
        """
        super(RandomChoiceAgent, self).init(observation_space_desc,
                                            action_space_descriptor)
        self._network_input_spec = TensorDescriptor(
            self._input_observation_name, self._input_observation_dtype,
            self._frame_buffer_output_shape, self._input_observation_type)
        self._network_output_spec = TensorDescriptor(
            "network_output", self._input_observation_dtype,
            self._action_space_desc.get_tensor_shape(), NetworkInputType.NONE)
        self._network = KatherineApplication.get_application_factory(
        ).build_network()
        self._network.init(output_descriptor=self._network_output_spec,
                           input_descriptor=self._network_input_spec)
        self._replay_memory = self._build_replay_memory()
Esempio n. 13
0
    def _build_replay_memory(self) -> IReplayMemory:
        """
        Helper function for building the replay memory.

        :returns
            an initialized `IReplayMemory` instance, based on the current configuration
        """
        memory_max_size = self._config_handler.get_config_property(
            AgentConfigurationProperty.MEMORY_MAX_SIZE,
            AgentConfigurationProperty.MEMORY_MAX_SIZE.prop_type)
        memory_tensor_spec = \
            (TensorDescriptor('s1_states',
                              self._input_observation_dtype,
                              (memory_max_size, *self._frame_buffer_output_shape)),
             TensorDescriptor('action_ids', self._action_space_desc.get_data_type(), (memory_max_size,)),
             TensorDescriptor('s2_states',
                              self._input_observation_dtype,
                              (memory_max_size, *self._frame_buffer_output_shape)),
             TensorDescriptor('rewards', np.float32, (memory_max_size, )),
             TensorDescriptor('terminals', np.bool, (memory_max_size, )))
        memory = KatherineApplication.get_application_factory().build_memory()
        memory.init(memory_tensor_spec)
        return memory
Esempio n. 14
0
 def __init__(self):
     """
     Default constructor.
     """
     self._config_handler = KatherineApplication.get_application_config()