We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
listing the detection and recognition models not working in pytorch
### Bug description

Hi,

This is the list of models not working in inference:

- detection models:
   * db_resnet_34
   * linknet_resnet18
   * linknet_resnet34
   * linknet_resnet50
for all these detection models in pytorch, the code inference works but it get to much segmentations/detected boxes. 


- recognition models:
  * sar_resnet31
  * master
  * vitstr_small
  * vitstr_base
For all of these models in pytorch, the code inference seems to work, but it gets random character recognition. I think they are not  correct loaded or trained.


### Code snippet to reproduce the bug

in doctr/demo/backend/pytorch.py file, changing this lines
```
DET_ARCHS = ["db_resnet50", "db_mobilenet_v3_large", "linknet_resnet50_rotation"]
RECO_ARCHS = ["crnn_vgg16_bn", "crnn_mobilenet_v3_small", "master", "sar_resnet31"]
```

by this lines 
```
#DET_ARCHS = ["db_resnet50", "db_mobilenet_v3_large", "linknet_resnet50_rotation"]
DET_ARCHS = [ "db_resnet34",
        "db_resnet50",
        "db_mobilenet_v3_large",
        "linknet_resnet18",
        "linknet_resnet34",
        "linknet_resnet50",
        "db_resnet50_rotation"]
#RECO_ARCHS = ["crnn_vgg16_bn", "crnn_mobilenet_v3_small", "master", "sar_resnet31"]
RECO_ARCHS=[ "crnn_vgg16_bn",
    "crnn_mobilenet_v3_small",
    "crnn_mobilenet_v3_large",
    "sar_resnet31",
    "master",
    "vitstr_small",
    "vitstr_base"]
```

and running this code to try all the pytorch models
```
USE_TF=0 streamlit run demo/app.py
```


### Error traceback

not errors but bugs on models

### Environment

wget https://raw.githubusercontent.com/mindee/doctr/main/scripts/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

### Deep Learning backend

 from doctr.file_utils import is_tf_available, is_torch_available

print(f"is_tf_available: {is_tf_available()}")
print(f"is_torch_available: {is_torch_available()}")

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `demo/backend/tensorflow.py`
Content:
```
1 # Copyright (C) 2021-2023, Mindee.
2 
3 # This program is licensed under the Apache License 2.0.
4 # See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
5 
6 import numpy as np
7 import tensorflow as tf
8 
9 from doctr.models import ocr_predictor
10 from doctr.models.predictor import OCRPredictor
11 
12 DET_ARCHS = ["db_resnet50", "db_mobilenet_v3_large", "linknet_resnet18_rotation"]
13 RECO_ARCHS = ["crnn_vgg16_bn", "crnn_mobilenet_v3_small", "master", "sar_resnet31"]
14 
15 
16 def load_predictor(det_arch: str, reco_arch: str, device) -> OCRPredictor:
17     """
18     Args:
19         device is tf.device
20     """
21     with device:
22         predictor = ocr_predictor(
23             det_arch, reco_arch, pretrained=True, assume_straight_pages=("rotation" not in det_arch)
24         )
25     return predictor
26 
27 
28 def forward_image(predictor: OCRPredictor, image: np.ndarray, device) -> np.ndarray:
29     """
30     Args:
31         device is tf.device
32     """
33     with device:
34         processed_batches = predictor.det_predictor.pre_processor([image])
35         out = predictor.det_predictor.model(processed_batches[0], return_model_output=True)
36         seg_map = out["out_map"]
37 
38     with tf.device("/cpu:0"):
39         seg_map = tf.identity(seg_map).numpy()
40 
41     return seg_map
42
```

