We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Misleading ValueError - Accuracy Metric Multilabel
## 🐛 Bug description


When using Accuracy.update() with both inputs having the second dimension 1, e.g. in my case `torch.Size([256,1])` the raised error message is misleading.

To reproduce 
```
from ignite.metrics import Accuracy
import torch
acc = Accuracy(is_multilabel=True)
acc.update((torch.zeros((256,1)), torch.zeros((256,1))))
```
`ValueError: y and y_pred must have same shape of (batch_size, num_categories, ...).`

In this case the y and y_pred do have the same shape but the issue is that it's not an accepted multilabel input (the `and y.shape[1] != 1` in the following code block from `_check_shape` in `_BaseClassification`). This should be indicated in the error message (or the if statement changed).

What is the argument to not allow a `y.shape[1]` of 1?

```
if self._is_multilabel and not (y.shape == y_pred.shape and y.ndimension() > 1 and y.shape[1] != 1):
            raise ValueError("y and y_pred must have same shape of (batch_size, num_categories, ...).")
```


## Environment

 - PyTorch Version (e.g., 1.4): 
 - Ignite Version (e.g., 0.3.0): 0.3.0
 - OS (e.g., Linux): Linux
 - How you installed Ignite (`conda`, `pip`, source): conda
 - Python version:
 - Any other relevant information:


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ignite/metrics/accuracy.py`
Content:
```
1 from typing import Callable, Optional, Sequence, Union
2 
3 import torch
4 
5 from ignite.exceptions import NotComputableError
6 from ignite.metrics.metric import Metric, reinit__is_reduced, sync_all_reduce
7 
8 __all__ = ["Accuracy"]
9 
10 
11 class _BaseClassification(Metric):
12     def __init__(
13         self,
14         output_transform: Callable = lambda x: x,
15         is_multilabel: bool = False,
16         device: Optional[Union[str, torch.device]] = None,
17     ):
18         self._is_multilabel = is_multilabel
19         self._type = None
20         self._num_classes = None
21         super(_BaseClassification, self).__init__(output_transform=output_transform, device=device)
22 
23     def reset(self) -> None:
24         self._type = None
25         self._num_classes = None
26 
27     def _check_shape(self, output: Sequence[torch.Tensor]) -> None:
28         y_pred, y = output
29 
30         if not (y.ndimension() == y_pred.ndimension() or y.ndimension() + 1 == y_pred.ndimension()):
31             raise ValueError(
32                 "y must have shape of (batch_size, ...) and y_pred must have "
33                 "shape of (batch_size, num_categories, ...) or (batch_size, ...), "
34                 "but given {} vs {}.".format(y.shape, y_pred.shape)
35             )
36 
37         y_shape = y.shape
38         y_pred_shape = y_pred.shape
39 
40         if y.ndimension() + 1 == y_pred.ndimension():
41             y_pred_shape = (y_pred_shape[0],) + y_pred_shape[2:]
42 
43         if not (y_shape == y_pred_shape):
44             raise ValueError("y and y_pred must have compatible shapes.")
45 
46         if self._is_multilabel and not (y.shape == y_pred.shape and y.ndimension() > 1 and y.shape[1] != 1):
47             raise ValueError("y and y_pred must have same shape of (batch_size, num_categories, ...).")
48 
49     def _check_binary_multilabel_cases(self, output: Sequence[torch.Tensor]) -> None:
50         y_pred, y = output
51 
52         if not torch.equal(y, y ** 2):
53             raise ValueError("For binary cases, y must be comprised of 0's and 1's.")
54 
55         if not torch.equal(y_pred, y_pred ** 2):
56             raise ValueError("For binary cases, y_pred must be comprised of 0's and 1's.")
57 
58     def _check_type(self, output: Sequence[torch.Tensor]) -> None:
59         y_pred, y = output
60 
61         if y.ndimension() + 1 == y_pred.ndimension():
62             num_classes = y_pred.shape[1]
63             if num_classes == 1:
64                 update_type = "binary"
65                 self._check_binary_multilabel_cases((y_pred, y))
66             else:
67                 update_type = "multiclass"
68         elif y.ndimension() == y_pred.ndimension():
69             self._check_binary_multilabel_cases((y_pred, y))
70 
71             if self._is_multilabel:
72                 update_type = "multilabel"
73                 num_classes = y_pred.shape[1]
74             else:
75                 update_type = "binary"
76                 num_classes = 1
77         else:
78             raise RuntimeError(
79                 "Invalid shapes of y (shape={}) and y_pred (shape={}), check documentation."
80                 " for expected shapes of y and y_pred.".format(y.shape, y_pred.shape)
81             )
82         if self._type is None:
83             self._type = update_type
84             self._num_classes = num_classes
85         else:
86             if self._type != update_type:
87                 raise RuntimeError("Input data type has changed from {} to {}.".format(self._type, update_type))
88             if self._num_classes != num_classes:
89                 raise ValueError(
90                     "Input data number of classes has changed from {} to {}".format(self._num_classes, num_classes)
91                 )
92 
93 
94 class Accuracy(_BaseClassification):
95     """
96     Calculates the accuracy for binary, multiclass and multilabel data.
97 
98     - `update` must receive output of the form `(y_pred, y)` or `{'y_pred': y_pred, 'y': y}`.
99     - `y_pred` must be in the following shape (batch_size, num_categories, ...) or (batch_size, ...).
100     - `y` must be in the following shape (batch_size, ...).
101     - `y` and `y_pred` must be in the following shape of (batch_size, num_categories, ...) for multilabel cases.
102 
103     In binary and multilabel cases, the elements of `y` and `y_pred` should have 0 or 1 values. Thresholding of
104     predictions can be done as below:
105 
106     .. code-block:: python
107 
108         def thresholded_output_transform(output):
109             y_pred, y = output
110             y_pred = torch.round(y_pred)
111             return y_pred, y
112 
113         binary_accuracy = Accuracy(thresholded_output_transform)
114 
115 
116     Args:
117         output_transform (callable, optional): a callable that is used to transform the
118             :class:`~ignite.engine.Engine`'s `process_function`'s output into the
119             form expected by the metric. This can be useful if, for example, you have a multi-output model and
120             you want to compute the metric with respect to one of the outputs.
121         is_multilabel (bool, optional): flag to use in multilabel case. By default, False.
122         device (str of torch.device, optional): unused argument.
123 
124     """
125 
126     def __init__(
127         self,
128         output_transform: Callable = lambda x: x,
129         is_multilabel: bool = False,
130         device: Optional[Union[str, torch.device]] = None,
131     ):
132         self._num_correct = None
133         self._num_examples = None
134         super(Accuracy, self).__init__(output_transform=output_transform, is_multilabel=is_multilabel, device=device)
135 
136     @reinit__is_reduced
137     def reset(self) -> None:
138         self._num_correct = 0
139         self._num_examples = 0
140         super(Accuracy, self).reset()
141 
142     @reinit__is_reduced
143     def update(self, output: Sequence[torch.Tensor]) -> None:
144         y_pred, y = output
145         self._check_shape((y_pred, y))
146         self._check_type((y_pred, y))
147 
148         if self._type == "binary":
149             correct = torch.eq(y_pred.view(-1).to(y), y.view(-1))
150         elif self._type == "multiclass":
151             indices = torch.argmax(y_pred, dim=1)
152             correct = torch.eq(indices, y).view(-1)
153         elif self._type == "multilabel":
154             # if y, y_pred shape is (N, C, ...) -> (N x ..., C)
155             num_classes = y_pred.size(1)
156             last_dim = y_pred.ndimension()
157             y_pred = torch.transpose(y_pred, 1, last_dim - 1).reshape(-1, num_classes)
158             y = torch.transpose(y, 1, last_dim - 1).reshape(-1, num_classes)
159             correct = torch.all(y == y_pred.type_as(y), dim=-1)
160 
161         self._num_correct += torch.sum(correct).item()
162         self._num_examples += correct.shape[0]
163 
164     @sync_all_reduce("_num_examples", "_num_correct")
165     def compute(self) -> torch.Tensor:
166         if self._num_examples == 0:
167             raise NotComputableError("Accuracy must have at least one example before it can be computed.")
168         return self._num_correct / self._num_examples
169
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/ignite/metrics/accuracy.py b/ignite/metrics/accuracy.py
--- a/ignite/metrics/accuracy.py
+++ b/ignite/metrics/accuracy.py
@@ -43,8 +43,10 @@
         if not (y_shape == y_pred_shape):
             raise ValueError("y and y_pred must have compatible shapes.")
 
