We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
bug in recall and precision?
hi:
   It seems the  https://github.com/open-mmlab/mmclassification/blob/92438da12a9f8bf0390277be902dc96e6970b54d/mmcls/models/losses/eval_metrics.py#L55
and https://github.com/open-mmlab/mmclassification/blob/92438da12a9f8bf0390277be902dc96e6970b54d/mmcls/models/losses/eval_metrics.py#L37
get inversed?
@LXXXXR @ycxioooong

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mmcls/models/losses/eval_metrics.py`
Content:
```
1 import numpy as np
2 import torch
3 
4 
5 def calculate_confusion_matrix(pred, target):
6     if isinstance(pred, np.ndarray) and isinstance(target, np.ndarray):
7         pred = torch.from_numpy(pred)
8         target = torch.from_numpy(target)
9     elif not (isinstance(pred, torch.Tensor)
10               and isinstance(target, torch.Tensor)):
11         raise TypeError('pred and target should both be'
12                         'torch.Tensor or np.ndarray')
13     _, pred_label = pred.topk(1, dim=1)
14     num_classes = pred.size(1)
15     pred_label = pred_label.view(-1)
16     target_label = target.view(-1)
17     assert len(pred_label) == len(target_label)
18     confusion_matrix = torch.zeros(num_classes, num_classes)
19     with torch.no_grad():
20         confusion_matrix[target_label.long(), pred_label.long()] += 1
21     return confusion_matrix
22 
23 
24 def precision(pred, target):
25     """Calculate macro-averaged precision according to the prediction and target
26 
27     Args:
28         pred (torch.Tensor | np.array): The model prediction.
29         target (torch.Tensor | np.array): The target of each prediction.
30 
31     Returns:
32         float: The function will return a single float as precision.
33     """
34     confusion_matrix = calculate_confusion_matrix(pred, target)
35     with torch.no_grad():
36         res = confusion_matrix.diag() / torch.clamp(
37             confusion_matrix.sum(1), min=1)
38         res = res.mean().item() * 100
39     return res
40 
41 
42 def recall(pred, target):
43     """Calculate macro-averaged recall according to the prediction and target
44 
45     Args:
46         pred (torch.Tensor | np.array): The model prediction.
47         target (torch.Tensor | np.array): The target of each prediction.
48 
49     Returns:
50         float: The function will return a single float as recall.
51     """
52     confusion_matrix = calculate_confusion_matrix(pred, target)
53     with torch.no_grad():
54         res = confusion_matrix.diag() / torch.clamp(
55             confusion_matrix.sum(0), min=1)
56         res = res.mean().item() * 100
57     return res
58 
59 
60 def f1_score(pred, target):
61     """Calculate macro-averaged F1 score according to the prediction and target
62 
63     Args:
64         pred (torch.Tensor | np.array): The model prediction.
65         target (torch.Tensor | np.array): The target of each prediction.
66 
67     Returns:
68         float: The function will return a single float as F1 score.
69     """
70     confusion_matrix = calculate_confusion_matrix(pred, target)
71     with torch.no_grad():
72         precision = confusion_matrix.diag() / torch.clamp(
73             confusion_matrix.sum(1), min=1)
74         recall = confusion_matrix.diag() / torch.clamp(
75             confusion_matrix.sum(0), min=1)
76         res = 2 * precision * recall / torch.clamp(
77             precision + recall, min=1e-20)
78         res = torch.where(torch.isnan(res), torch.full_like(res, 0), res)
79         res = res.mean().item() * 100
80     return res
81
```
--- 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/mmcls/models/losses/eval_metrics.py b/mmcls/models/losses/eval_metrics.py
--- a/mmcls/models/losses/eval_metrics.py
+++ b/mmcls/models/losses/eval_metrics.py
@@ -34,7 +34,7 @@
     confusion_matrix = calculate_confusion_matrix(pred, target)
     with torch.no_grad():
         res = confusion_matrix.diag() / torch.clamp(
-            confusion_matrix.sum(1), min=1)
+            confusion_matrix.sum(0), min=1)
         res = res.mean().item() * 100
     return res
 
@@ -52,7 +52,7 @@
     confusion_matrix = calculate_confusion_matrix(pred, target)
     with torch.no_grad():
         res = confusion_matrix.diag() / torch.clamp(
-            confusion_matrix.sum(0), min=1)
+            confusion_matrix.sum(1), min=1)
         res = res.mean().item() * 100
     return res

{"golden_diff": "diff --git a/mmcls/models/losses/eval_metrics.py b/mmcls/models/losses/eval_metrics.py\n--- a/mmcls/models/losses/eval_metrics.py\n+++ b/mmcls/models/losses/eval_metrics.py\n@@ -34,7 +34,7 @@\n     confusion_matrix = calculate_confusion_matrix(pred, target)\n     with torch.no_grad():\n         res = confusion_matrix.diag() / torch.clamp(\n-            confusion_matrix.sum(1), min=1)\n+            confusion_matrix.sum(0), min=1)\n         res = res.mean().item() * 100\n     return res\n \n@@ -52,7 +52,7 @@\n     confusion_matrix = calculate_confusion_matrix(pred, target)\n     with torch.no_grad():\n         res = confusion_matrix.diag() / torch.clamp(\n-            confusion_matrix.sum(0), min=1)\n+            confusion_matrix.sum(1), min=1)\n         res = res.mean().item() * 100\n     return res\n", "issue": "bug in recall and precision?\nhi:\r\n   It seems the  https://github.com/open-mmlab/mmclassification/blob/92438da12a9f8bf0390277be902dc96e6970b54d/mmcls/models/losses/eval_metrics.py#L55\r\nand https://github.com/open-mmlab/mmclassification/blob/92438da12a9f8bf0390277be902dc96e6970b54d/mmcls/models/losses/eval_metrics.py#L37\r\nget inversed?\r\n@LXXXXR @ycxioooong\n", "before_files": [{"content": "import numpy as np\nimport torch\n\n\ndef calculate_confusion_matrix(pred, target):\n    if isinstance(pred, np.ndarray) and isinstance(target, np.ndarray):\n        pred = torch.from_numpy(pred)\n        target = torch.from_numpy(target)\n    elif not (isinstance(pred, torch.Tensor)\n              and isinstance(target, torch.Tensor)):\n        raise TypeError('pred and target should both be'\n                        'torch.Tensor or np.ndarray')\n    _, pred_label = pred.topk(1, dim=1)\n    num_classes = pred.size(1)\n    pred_label = pred_label.view(-1)\n    target_label = target.view(-1)\n    assert len(pred_label) == len(target_label)\n    confusion_matrix = torch.zeros(num_classes, num_classes)\n    with torch.no_grad():\n        confusion_matrix[target_label.long(), pred_label.long()] += 1\n    return confusion_matrix\n\n\ndef precision(pred, target):\n    \"\"\"Calculate macro-averaged precision according to the prediction and target\n\n    Args:\n        pred (torch.Tensor | np.array): The model prediction.\n        target (torch.Tensor | np.array): The target of each prediction.\n\n    Returns:\n        float: The function will return a single float as precision.\n    \"\"\"\n    confusion_matrix = calculate_confusion_matrix(pred, target)\n    with torch.no_grad():\n        res = confusion_matrix.diag() / torch.clamp(\n            confusion_matrix.sum(1), min=1)\n        res = res.mean().item() * 100\n    return res\n\n\ndef recall(pred, target):\n    \"\"\"Calculate macro-averaged recall according to the prediction and target\n\n    Args:\n        pred (torch.Tensor | np.array): The model prediction.\n        target (torch.Tensor | np.array): The target of each prediction.\n\n    Returns:\n        float: The function will return a single float as recall.\n    \"\"\"\n    confusion_matrix = calculate_confusion_matrix(pred, target)\n    with torch.no_grad():\n        res = confusion_matrix.diag() / torch.clamp(\n            confusion_matrix.sum(0), min=1)\n        res = res.mean().item() * 100\n    return res\n\n\ndef f1_score(pred, target):\n    \"\"\"Calculate macro-averaged F1 score according to the prediction and target\n\n    Args:\n        pred (torch.Tensor | np.array): The model prediction.\n        target (torch.Tensor | np.array): The target of each prediction.\n\n    Returns:\n        float: The function will return a single float as F1 score.\n    \"\"\"\n    confusion_matrix = calculate_confusion_matrix(pred, target)\n    with torch.no_grad():\n        precision = confusion_matrix.diag() / torch.clamp(\n            confusion_matrix.sum(1), min=1)\n        recall = confusion_matrix.diag() / torch.clamp(\n            confusion_matrix.sum(0), min=1)\n        res = 2 * precision * recall / torch.clamp(\n            precision + recall, min=1e-20)\n        res = torch.where(torch.isnan(res), torch.full_like(res, 0), res)\n        res = res.mean().item() * 100\n    return res\n", "path": "mmcls/models/losses/eval_metrics.py"}], "after_files": [{"content": "import numpy as np\nimport torch\n\n\ndef calculate_confusion_matrix(pred, target):\n    if isinstance(pred, np.ndarray) and isinstance(target, np.ndarray):\n        pred = torch.from_numpy(pred)\n        target = torch.from_numpy(target)\n    elif not (isinstance(pred, torch.Tensor)\n              and isinstance(target, torch.Tensor)):\n        raise TypeError('pred and target should both be'\n                        'torch.Tensor or np.ndarray')\n    _, pred_label = pred.topk(1, dim=1)\n    num_classes = pred.size(1)\n    pred_label = pred_label.view(-1)\n    target_label = target.view(-1)\n    assert len(pred_label) == len(target_label)\n    confusion_matrix = torch.zeros(num_classes, num_classes)\n    with torch.no_grad():\n        confusion_matrix[target_label.long(), pred_label.long()] += 1\n    return confusion_matrix\n\n\ndef precision(pred, target):\n    \"\"\"Calculate macro-averaged precision according to the prediction and target\n\n    Args:\n        pred (torch.Tensor | np.array): The model prediction.\n        target (torch.Tensor | np.array): The target of each prediction.\n\n    Returns:\n        float: The function will return a single float as precision.\n    \"\"\"\n    confusion_matrix = calculate_confusion_matrix(pred, target)\n    with torch.no_grad():\n        res = confusion_matrix.diag() / torch.clamp(\n            confusion_matrix.sum(0), min=1)\n        res = res.mean().item() * 100\n    return res\n\n\ndef recall(pred, target):\n    \"\"\"Calculate macro-averaged recall according to the prediction and target\n\n    Args:\n        pred (torch.Tensor | np.array): The model prediction.\n        target (torch.Tensor | np.array): The target of each prediction.\n\n    Returns:\n        float: The function will return a single float as recall.\n    \"\"\"\n    confusion_matrix = calculate_confusion_matrix(pred, target)\n    with torch.no_grad():\n        res = confusion_matrix.diag() / torch.clamp(\n            confusion_matrix.sum(1), min=1)\n        res = res.mean().item() * 100\n    return res\n\n\ndef f1_score(pred, target):\n    \"\"\"Calculate macro-averaged F1 score according to the prediction and target\n\n    Args:\n        pred (torch.Tensor | np.array): The model prediction.\n        target (torch.Tensor | np.array): The target of each prediction.\n\n    Returns:\n        float: The function will return a single float as F1 score.\n    \"\"\"\n    confusion_matrix = calculate_confusion_matrix(pred, target)\n    with torch.no_grad():\n        precision = confusion_matrix.diag() / torch.clamp(\n            confusion_matrix.sum(1), min=1)\n        recall = confusion_matrix.diag() / torch.clamp(\n            confusion_matrix.sum(0), min=1)\n        res = 2 * precision * recall / torch.clamp(\n            precision + recall, min=1e-20)\n        res = torch.where(torch.isnan(res), torch.full_like(res, 0), res)\n        res = res.mean().item() * 100\n    return res\n", "path": "mmcls/models/losses/eval_metrics.py"}]}