Skip to content

Loss metric to use required_output_keys #1415

@vfdev-5

Description

@vfdev-5

🚀 Feature

Currently, if we have custom metrics that require data other then y_pred and y, we suggest to do the following:

metrics = {
    "Accuracy": Accuracy(),
    "Loss": Loss(criterion, output_transform=lambda out_dict: (out_dict["y_pred"], out_dict["y"])),
    "CustomMetric": CustomMetric()
}

evaluator = create_supervised_evaluator(
    model, 
    metrics=metrics, 
    output_transform=lambda x, y, y_pred: {"x": x, "y": y, "y_pred": y_pred}
)

where CustomMetric is defined as

class CustomMetric(Metric):

    required_output_keys = ("y_pred", "y", "x")

The idea is to extend this for Loss metric to support required_output_keys. The main issue with Loss now is with (prediction, target, kwargs) optional input, where kwargs is a dict for extra args for criterion function.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions