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
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