-        if self._is_multilabel and not (y.shape == y_pred.shape and y.ndimension() > 1 and y.shape[1] != 1):
-            raise ValueError("y and y_pred must have same shape of (batch_size, num_categories, ...).")
+        if self._is_multilabel and not (y.shape == y_pred.shape and y.ndimension() > 1 and y.shape[1] > 1):
+            raise ValueError(
+                "y and y_pred must have same shape of (batch_size, num_categories, ...) and num_categories > 1."
+            )
 
     def _check_binary_multilabel_cases(self, output: Sequence[torch.Tensor]) -> None:
         y_pred, y = output
@@ -98,7 +100,8 @@
     - `update` must receive output of the form `(y_pred, y)` or `{'y_pred': y_pred, 'y': y}`.
     - `y_pred` must be in the following shape (batch_size, num_categories, ...) or (batch_size, ...).
     - `y` must be in the following shape (batch_size, ...).
-    - `y` and `y_pred` must be in the following shape of (batch_size, num_categories, ...) for multilabel cases.
+    - `y` and `y_pred` must be in the following shape of (batch_size, num_categories, ...) and
+      num_categories must be greater than 1 for multilabel cases.
 
     In binary and multilabel cases, the elements of `y` and `y_pred` should have 0 or 1 values. Thresholding of
     predictions can be done as below:

