Beispiel #1
0
 def build_loggers(cls, args, controller=None):
     args = to_namespace(args)
     loggers = {}
     for split in try_get_attr(args, f'{cls.prefix_name()}_splits', []):
         setattr(args, f'{cls.prefix_name()}_name', split)
         loggers[split] = cls.build(args, controller=controller)
     return loggers
Beispiel #2
0
 def build(cls, params, sub_cls=None, controller=None):
     params = to_namespace(params)
     writer_kwargs = load_func_kwargs(params, SummaryWriter.__init__,
                                      cls.prefix_name())
     init_kwargs = load_func_kwargs(params, cls.__init__, cls.prefix_name())
     init_kwargs.update({'writer_kwargs': writer_kwargs})
     module = cls(**init_kwargs)
     controller.register_module(module)
     return module
Beispiel #3
0
 def build(cls, params, sub_cls=None, controller=None):
     params = to_namespace(params)
     if cls.is_root_cls():
         sub_cls = cls.load_cls(
             getattr(params, f'{cls.prefix_name()}_cls', sub_cls))
         if sub_cls is not None:
             if cls is sub_cls and 'build' not in cls.__dict__:
                 return cls.default_build(params, controller=controller)
             return sub_cls.build(params, controller=controller)
         else:
             return cls.default_build(params, controller=controller)
     else:
         return cls.default_build(params, controller=controller)
Beispiel #4
0
 def parse(self):
     params_list = list()
     for module_type, group in self.groups.items():
         # print(f'Parsing group for module type {module_type}')
         params_list.append(group.parse())
     ret_params = {}
     for params in params_list:
         for param_name, param_value in vars(params).items():
             if param_name in ret_params and ret_params[
                     param_name] is not None:
                 continue
             if callable(param_value):
                 continue
             ret_params[param_name] = param_value
     self.params = to_namespace(ret_params)
Beispiel #5
0
    def build_modules(self):
        module_types = copy.deepcopy(self.module_types)
        params = None
        if 'parser' in module_types:
            module_types.remove('parser')
            parser = Parser(self.init_params, module_types)
            self.module_dicts['parser'] = parser
            params = parser.params
            parser.save()
        self.params = params or to_namespace(self.init_params)

        for module_type in module_types:
            # print(f'Building module {module_type}')
            module_root_cls = PtBase.load_cls(module_type)
            module = module_root_cls.build(self.params, controller=self)
            if module_type != 'dataset':
                self.register_module(module)
            else:
                self.module_dicts['dataset'] = module  # loaders