[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple output models #223

Merged
merged 3 commits into from
Dec 1, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 36 additions & 25 deletions model_card_toolkit/utils/tfx_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,31 +442,42 @@ def _parse_array_value(array: Dict[str, Any]) -> str:
logging.warning('Received unexpected array %s', str(array))
return ''

for slice_repr, metrics_for_slice in (
eval_result.get_metrics_for_all_slices().items()):
# Parse the slice name
if not isinstance(slice_repr, tuple):
raise ValueError(
f'Expected EvalResult slices to be tuples; found {type(slice_repr)}')
slice_name = '_X_'.join(f'{a}_{b}' for a, b in slice_repr)
for metric_name, metric_value in metrics_for_slice.items():
# Parse the metric value
parsed_value = ''
if 'doubleValue' in metric_value:
parsed_value = metric_value['doubleValue']
elif 'boundedValue' in metric_value:
parsed_value = metric_value['boundedValue']['value']
elif 'arrayValue' in metric_value:
parsed_value = _parse_array_value(metric_value['arrayValue'])
else:
logging.warning(
'Expected doubleValue, boundedValue, or arrayValue; found %s',
metric_value.keys())
if parsed_value:
# Create the PerformanceMetric and append to the ModelCard
metric = model_card_module.PerformanceMetric(
type=metric_name, value=str(parsed_value), slice=slice_name)
model_card.quantitative_analysis.performance_metrics.append(metric)
# NB(gcasassaez): When multiple outputs are passed, each will be in it's own output_name key
codesue marked this conversation as resolved.
Show resolved Hide resolved
# If that's the case add each output_name + metric to the quantitative_analysis by namespacing by
# output_name.metric to distinguish them
output_names = set()
for slicing_metric in eval_result.slicing_metrics:
for output_name in slicing_metric[1]:
output_names.add(output_name)
for output_name in sorted(output_names):
for slice_repr, metrics_for_slice in (
eval_result.get_metrics_for_all_slices(output_name=output_name).items()):
# Parse the slice name
if not isinstance(slice_repr, tuple):
raise ValueError(
f'Expected EvalResult slices to be tuples; found {type(slice_repr)}')
slice_name = '_X_'.join(f'{a}_{b}' for a, b in slice_repr)
for metric_name, metric_value in metrics_for_slice.items():
# Parse the metric value
parsed_value = ''
if 'doubleValue' in metric_value:
parsed_value = metric_value['doubleValue']
elif 'boundedValue' in metric_value:
parsed_value = metric_value['boundedValue']['value']
elif 'arrayValue' in metric_value:
parsed_value = _parse_array_value(metric_value['arrayValue'])
else:
logging.warning(
'Expected doubleValue, boundedValue, or arrayValue; found %s',
metric_value.keys())
if parsed_value:
metric_type = metric_name
if output_name:
metric_type = f"{output_name}.{metric_name}"
# Create the PerformanceMetric and append to the ModelCard
metric = model_card_module.PerformanceMetric(
type=metric_type, value=str(parsed_value), slice=slice_name)
model_card.quantitative_analysis.performance_metrics.append(metric)


def filter_metrics(
Expand Down