Path: `demo/backend/pytorch.py`
Content:
```
1 # Copyright (C) 2021-2023, Mindee.
2 
3 # This program is licensed under the Apache License 2.0.
4 # See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
5 
6 import numpy as np
7 import torch
8 
9 from doctr.models import ocr_predictor
10 from doctr.models.predictor import OCRPredictor
11 
12 DET_ARCHS = ["db_resnet50", "db_mobilenet_v3_large", "linknet_resnet50_rotation"]
13 RECO_ARCHS = ["crnn_vgg16_bn", "crnn_mobilenet_v3_small", "master", "sar_resnet31"]
14 
15 
16 def load_predictor(det_arch: str, reco_arch: str, device) -> OCRPredictor:
17     """
18     Args:
19         device is torch.device
20     """
21     predictor = ocr_predictor(
22         det_arch, reco_arch, pretrained=True, assume_straight_pages=("rotation" not in det_arch)
23     ).to(device)
24     return predictor
25 
26 
27 def forward_image(predictor: OCRPredictor, image: np.ndarray, device) -> np.ndarray:
28     """
29     Args:
30         device is torch.device
31     """
32     with torch.no_grad():
33         processed_batches = predictor.det_predictor.pre_processor([image])
34         out = predictor.det_predictor.model(processed_batches[0].to(device), return_model_output=True)
35         seg_map = out["out_map"].to("cpu").numpy()
36 
37     return seg_map
38
```
--- 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/demo/backend/pytorch.py b/demo/backend/pytorch.py
--- a/demo/backend/pytorch.py
+++ b/demo/backend/pytorch.py
@@ -9,8 +9,25 @@
 from doctr.models import ocr_predictor
 from doctr.models.predictor import OCRPredictor
 
-DET_ARCHS = ["db_resnet50", "db_mobilenet_v3_large", "linknet_resnet50_rotation"]
-RECO_ARCHS = ["crnn_vgg16_bn", "crnn_mobilenet_v3_small", "master", "sar_resnet31"]
+DET_ARCHS = [
+    "db_resnet50",
+    "db_resnet34",
+    "db_mobilenet_v3_large",
+    "db_resnet50_rotation",
+    "linknet_resnet18",
+    "linknet_resnet34",
+    "linknet_resnet50",
+]
+RECO_ARCHS = [
+    "crnn_vgg16_bn",
+    "crnn_mobilenet_v3_small",
+    "crnn_mobilenet_v3_large",
+    "master",
+    "sar_resnet31",
+    "vitstr_small",
+    "vitstr_base",
+    "parseq",
+]
 
 
 def load_predictor(det_arch: str, reco_arch: str, device) -> OCRPredictor:
diff --git a/demo/backend/tensorflow.py b/demo/backend/tensorflow.py
--- a/demo/backend/tensorflow.py
+++ b/demo/backend/tensorflow.py
@@ -9,8 +9,24 @@
 from doctr.models import ocr_predictor
 from doctr.models.predictor import OCRPredictor
 
-DET_ARCHS = ["db_resnet50", "db_mobilenet_v3_large", "linknet_resnet18_rotation"]
-RECO_ARCHS = ["crnn_vgg16_bn", "crnn_mobilenet_v3_small", "master", "sar_resnet31"]
+DET_ARCHS = [
+    "db_resnet50",
+    "db_mobilenet_v3_large",
+    "linknet_resnet18",
+    "linknet_resnet18_rotation",
+    "linknet_resnet34",
+    "linknet_resnet50",
+]
+RECO_ARCHS = [
+    "crnn_vgg16_bn",
+    "crnn_mobilenet_v3_small",
+    "crnn_mobilenet_v3_large",
+    "master",
+    "sar_resnet31",
+    "vitstr_small",
+    "vitstr_base",
+    "parseq",
+]
 
 
 def load_predictor(det_arch: str, reco_arch: str, device) -> OCRPredictor:

