-
-
Notifications
You must be signed in to change notification settings - Fork 654
ENH: Updated Loss metric to use required_output_keys #2027
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
Conversation
Following is the demo code to check the validity of the above change: import torch
import torch.nn as nn
from torch.nn.functional import nll_loss
from ignite.metrics import Accuracy, Loss
from ignite.engine import create_supervised_evaluator
model = nn.Linear(10, 3)
metrics = {
"Accuracy": Accuracy(),
"Loss": Loss(nll_loss)
}
# global criterion kwargs
criterion_kwargs = {"reduction": 'sum'}
# criterion_kwargs = {}
evaluator = create_supervised_evaluator(
model,
metrics=metrics,
output_transform=lambda x, y, y_pred: {
"x": x, "y": y, "y_pred": y_pred, "criterion_kwargs": criterion_kwargs}
)
data = [
(torch.rand(4, 10), torch.randint(0, 3, size=(4, ))),
(torch.rand(4, 10), torch.randint(0, 3, size=(4, ))),
(torch.rand(4, 10), torch.randint(0, 3, size=(4, )))
]
res = evaluator.run(data) As the |
@01-vyom thanks for the draft PR !
Instead of ignite/tests/ignite/metrics/test_metric.py Lines 28 to 29 in 692487c
Please let me know if need more explanations. We can also add your above demo example as an integration test to https://github.com/pytorch/ignite/blob/master/tests/ignite/metrics/test_loss.py |
Ok, I will add a ignite/tests/ignite/metrics/test_metric.py Line 894 in 692487c
|
…utput_keys support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @01-vyom !
Fixes #1415
Description:
Similar to
Metric
,Loss
metric now supportsrequired_output_keys
.Check list: