Ejemplo n.º 1
0
    def __init__(self,
                 args: Namespace,
                 index=None,
                 trainer: SimpleTrainer = None,
                 load_path: str = None,
                 method: AbstractMethod = None,
                 **kwargs):
        super().__init__(args, index=index, **kwargs)

        # ensure all required parameters are available
        if (method is None) and (trainer is not None):
            method = trainer.get_method()
        reg_kwargs = Register.get_my_kwargs(self.__class__)
        if reg_kwargs.get('requires_trainer'):
            assert isinstance(
                trainer,
                SimpleTrainer), "%s needs a trainer" % self.__class__.__name__
            assert isinstance(
                load_path, str
            ), "%s needs a path to load weights" % self.__class__.__name__
        if reg_kwargs.get('requires_method'):
            assert isinstance(
                method,
                AbstractMethod), "%s needs a method" % self.__class__.__name__
            assert isinstance(method.get_network(), SearchUninasNetwork),\
                "%s's method must use a search network" % self.__class__.__name__

        self.method = method
        self.trainer = trainer
        self.load_path = load_path
Ejemplo n.º 2
0
 def meta_args_to_add(cls) -> [MetaArgument]:
     """
     list meta arguments to add to argparse for when this class is chosen,
     classes specified in meta arguments may have their own respective arguments
     """
     kwargs = Register.get_my_kwargs(cls)
     aug_sets = Register.augmentation_sets.filter_match_all(on_images=kwargs.get('images'))
     return super().meta_args_to_add() + [
         MetaArgument('cls_augmentations', aug_sets, help_name='data augmentation'),
     ]
Ejemplo n.º 3
0
    def meta_args_to_add(cls) -> [MetaArgument]:
        """
        list meta arguments to add to argparse for when this class is chosen,
        classes specified in meta arguments may have their own respective arguments
        """
        kwargs = Register.get_my_kwargs(cls)
        methods = Register.methods.filter_match_all(search=kwargs.get('search'))

        return super().meta_args_to_add() + [
            MetaArgument('cls_device', Register.devices_managers, help_name='device manager', allowed_num=1),
            MetaArgument('cls_trainer', Register.trainers, help_name='trainer', allowed_num=1),
            MetaArgument('cls_method', methods, help_name='method', allowed_num=1),
        ]
Ejemplo n.º 4
0
    def meta_args_to_add(cls, num_optimizers=1, search=True) -> [MetaArgument]:
        """
        list meta arguments to add to argparse for when this class is chosen,
        classes specified in meta arguments may have their own respective arguments
        """
        kwargs = Register.get_my_kwargs(cls)
        metrics = Register.metrics.filter_match_all(
            distill=kwargs.get('distill'))
        criteria = Register.criteria.filter_match_all(
            distill=kwargs.get('distill'))
        networks = Register.networks.filter_match_all(search=search)

        return super().meta_args_to_add() + [
            MetaArgument('cls_data',
                         Register.data_sets,
                         help_name='data set',
                         allowed_num=1),
            MetaArgument(
                'cls_network', networks, help_name='network', allowed_num=1),
            MetaArgument('cls_criterion',
                         criteria,
                         help_name='criterion',
                         allowed_num=1),
            MetaArgument('cls_metrics', metrics, help_name='training metric'),
            MetaArgument('cls_initializers',
                         Register.initializers,
                         help_name='weight initializer'),
            MetaArgument('cls_regularizers',
                         Register.regularizers,
                         help_name='regularizer'),
            MetaArgument('cls_optimizers',
                         Register.optimizers,
                         help_name='optimizer',
                         allow_duplicates=True,
                         allowed_num=num_optimizers,
                         use_index=True),
            MetaArgument('cls_schedulers',
                         Register.schedulers,
                         help_name='scheduler',
                         allow_duplicates=True,
                         allowed_num=(0, num_optimizers),
                         use_index=True),
        ]
Ejemplo n.º 5
0
 def num_classes(cls) -> int:
     kwargs = Register.get_my_kwargs(cls)
     assert kwargs.get('classification', False)
     return cls.label_shape.num_features()
Ejemplo n.º 6
0
 def is_classification(cls) -> bool:
     kwargs = Register.get_my_kwargs(cls)
     return kwargs.get('classification', False)
Ejemplo n.º 7
0
 def is_on_images(cls) -> bool:
     kwargs = Register.get_my_kwargs(cls)
     return kwargs.get('images', False)
Ejemplo n.º 8
0
 def is_single_path(cls) -> bool:
     return Register.get_my_kwargs(cls).get('single_path', False)
Ejemplo n.º 9
0
 def is_external(self) -> bool:
     return Register.get_my_kwargs(self.__class__).get('external')
Ejemplo n.º 10
0
 def is_tabular(self) -> bool:
     return Register.get_my_kwargs(self.__class__).get('tabular', False)