prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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()}")
  
  </issue>
  <code>
  [start of demo/backend/tensorflow.py]
  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
  [end of demo/backend/tensorflow.py]
  [start of demo/backend/pytorch.py]
  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 of demo/backend/pytorch.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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:
  
verification_info: {"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"}]}