def _create_sub_keys( spec: config.MetricsSpec ) -> Dict[Optional[metric_types.AggregationType], List[Optional[metric_types.SubKey]]]: """Creates sub keys per aggregation type.""" result = {} if spec.HasField('binarize'): sub_keys = [] if spec.binarize.class_ids.values: for v in spec.binarize.class_ids.values: sub_keys.append(metric_types.SubKey(class_id=v)) if spec.binarize.k_list.values: for v in spec.binarize.k_list.values: sub_keys.append(metric_types.SubKey(k=v)) if spec.binarize.top_k_list.values: for v in spec.binarize.top_k_list.values: sub_keys.append(metric_types.SubKey(top_k=v)) if sub_keys: result[None] = sub_keys if spec.HasField('aggregate'): sub_keys = [] for top_k in spec.aggregate.top_k_list.values: sub_keys.append(metric_types.SubKey(top_k=top_k)) if not sub_keys: sub_keys = [None] result[_aggregation_type(spec)] = sub_keys return result if result else {None: [None]}
def _create_sub_keys( spec: config.MetricsSpec) -> Optional[List[metric_types.SubKey]]: """Creates subkeys associated with spec.""" sub_keys = None if spec.HasField('binarize'): sub_keys = [] if spec.binarize.class_ids.values: for v in spec.binarize.class_ids.values: sub_keys.append(metric_types.SubKey(class_id=v)) if spec.binarize.k_list.values: for v in spec.binarize.k_list.values: sub_keys.append(metric_types.SubKey(k=v)) if spec.binarize.top_k_list.values: for v in spec.binarize.top_k_list.values: sub_keys.append(metric_types.SubKey(top_k=v)) if spec.aggregate.micro_average: # Micro averaging is performed by flattening the labels and predictions # and treating them as independent pairs. This is done by default by most # metrics whenever binarization is not used. If micro-averaging and # binarization are used, then we need to create an empty subkey to ensure # the overall aggregate key is still computed. Note that the class_weights # should always be passed to all metric calculations to ensure they are # taken into account when flattening is required. sub_keys.append(None) return sub_keys # pytype: disable=bad-return-type
def _create_sub_keys( spec: config.MetricsSpec) -> Optional[List[metric_types.SubKey]]: """Creates subkeys associated with spec.""" sub_keys = None if spec.HasField('binarize'): sub_keys = [] if spec.binarize.class_ids: for v in spec.binarize.class_ids: sub_keys.append(metric_types.SubKey(class_id=v)) if spec.binarize.k_list: for v in spec.binarize.k_list: sub_keys.append(metric_types.SubKey(k=v)) if spec.binarize.top_k_list: for v in spec.binarize.top_k_list: sub_keys.append(metric_types.SubKey(top_k=v)) return sub_keys