def __init__(self, input_shape, metrics, compute=True, timing=False, device='cuda', mixed_only=False, keep_stats=True, traversal_type='tape_nodes'): super().__init__() if rasp is None: raise ValueError('package RASP is not found') self.metrics = build(metrics) self.eval_compute = compute self.eval_timing = timing self.input_shape = input_shape self.device = device self.mixed_only = mixed_only self.keep_stats = keep_stats if traversal_type == 'tape_leaves': self.traverse = self._traverse_tape_leaves elif traversal_type == 'tape_nodes': self.traverse = self._traverse_tape_nodes else: raise ValueError('invalid traversal type') self.excluded = set()
def __init__(self, metrics, head=None, save_path=None): super().__init__() self.head = head self.metrics = build(metrics) self.record = dict() self.save_path = save_path self.save_file = None if save_path is not None: self.save_file = open(save_path, 'w')
def __init__(self, metrics_conf): super().__init__() self.metrics = {k: build(conf) for k, conf in metrics_conf.items()} self.base = { k: conf.get('base', 1) for k, conf in metrics_conf.items() } self.weight = { k: conf.get('weight', 1) for k, conf in metrics_conf.items() }
def __init__(self, metrics, head=None, export_dir=None, verbose=False): super().__init__() self.metrics = build(metrics) if head is None: head = 'name' self.head = head if export_dir is None: export_dir = tempfile.gettempdir() os.makedirs(export_dir, exist_ok=True) self.export_dir = export_dir self.verbose = verbose self.exported = {}
def build_metrics_all(mt_configs, estim=None): """Build Metrics from configs.""" metrics = {} if mt_configs is None: mt_configs = {} MetricsBase.set_estim(estim) if not isinstance(mt_configs, dict): mt_configs = {'default': mt_configs} for mt_name, mt_conf in mt_configs.items(): mt = build(mt_conf) metrics[mt_name] = mt MetricsBase.set_estim(None) return metrics
def __init__(self, input_shape, metrics, compute=True, timing=False, device=None): super().__init__() if rasp is None: raise ValueError('package RASP is not found') self.metrics = build(metrics) self.eval_compute = compute self.eval_timing = timing self.input_shape = input_shape self.device = device
def __init__(self, metrics_conf): super().__init__() self.metrics = {k: build(conf) for k, conf in metrics_conf.items()} self.base = { k: conf.get('base', 1) for k, conf in metrics_conf.items() } self.alpha = { k: conf.get('alpha', 1) for k, conf in metrics_conf.items() } self.beta = { k: conf.get('beta', 1) for k, conf in metrics_conf.items() }
def __init__(self, metrics): super().__init__() self.metrics = build(metrics)
def __init__(self, metrics_conf): super().__init__() self.metrics = {k: build(conf) for k, conf in metrics_conf.items()}