{"golden_diff": "diff --git a/demo/backend/pytorch.py b/demo/backend/pytorch.py\n--- a/demo/backend/pytorch.py\n+++ b/demo/backend/pytorch.py\n@@ -9,8 +9,25 @@\n from doctr.models import ocr_predictor\n from doctr.models.predictor import OCRPredictor\n \n-DET_ARCHS = [\"db_resnet50\", \"db_mobilenet_v3_large\", \"linknet_resnet50_rotation\"]\n-RECO_ARCHS = [\"crnn_vgg16_bn\", \"crnn_mobilenet_v3_small\", \"master\", \"sar_resnet31\"]\n+DET_ARCHS = [\n+    \"db_resnet50\",\n+    \"db_resnet34\",\n+    \"db_mobilenet_v3_large\",\n+    \"db_resnet50_rotation\",\n+    \"linknet_resnet18\",\n+    \"linknet_resnet34\",\n+    \"linknet_resnet50\",\n+]\n+RECO_ARCHS = [\n+    \"crnn_vgg16_bn\",\n+    \"crnn_mobilenet_v3_small\",\n+    \"crnn_mobilenet_v3_large\",\n+    \"master\",\n+    \"sar_resnet31\",\n+    \"vitstr_small\",\n+    \"vitstr_base\",\n+    \"parseq\",\n+]\n \n \n def load_predictor(det_arch: str, reco_arch: str, device) -> OCRPredictor:\ndiff --git a/demo/backend/tensorflow.py b/demo/backend/tensorflow.py\n--- a/demo/backend/tensorflow.py\n+++ b/demo/backend/tensorflow.py\n@@ -9,8 +9,24 @@\n from doctr.models import ocr_predictor\n from doctr.models.predictor import OCRPredictor\n \n-DET_ARCHS = [\"db_resnet50\", \"db_mobilenet_v3_large\", \"linknet_resnet18_rotation\"]\n-RECO_ARCHS = [\"crnn_vgg16_bn\", \"crnn_mobilenet_v3_small\", \"master\", \"sar_resnet31\"]\n+DET_ARCHS = [\n+    \"db_resnet50\",\n+    \"db_mobilenet_v3_large\",\n+    \"linknet_resnet18\",\n+    \"linknet_resnet18_rotation\",\n+    \"linknet_resnet34\",\n+    \"linknet_resnet50\",\n+]\n+RECO_ARCHS = [\n+    \"crnn_vgg16_bn\",\n+    \"crnn_mobilenet_v3_small\",\n+    \"crnn_mobilenet_v3_large\",\n+    \"master\",\n+    \"sar_resnet31\",\n+    \"vitstr_small\",\n+    \"vitstr_base\",\n+    \"parseq\",\n+]\n \n \n def load_predictor(det_arch: str, reco_arch: str, device) -> OCRPredictor:\n", "issue": "listing the detection and recognition models not working in pytorch\n### Bug description\r\n\r\nHi,\r\n\r\nThis is the list of models not working in inference:\r\n\r\n- detection models:\r\n   * db_resnet_34\r\n   * linknet_resnet18\r\n   * linknet_resnet34\r\n   * linknet_resnet50\r\nfor all these detection models in pytorch, the code inference works but it get to much segmentations/detected boxes. \r\n\r\n\r\n- recognition models:\r\n  * sar_resnet31\r\n  * master\r\n  * vitstr_small\r\n  * vitstr_base\r\nFor all of these models in pytorch, the code inference seems to work, but it gets random character recognition. I think they are not  correct loaded or trained.\r\n\r\n\r\n### Code snippet to reproduce the bug\r\n\r\nin doctr/demo/backend/pytorch.py file, changing this lines\r\n```\r\nDET_ARCHS = [\"db_resnet50\", \"db_mobilenet_v3_large\", \"linknet_resnet50_rotation\"]\r\nRECO_ARCHS = [\"crnn_vgg16_bn\", \"crnn_mobilenet_v3_small\", \"master\", \"sar_resnet31\"]\r\n```\r\n\r\nby this lines \r\n```\r\n#DET_ARCHS = [\"db_resnet50\", \"db_mobilenet_v3_large\", \"linknet_resnet50_rotation\"]\r\nDET_ARCHS = [ \"db_resnet34\",\r\n        \"db_resnet50\",\r\n        \"db_mobilenet_v3_large\",\r\n        \"linknet_resnet18\",\r\n        \"linknet_resnet34\",\r\n        \"linknet_resnet50\",\r\n        \"db_resnet50_rotation\"]\r\n#RECO_ARCHS = [\"crnn_vgg16_bn\", \"crnn_mobilenet_v3_small\", \"master\", \"sar_resnet31\"]\r\nRECO_ARCHS=[ \"crnn_vgg16_bn\",\r\n    \"crnn_mobilenet_v3_small\",\r\n    \"crnn_mobilenet_v3_large\",\r\n    \"sar_resnet31\",\r\n    \"master\",\r\n    \"vitstr_small\",\r\n    \"vitstr_base\"]\r\n```\r\n\r\nand running this code to try all the pytorch models\r\n```\r\nUSE_TF=0 streamlit run demo/app.py\r\n```\r\n\r\n\r\n### Error traceback\r\n\r\nnot errors but bugs on models\r\n\r\n### Environment\r\n\r\nwget https://raw.githubusercontent.com/mindee/doctr/main/scripts/collect_env.py\r\n# For security purposes, please check the contents of collect_env.py before running it.\r\npython collect_env.py\r\n\r\n### Deep Learning backend\r\n\r\n from doctr.file_utils import is_tf_available, is_torch_available\r\n\r\nprint(f\"is_tf_available: {is_tf_available()}\")\r\nprint(f\"is_torch_available: {is_torch_available()}\")\n", "before_files": [{"content": "# Copyright (C) 2021-2023, Mindee.\n\n# This program is licensed under the Apache License 2.0.\n# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom doctr.models import ocr_predictor\nfrom doctr.models.predictor import OCRPredictor\n\nDET_ARCHS = [\"db_resnet50\", \"db_mobilenet_v3_large\", \"linknet_resnet18_rotation\"]\nRECO_ARCHS = [\"crnn_vgg16_bn\", \"crnn_mobilenet_v3_small\", \"master\", \"sar_resnet31\"]\n\n\ndef load_predictor(det_arch: str, reco_arch: str, device) -> OCRPredictor:\n    \"\"\"\n    Args:\n        device is tf.device\n    \"\"\"\n    with device:\n        predictor = ocr_predictor(\n            det_arch, reco_arch, pretrained=True, assume_straight_pages=(\"rotation\" not in det_arch)\n        )\n    return predictor\n\n\ndef forward_image(predictor: OCRPredictor, image: np.ndarray, device) -> np.ndarray:\n    \"\"\"\n    Args:\n        device is tf.device\n    \"\"\"\n    with device:\n        processed_batches = predictor.det_predictor.pre_processor([image])\n        out = predictor.det_predictor.model(processed_batches[0], return_model_output=True)\n        seg_map = out[\"out_map\"]\n\n    with tf.device(\"/cpu:0\"):\n        seg_map = tf.identity(seg_map).numpy()\n\n    return seg_map\n", "path": "demo/backend/tensorflow.py"}, {"content": "# Copyright (C) 2021-2023, Mindee.\n\n# This program is licensed under the Apache License 2.0.\n# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.\n\nimport numpy as np\nimport torch\n\nfrom doctr.models import ocr_predictor\nfrom doctr.models.predictor import OCRPredictor\n\nDET_ARCHS = [\"db_resnet50\", \"db_mobilenet_v3_large\", \"linknet_resnet50_rotation\"]\nRECO_ARCHS = [\"crnn_vgg16_bn\", \"crnn_mobilenet_v3_small\", \"master\", \"sar_resnet31\"]\n\n\ndef load_predictor(det_arch: str, reco_arch: str, device) -> OCRPredictor:\n    \"\"\"\n    Args:\n        device is torch.device\n    \"\"\"\n    predictor = ocr_predictor(\n        det_arch, reco_arch, pretrained=True, assume_straight_pages=(\"rotation\" not in det_arch)\n    ).to(device)\n    return predictor\n\n\ndef forward_image(predictor: OCRPredictor, image: np.ndarray, device) -> np.ndarray:\n    \"\"\"\n    Args:\n        device is torch.device\n    \"\"\"\n    with torch.no_grad():\n        processed_batches = predictor.det_predictor.pre_processor([image])\n        out = predictor.det_predictor.model(processed_batches[0].to(device), return_model_output=True)\n        seg_map = out[\"out_map\"].to(\"cpu\").numpy()\n\n    return seg_map\n", "path": "demo/backend/pytorch.py"}], "after_files": [{"content": "# Copyright (C) 2021-2023, Mindee.\n\n# This program is licensed under the Apache License 2.0.\n# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom doctr.models import ocr_predictor\nfrom doctr.models.predictor import OCRPredictor\n\nDET_ARCHS = [\n    \"db_resnet50\",\n    \"db_mobilenet_v3_large\",\n    \"linknet_resnet18\",\n    \"linknet_resnet18_rotation\",\n    \"linknet_resnet34\",\n    \"linknet_resnet50\",\n]\nRECO_ARCHS = [\n    \"crnn_vgg16_bn\",\n    \"crnn_mobilenet_v3_small\",\n    \"crnn_mobilenet_v3_large\",\n    \"master\",\n    \"sar_resnet31\",\n    \"vitstr_small\",\n    \"vitstr_base\",\n    \"parseq\",\n]\n\n\ndef load_predictor(det_arch: str, reco_arch: str, device) -> OCRPredictor:\n    \"\"\"\n    Args:\n        device is tf.device\n    \"\"\"\n    with device:\n        predictor = ocr_predictor(\n            det_arch, reco_arch, pretrained=True, assume_straight_pages=(\"rotation\" not in det_arch)\n        )\n    return predictor\n\n\ndef forward_image(predictor: OCRPredictor, image: np.ndarray, device) -> np.ndarray:\n    \"\"\"\n    Args:\n        device is tf.device\n    \"\"\"\n    with device:\n        processed_batches = predictor.det_predictor.pre_processor([image])\n        out = predictor.det_predictor.model(processed_batches[0], return_model_output=True)\n        seg_map = out[\"out_map\"]\n\n    with tf.device(\"/cpu:0\"):\n        seg_map = tf.identity(seg_map).numpy()\n\n    return seg_map\n", "path": "demo/backend/tensorflow.py"}, {"content": "# Copyright (C) 2021-2023, Mindee.\n\n# This program is licensed under the Apache License 2.0.\n# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.\n\nimport numpy as np\nimport torch\n\nfrom doctr.models import ocr_predictor\nfrom doctr.models.predictor import OCRPredictor\n\nDET_ARCHS = [\n    \"db_resnet50\",\n    \"db_resnet34\",\n    \"db_mobilenet_v3_large\",\n    \"db_resnet50_rotation\",\n    \"linknet_resnet18\",\n    \"linknet_resnet34\",\n    \"linknet_resnet50\",\n]\nRECO_ARCHS = [\n    \"crnn_vgg16_bn\",\n    \"crnn_mobilenet_v3_small\",\n    \"crnn_mobilenet_v3_large\",\n    \"master\",\n    \"sar_resnet31\",\n    \"vitstr_small\",\n    \"vitstr_base\",\n    \"parseq\",\n]\n\n\ndef load_predictor(det_arch: str, reco_arch: str, device) -> OCRPredictor:\n    \"\"\"\n    Args:\n        device is torch.device\n    \"\"\"\n    predictor = ocr_predictor(\n        det_arch, reco_arch, pretrained=True, assume_straight_pages=(\"rotation\" not in det_arch)\n    ).to(device)\n    return predictor\n\n\ndef forward_image(predictor: OCRPredictor, image: np.ndarray, device) -> np.ndarray:\n    \"\"\"\n    Args:\n        device is torch.device\n    \"\"\"\n    with torch.no_grad():\n        processed_batches = predictor.det_predictor.pre_processor([image])\n        out = predictor.det_predictor.model(processed_batches[0].to(device), return_model_output=True)\n        seg_map = out[\"out_map\"].to(\"cpu\").numpy()\n\n    return seg_map\n", "path": "demo/backend/pytorch.py"}]}