{"golden_diff": "diff --git a/ignite/metrics/accuracy.py b/ignite/metrics/accuracy.py\n--- a/ignite/metrics/accuracy.py\n+++ b/ignite/metrics/accuracy.py\n@@ -43,8 +43,10 @@\n         if not (y_shape == y_pred_shape):\n             raise ValueError(\"y and y_pred must have compatible shapes.\")\n \n-        if self._is_multilabel and not (y.shape == y_pred.shape and y.ndimension() > 1 and y.shape[1] != 1):\n-            raise ValueError(\"y and y_pred must have same shape of (batch_size, num_categories, ...).\")\n+        if self._is_multilabel and not (y.shape == y_pred.shape and y.ndimension() > 1 and y.shape[1] > 1):\n+            raise ValueError(\n+                \"y and y_pred must have same shape of (batch_size, num_categories, ...) and num_categories > 1.\"\n+            )\n \n     def _check_binary_multilabel_cases(self, output: Sequence[torch.Tensor]) -> None:\n         y_pred, y = output\n@@ -98,7 +100,8 @@\n     - `update` must receive output of the form `(y_pred, y)` or `{'y_pred': y_pred, 'y': y}`.\n     - `y_pred` must be in the following shape (batch_size, num_categories, ...) or (batch_size, ...).\n     - `y` must be in the following shape (batch_size, ...).\n-    - `y` and `y_pred` must be in the following shape of (batch_size, num_categories, ...) for multilabel cases.\n+    - `y` and `y_pred` must be in the following shape of (batch_size, num_categories, ...) and\n+      num_categories must be greater than 1 for multilabel cases.\n \n     In binary and multilabel cases, the elements of `y` and `y_pred` should have 0 or 1 values. Thresholding of\n     predictions can be done as below:\n", "issue": "Misleading ValueError - Accuracy Metric Multilabel\n## \ud83d\udc1b Bug description\r\n\r\n\r\nWhen using Accuracy.update() with both inputs having the second dimension 1, e.g. in my case `torch.Size([256,1])` the raised error message is misleading.\r\n\r\nTo reproduce \r\n```\r\nfrom ignite.metrics import Accuracy\r\nimport torch\r\nacc = Accuracy(is_multilabel=True)\r\nacc.update((torch.zeros((256,1)), torch.zeros((256,1))))\r\n```\r\n`ValueError: y and y_pred must have same shape of (batch_size, num_categories, ...).`\r\n\r\nIn this case the y and y_pred do have the same shape but the issue is that it's not an accepted multilabel input (the `and y.shape[1] != 1` in the following code block from `_check_shape` in `_BaseClassification`). This should be indicated in the error message (or the if statement changed).\r\n\r\nWhat is the argument to not allow a `y.shape[1]` of 1?\r\n\r\n```\r\nif self._is_multilabel and not (y.shape == y_pred.shape and y.ndimension() > 1 and y.shape[1] != 1):\r\n            raise ValueError(\"y and y_pred must have same shape of (batch_size, num_categories, ...).\")\r\n```\r\n\r\n\r\n## Environment\r\n\r\n - PyTorch Version (e.g., 1.4): \r\n - Ignite Version (e.g., 0.3.0): 0.3.0\r\n - OS (e.g., Linux): Linux\r\n - How you installed Ignite (`conda`, `pip`, source): conda\r\n - Python version:\r\n - Any other relevant information:\r\n\n", "before_files": [{"content": "from typing import Callable, Optional, Sequence, Union\n\nimport torch\n\nfrom ignite.exceptions import NotComputableError\nfrom ignite.metrics.metric import Metric, reinit__is_reduced, sync_all_reduce\n\n__all__ = [\"Accuracy\"]\n\n\nclass _BaseClassification(Metric):\n    def __init__(\n        self,\n        output_transform: Callable = lambda x: x,\n        is_multilabel: bool = False,\n        device: Optional[Union[str, torch.device]] = None,\n    ):\n        self._is_multilabel = is_multilabel\n        self._type = None\n        self._num_classes = None\n        super(_BaseClassification, self).__init__(output_transform=output_transform, device=device)\n\n    def reset(self) -> None:\n        self._type = None\n        self._num_classes = None\n\n    def _check_shape(self, output: Sequence[torch.Tensor]) -> None:\n        y_pred, y = output\n\n        if not (y.ndimension() == y_pred.ndimension() or y.ndimension() + 1 == y_pred.ndimension()):\n            raise ValueError(\n                \"y must have shape of (batch_size, ...) and y_pred must have \"\n                \"shape of (batch_size, num_categories, ...) or (batch_size, ...), \"\n                \"but given {} vs {}.\".format(y.shape, y_pred.shape)\n            )\n\n        y_shape = y.shape\n        y_pred_shape = y_pred.shape\n\n        if y.ndimension() + 1 == y_pred.ndimension():\n            y_pred_shape = (y_pred_shape[0],) + y_pred_shape[2:]\n\n        if not (y_shape == y_pred_shape):\n            raise ValueError(\"y and y_pred must have compatible shapes.\")\n\n        if self._is_multilabel and not (y.shape == y_pred.shape and y.ndimension() > 1 and y.shape[1] != 1):\n            raise ValueError(\"y and y_pred must have same shape of (batch_size, num_categories, ...).\")\n\n    def _check_binary_multilabel_cases(self, output: Sequence[torch.Tensor]) -> None:\n        y_pred, y = output\n\n        if not torch.equal(y, y ** 2):\n            raise ValueError(\"For binary cases, y must be comprised of 0's and 1's.\")\n\n        if not torch.equal(y_pred, y_pred ** 2):\n            raise ValueError(\"For binary cases, y_pred must be comprised of 0's and 1's.\")\n\n    def _check_type(self, output: Sequence[torch.Tensor]) -> None:\n        y_pred, y = output\n\n        if y.ndimension() + 1 == y_pred.ndimension():\n            num_classes = y_pred.shape[1]\n            if num_classes == 1:\n                update_type = \"binary\"\n                self._check_binary_multilabel_cases((y_pred, y))\n            else:\n                update_type = \"multiclass\"\n        elif y.ndimension() == y_pred.ndimension():\n            self._check_binary_multilabel_cases((y_pred, y))\n\n            if self._is_multilabel:\n                update_type = \"multilabel\"\n                num_classes = y_pred.shape[1]\n            else:\n                update_type = \"binary\"\n                num_classes = 1\n        else:\n            raise RuntimeError(\n                \"Invalid shapes of y (shape={}) and y_pred (shape={}), check documentation.\"\n                \" for expected shapes of y and y_pred.\".format(y.shape, y_pred.shape)\n            )\n        if self._type is None:\n            self._type = update_type\n            self._num_classes = num_classes\n        else:\n            if self._type != update_type:\n                raise RuntimeError(\"Input data type has changed from {} to {}.\".format(self._type, update_type))\n            if self._num_classes != num_classes:\n                raise ValueError(\n                    \"Input data number of classes has changed from {} to {}\".format(self._num_classes, num_classes)\n                )\n\n\nclass Accuracy(_BaseClassification):\n    \"\"\"\n    Calculates the accuracy for binary, multiclass and multilabel data.\n\n    - `update` must receive output of the form `(y_pred, y)` or `{'y_pred': y_pred, 'y': y}`.\n    - `y_pred` must be in the following shape (batch_size, num_categories, ...) or (batch_size, ...).\n    - `y` must be in the following shape (batch_size, ...).\n    - `y` and `y_pred` must be in the following shape of (batch_size, num_categories, ...) for multilabel cases.\n\n    In binary and multilabel cases, the elements of `y` and `y_pred` should have 0 or 1 values. Thresholding of\n    predictions can be done as below:\n\n    .. code-block:: python\n\n        def thresholded_output_transform(output):\n            y_pred, y = output\n            y_pred = torch.round(y_pred)\n            return y_pred, y\n\n        binary_accuracy = Accuracy(thresholded_output_transform)\n\n\n    Args:\n        output_transform (callable, optional): a callable that is used to transform the\n            :class:`~ignite.engine.Engine`'s `process_function`'s output into the\n            form expected by the metric. This can be useful if, for example, you have a multi-output model and\n            you want to compute the metric with respect to one of the outputs.\n        is_multilabel (bool, optional): flag to use in multilabel case. By default, False.\n        device (str of torch.device, optional): unused argument.\n\n    \"\"\"\n\n    def __init__(\n        self,\n        output_transform: Callable = lambda x: x,\n        is_multilabel: bool = False,\n        device: Optional[Union[str, torch.device]] = None,\n    ):\n        self._num_correct = None\n        self._num_examples = None\n        super(Accuracy, self).__init__(output_transform=output_transform, is_multilabel=is_multilabel, device=device)\n\n    @reinit__is_reduced\n    def reset(self) -> None:\n        self._num_correct = 0\n        self._num_examples = 0\n        super(Accuracy, self).reset()\n\n    @reinit__is_reduced\n    def update(self, output: Sequence[torch.Tensor]) -> None:\n        y_pred, y = output\n        self._check_shape((y_pred, y))\n        self._check_type((y_pred, y))\n\n        if self._type == \"binary\":\n            correct = torch.eq(y_pred.view(-1).to(y), y.view(-1))\n        elif self._type == \"multiclass\":\n            indices = torch.argmax(y_pred, dim=1)\n            correct = torch.eq(indices, y).view(-1)\n        elif self._type == \"multilabel\":\n            # if y, y_pred shape is (N, C, ...) -> (N x ..., C)\n            num_classes = y_pred.size(1)\n            last_dim = y_pred.ndimension()\n            y_pred = torch.transpose(y_pred, 1, last_dim - 1).reshape(-1, num_classes)\n            y = torch.transpose(y, 1, last_dim - 1).reshape(-1, num_classes)\n            correct = torch.all(y == y_pred.type_as(y), dim=-1)\n\n        self._num_correct += torch.sum(correct).item()\n        self._num_examples += correct.shape[0]\n\n    @sync_all_reduce(\"_num_examples\", \"_num_correct\")\n    def compute(self) -> torch.Tensor:\n        if self._num_examples == 0:\n            raise NotComputableError(\"Accuracy must have at least one example before it can be computed.\")\n        return self._num_correct / self._num_examples\n", "path": "ignite/metrics/accuracy.py"}], "after_files": [{"content": "from typing import Callable, Optional, Sequence, Union\n\nimport torch\n\nfrom ignite.exceptions import NotComputableError\nfrom ignite.metrics.metric import Metric, reinit__is_reduced, sync_all_reduce\n\n__all__ = [\"Accuracy\"]\n\n\nclass _BaseClassification(Metric):\n    def __init__(\n        self,\n        output_transform: Callable = lambda x: x,\n        is_multilabel: bool = False,\n        device: Optional[Union[str, torch.device]] = None,\n    ):\n        self._is_multilabel = is_multilabel\n        self._type = None\n        self._num_classes = None\n        super(_BaseClassification, self).__init__(output_transform=output_transform, device=device)\n\n    def reset(self) -> None:\n        self._type = None\n        self._num_classes = None\n\n    def _check_shape(self, output: Sequence[torch.Tensor]) -> None:\n        y_pred, y = output\n\n        if not (y.ndimension() == y_pred.ndimension() or y.ndimension() + 1 == y_pred.ndimension()):\n            raise ValueError(\n                \"y must have shape of (batch_size, ...) and y_pred must have \"\n                \"shape of (batch_size, num_categories, ...) or (batch_size, ...), \"\n                \"but given {} vs {}.\".format(y.shape, y_pred.shape)\n            )\n\n        y_shape = y.shape\n        y_pred_shape = y_pred.shape\n\n        if y.ndimension() + 1 == y_pred.ndimension():\n            y_pred_shape = (y_pred_shape[0],) + y_pred_shape[2:]\n\n        if not (y_shape == y_pred_shape):\n            raise ValueError(\"y and y_pred must have compatible shapes.\")\n\n        if self._is_multilabel and not (y.shape == y_pred.shape and y.ndimension() > 1 and y.shape[1] > 1):\n            raise ValueError(\n                \"y and y_pred must have same shape of (batch_size, num_categories, ...) and num_categories > 1.\"\n            )\n\n    def _check_binary_multilabel_cases(self, output: Sequence[torch.Tensor]) -> None:\n        y_pred, y = output\n\n        if not torch.equal(y, y ** 2):\n            raise ValueError(\"For binary cases, y must be comprised of 0's and 1's.\")\n\n        if not torch.equal(y_pred, y_pred ** 2):\n            raise ValueError(\"For binary cases, y_pred must be comprised of 0's and 1's.\")\n\n    def _check_type(self, output: Sequence[torch.Tensor]) -> None:\n        y_pred, y = output\n\n        if y.ndimension() + 1 == y_pred.ndimension():\n            num_classes = y_pred.shape[1]\n            if num_classes == 1:\n                update_type = \"binary\"\n                self._check_binary_multilabel_cases((y_pred, y))\n            else:\n                update_type = \"multiclass\"\n        elif y.ndimension() == y_pred.ndimension():\n            self._check_binary_multilabel_cases((y_pred, y))\n\n            if self._is_multilabel:\n                update_type = \"multilabel\"\n                num_classes = y_pred.shape[1]\n            else:\n                update_type = \"binary\"\n                num_classes = 1\n        else:\n            raise RuntimeError(\n                \"Invalid shapes of y (shape={}) and y_pred (shape={}), check documentation.\"\n                \" for expected shapes of y and y_pred.\".format(y.shape, y_pred.shape)\n            )\n        if self._type is None:\n            self._type = update_type\n            self._num_classes = num_classes\n        else:\n            if self._type != update_type:\n                raise RuntimeError(\"Input data type has changed from {} to {}.\".format(self._type, update_type))\n            if self._num_classes != num_classes:\n                raise ValueError(\n                    \"Input data number of classes has changed from {} to {}\".format(self._num_classes, num_classes)\n                )\n\n\nclass Accuracy(_BaseClassification):\n    \"\"\"\n    Calculates the accuracy for binary, multiclass and multilabel data.\n\n    - `update` must receive output of the form `(y_pred, y)` or `{'y_pred': y_pred, 'y': y}`.\n    - `y_pred` must be in the following shape (batch_size, num_categories, ...) or (batch_size, ...).\n    - `y` must be in the following shape (batch_size, ...).\n    - `y` and `y_pred` must be in the following shape of (batch_size, num_categories, ...) and\n      num_categories must be greater than 1 for multilabel cases.\n\n    In binary and multilabel cases, the elements of `y` and `y_pred` should have 0 or 1 values. Thresholding of\n    predictions can be done as below:\n\n    .. code-block:: python\n\n        def thresholded_output_transform(output):\n            y_pred, y = output\n            y_pred = torch.round(y_pred)\n            return y_pred, y\n\n        binary_accuracy = Accuracy(thresholded_output_transform)\n\n\n    Args:\n        output_transform (callable, optional): a callable that is used to transform the\n            :class:`~ignite.engine.Engine`'s `process_function`'s output into the\n            form expected by the metric. This can be useful if, for example, you have a multi-output model and\n            you want to compute the metric with respect to one of the outputs.\n        is_multilabel (bool, optional): flag to use in multilabel case. By default, False.\n        device (str of torch.device, optional): unused argument.\n\n    \"\"\"\n\n    def __init__(\n        self,\n        output_transform: Callable = lambda x: x,\n        is_multilabel: bool = False,\n        device: Optional[Union[str, torch.device]] = None,\n    ):\n        self._num_correct = None\n        self._num_examples = None\n        super(Accuracy, self).__init__(output_transform=output_transform, is_multilabel=is_multilabel, device=device)\n\n    @reinit__is_reduced\n    def reset(self) -> None:\n        self._num_correct = 0\n        self._num_examples = 0\n        super(Accuracy, self).reset()\n\n    @reinit__is_reduced\n    def update(self, output: Sequence[torch.Tensor]) -> None:\n        y_pred, y = output\n        self._check_shape((y_pred, y))\n        self._check_type((y_pred, y))\n\n        if self._type == \"binary\":\n            correct = torch.eq(y_pred.view(-1).to(y), y.view(-1))\n        elif self._type == \"multiclass\":\n            indices = torch.argmax(y_pred, dim=1)\n            correct = torch.eq(indices, y).view(-1)\n        elif self._type == \"multilabel\":\n            # if y, y_pred shape is (N, C, ...) -> (N x ..., C)\n            num_classes = y_pred.size(1)\n            last_dim = y_pred.ndimension()\n            y_pred = torch.transpose(y_pred, 1, last_dim - 1).reshape(-1, num_classes)\n            y = torch.transpose(y, 1, last_dim - 1).reshape(-1, num_classes)\n            correct = torch.all(y == y_pred.type_as(y), dim=-1)\n\n        self._num_correct += torch.sum(correct).item()\n        self._num_examples += correct.shape[0]\n\n    @sync_all_reduce(\"_num_examples\", \"_num_correct\")\n    def compute(self) -> torch.Tensor:\n        if self._num_examples == 0:\n            raise NotComputableError(\"Accuracy must have at least one example before it can be computed.\")\n        return self._num_correct / self._num_examples\n", "path": "ignite/metrics/accuracy.py"}]}