Skip to content
Closed
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
25 changes: 25 additions & 0 deletions ignite/metrics/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,31 @@ def thresholded_output_transform(output):
device: specifies which device updates are accumulated on. Setting the metric's
device to be the same as your ``update`` arguments ensures the ``update`` method is non-blocking. By
default, CPU.

Examples:
To use with ``Engine`` and ``process_function``, simply attach the metric instance to the engine.
The output of the engine's ``process_function`` needs to be in the format of
``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y, ...}``. If not, ``output_tranform`` can be added
to the metric to transform the output into the form expected by the metric.

``y_pred`` and ``y`` should have the same shape.

.. testcode::

def process_function(engine, batch):
y_pred, y = batch
return y_pred, y
engine = Engine(process_function)
metric = Accuracy()
metric.attach(engine, 'accuracy')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could create a default evaluator as above and hide this part of code from the user ?

cc @ydcjeff

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel it would be good to have this part of the code so that it remains transparent.
Could you also explain the alternative that you are proposing?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a way to define a global context using this:

ignite/docs/source/conf.py

Lines 344 to 353 in 74dabca

doctest_global_setup = """
import torch
from torch import nn, optim
from ignite.engine import *
from ignite.handlers import *
from ignite.metrics import *
from ignite.utils import *
manual_seed(666)

preds = torch.Tensor([[1,0,0,1]])
target = torch.Tensor([[1,0,0,0]])
state = engine.run([[preds, target]])
print(state.metrics['accuracy'])

.. testoutput::

0.75
"""

def __init__(
Expand Down