def __init__( self, option_map, name='eval', stats=True, verbose=False, actor_name="actor"): """Initialization for Evaluator.""" # print("\u001b[31;1m|py|\u001b[0m\u001b[37m", "Evaluator::", inspect.currentframe().f_code.co_name) # print("\u001b[31;1m", os.path.dirname(os.path.abspath(__file__)), " - ", os.path.basename(__file__), "\u001b[0m") import_options(self, option_map, self.get_option_spec(name)) if stats: self.stats = Stats(option_map, name) else: self.stats = None if self.stats is not None and not self.stats.is_valid(): self.stats = None self.name = name self.actor_name = actor_name # verbose = option_map.get("verbose") self.verbose = verbose self.keys_in_reply = set(self.options.keys_in_reply) self.logger = logging.getIndexedLogger( '\u001b[31;1m|py|\u001b[0mrlpytorch.trainer.Evaluator-', '') print("name : ", name) print("actor_name : ", actor_name)
def __init__(self, option_map, model_class, model_idx=None, logger=None): """Initialize ModelLoader. Loading will fail if extra keys are not put in ``omit_keys`` Args: model_class(class): class name of the model model_idx(int): index of the model to be loaded. There may be multiple models in an `ModelInterface` to load. """ import_options( self, option_map, self.get_option_spec(model_class, model_idx)) if logger is not None: self.logger = logger else: self.logger = _logger_factory.makeLogger( 'rlpytorch.model_loader.ModelLoader-', f'-model_index{model_idx}') self.model_class = model_class self.model_idx = model_idx self._on_get_args = lambda *args, **kwargs: None option_spec = self.get_option_spec(model_class, model_idx) option_names = set(option_spec.getOptionNames()) model_option_spec = model_class.get_option_spec() model_option_names = set(model_option_spec.getOptionNames()) self.option_map_for_model = PyOptionMap(model_option_spec) # Here, the names in option_names are still possibly suffixed with # the model_idx. If so, we need to remove this suffix. model_options_to_load = {} for option_name in option_names: value = getattr(self.options, option_name) if model_idx is not None and option_name.endswith(str(model_idx)): # This is the name without the model_idx suffix orig_option_name = option_name[:-len(str(model_idx))] setattr(self.options, orig_option_name, value) delattr(self.options, option_name) if orig_option_name in model_option_names: model_options_to_load[orig_option_name] = value elif option_name in model_option_names: model_options_to_load[option_name] = value if model_options_to_load: self.option_map_for_model.loadOptionDict( model_options_to_load)
def __init__(self, option_map, stats_name=''): """Initialization for Stats.""" import_options(self, option_map, self.get_option_spec(stats_name)) self.name = stats_name + "_stats" self.collector = None self.stats_name = getattr(self.options, self.name) if self.stats_name == "rewards": self.collector = RewardCount() elif self.stats_name == "winrate": self.collector = WinRate() else: self.collector = None print("Stats: Name " + str(self.stats_name) + " is not known!")
def __init__(self, option_map, name='eval', stats=True, verbose=False, actor_name="actor"): """Initialization for Evaluator.""" import_options(self, option_map, self.get_option_spec(name)) if stats: self.stats = Stats(option_map, name) else: self.stats = None if self.stats is not None and not self.stats.is_valid(): self.stats = None self.name = name self.actor_name = actor_name self.verbose = verbose self.keys_in_reply = set(self.options.keys_in_reply)
def __init__( self, option_map, name='eval', stats=True, verbose=False, actor_name="actor"): """Initialization for Evaluator.""" import_options(self, option_map, self.get_option_spec(name)) if stats: self.stats = Stats(option_map, name) else: self.stats = None if self.stats is not None and not self.stats.is_valid(): self.stats = None self.name = name self.actor_name = actor_name self.verbose = verbose self.keys_in_reply = set(self.options.keys_in_reply)