We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Efficientdet inference returns wrong bbox predictions
## 🐛 Bug
When running inference on efficientdet models, the predictions are squeezed to only fit square aspect ratio. This problem is only visible when running efficientdet in rectangular input shape (eg 512x768). Here is a screenshot of default behavior:
![image](https://user-images.githubusercontent.com/52150545/130605997-de6572df-e9f0-4939-aa1b-3787d88ffd72.png)

Note that predictions are squezzed, seemingly to only square image resolution. I have discovered that the bug comes from `process_infer_record` function, where the image input shape is passed to effdet in the wrong notation (H, W instead of W, H).

I applied that fix and the result is working as expected:
![image](https://user-images.githubusercontent.com/52150545/130606249-2f6610bf-1044-41d1-abf8-597fbf3562a5.png)


**To Reproduce**
Steps to reproduce the behavior:
1. Train efficientdet model in rectangular image input shape
2. Run inference



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `icevision/models/ross/efficientdet/dataloaders.py`
Content:
```
1 __all__ = [
2     "build_train_batch",
3     "build_valid_batch",
4     "build_infer_batch",
5     "train_dl",
6     "valid_dl",
7     "infer_dl",
8 ]
9 
10 from icevision.imports import *
11 from icevision.models.utils import *
12 
13 
14 def train_dl(dataset, batch_tfms=None, **dataloader_kwargs) -> DataLoader:
15     """A `DataLoader` with a custom `collate_fn` that batches items as required for training the model.
16 
17     # Arguments
18         dataset: Possibly a `Dataset` object, but more generally, any `Sequence` that returns records.
19         batch_tfms: Transforms to be applied at the batch level.
20         **dataloader_kwargs: Keyword arguments that will be internally passed to a Pytorch `DataLoader`.
21         The parameter `collate_fn` is already defined internally and cannot be passed here.
22 
23     # Returns
24         A Pytorch `DataLoader`.
25     """
26     return transform_dl(
27         dataset=dataset,
28         build_batch=build_train_batch,
29         batch_tfms=batch_tfms,
30         **dataloader_kwargs
31     )
32 
33 
34 def valid_dl(dataset, batch_tfms=None, **dataloader_kwargs) -> DataLoader:
35     """A `DataLoader` with a custom `collate_fn` that batches items as required for validating the model.
36 
37     # Arguments
38         dataset: Possibly a `Dataset` object, but more generally, any `Sequence` that returns records.
39         batch_tfms: Transforms to be applied at the batch level.
40         **dataloader_kwargs: Keyword arguments that will be internally passed to a Pytorch `DataLoader`.
41         The parameter `collate_fn` is already defined internally and cannot be passed here.
42 
43     # Returns
44         A Pytorch `DataLoader`.
45     """
46     return transform_dl(
47         dataset=dataset,
48         build_batch=build_valid_batch,
49         batch_tfms=batch_tfms,
50         **dataloader_kwargs
51     )
52 
53 
54 def infer_dl(dataset, batch_tfms=None, **dataloader_kwargs) -> DataLoader:
55     """A `DataLoader` with a custom `collate_fn` that batches items as required for inferring the model.
56 
57     # Arguments
58         dataset: Possibly a `Dataset` object, but more generally, any `Sequence` that returns records.
59         batch_tfms: Transforms to be applied at the batch level.
60         **dataloader_kwargs: Keyword arguments that will be internally passed to a Pytorch `DataLoader`.
61         The parameter `collate_fn` is already defined internally and cannot be passed here.
62 
63     # Returns
64         A Pytorch `DataLoader`.
65     """
66     return transform_dl(
67         dataset=dataset,
68         build_batch=build_infer_batch,
69         batch_tfms=batch_tfms,
70         **dataloader_kwargs
71     )
72 
73 
74 def build_train_batch(records):
75     """Builds a batch in the format required by the model when training.
76 
77     # Arguments
78         records: A `Sequence` of records.
79 
80     # Returns
81         A tuple with two items. The first will be a tuple like `(images, targets)`,
82         in the input format required by the model. The second will be a list
83         of the input records.
84 
85     # Examples
86 
87     Use the result of this function to feed the model.
88     ```python
89     batch, records = build_train_batch(records)
90     outs = model(*batch)
91     ```
92     """
93     batch_images, batch_bboxes, batch_classes = zip(
94         *(process_train_record(record) for record in records)
95     )
96 
97     # convert to tensors
98     batch_images = torch.stack(batch_images)
99     batch_bboxes = [tensor(bboxes, dtype=torch.float32) for bboxes in batch_bboxes]
100     batch_classes = [tensor(classes, dtype=torch.float32) for classes in batch_classes]
101 
102     # convert to EffDet interface
103     targets = dict(bbox=batch_bboxes, cls=batch_classes)
104 
105     return (batch_images, targets), records
106 
107 
108 def build_valid_batch(records):
109     """Builds a batch in the format required by the model when validating.
110 
111     # Arguments
112         records: A `Sequence` of records.
113 
114     # Returns
115         A tuple with two items. The first will be a tuple like `(images, targets)`,
116         in the input format required by the model. The second will be a list
117         of the input records.
118 
119     # Examples
120 
121     Use the result of this function to feed the model.
122     ```python
123     batch, records = build_valid_batch(records)
124     outs = model(*batch)
125     ```
126     """
127     (batch_images, targets), records = build_train_batch(records)
128 
129     # convert to EffDet interface, when not training, dummy size and scale is required
130     targets = dict(img_size=None, img_scale=None, **targets)
131 
132     return (batch_images, targets), records
133 
134 
135 def build_infer_batch(records):
136     """Builds a batch in the format required by the model when doing inference.
137 
138     # Arguments
139         records: A `Sequence` of records.
140 
141     # Returns
142         A tuple with two items. The first will be a tuple like `(images, targets)`,
143         in the input format required by the model. The second will be a list
144         of the input records.
145     Use the result of this function to feed the model.
146     ```python
147     batch, records = build_infer_batch(records)
148     outs = model(*batch)
149     ```
150     """
151     batch_images, batch_sizes, batch_scales = zip(
152         *(process_infer_record(record) for record in records)
153     )
154 
155     # convert to tensors
156     batch_images = torch.stack(batch_images)
157     batch_sizes = tensor(batch_sizes, dtype=torch.float32)
158     batch_scales = tensor(batch_scales, dtype=torch.float32)
159 
160     # convert to EffDet interface
161     targets = dict(img_size=batch_sizes, img_scale=batch_scales)
162 
163     return (batch_images, targets), records
164 
165 
166 def process_train_record(record) -> tuple:
167     """Extracts information from record and prepares a format required by the EffDet training"""
168     image = im2tensor(record.img)
169     # background and dummy if no label in record
170     classes = record.detection.label_ids if record.detection.label_ids else [0]
171     bboxes = (
172         [bbox.yxyx for bbox in record.detection.bboxes]
173         if len(record.detection.label_ids) > 0
174         else [[0, 0, 0, 0]]
175     )
176     return image, bboxes, classes
177 
178 
179 def process_infer_record(record) -> tuple:
180     """Extracts information from record and prepares a format required by the EffDet inference"""
181     image = im2tensor(record.img)
182     image_size = image.shape[-2:]
183     image_scale = 1.0
184 
185     return image, image_size, image_scale
186
```
--- 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/icevision/models/ross/efficientdet/dataloaders.py b/icevision/models/ross/efficientdet/dataloaders.py
--- a/icevision/models/ross/efficientdet/dataloaders.py
+++ b/icevision/models/ross/efficientdet/dataloaders.py
@@ -179,7 +179,7 @@
 def process_infer_record(record) -> tuple:
     """Extracts information from record and prepares a format required by the EffDet inference"""
     image = im2tensor(record.img)
-    image_size = image.shape[-2:]
+    n_channels, image_height, image_width = image.shape
     image_scale = 1.0
-
-    return image, image_size, image_scale
+    # EffDet expects image size to be passed in W, H notation
+    return image, (image_width, image_height), image_scale

{"golden_diff": "diff --git a/icevision/models/ross/efficientdet/dataloaders.py b/icevision/models/ross/efficientdet/dataloaders.py\n--- a/icevision/models/ross/efficientdet/dataloaders.py\n+++ b/icevision/models/ross/efficientdet/dataloaders.py\n@@ -179,7 +179,7 @@\n def process_infer_record(record) -> tuple:\n     \"\"\"Extracts information from record and prepares a format required by the EffDet inference\"\"\"\n     image = im2tensor(record.img)\n-    image_size = image.shape[-2:]\n+    n_channels, image_height, image_width = image.shape\n     image_scale = 1.0\n-\n-    return image, image_size, image_scale\n+    # EffDet expects image size to be passed in W, H notation\n+    return image, (image_width, image_height), image_scale\n", "issue": "Efficientdet inference returns wrong bbox predictions\n## \ud83d\udc1b Bug\r\nWhen running inference on efficientdet models, the predictions are squeezed to only fit square aspect ratio. This problem is only visible when running efficientdet in rectangular input shape (eg 512x768). Here is a screenshot of default behavior:\r\n![image](https://user-images.githubusercontent.com/52150545/130605997-de6572df-e9f0-4939-aa1b-3787d88ffd72.png)\r\n\r\nNote that predictions are squezzed, seemingly to only square image resolution. I have discovered that the bug comes from `process_infer_record` function, where the image input shape is passed to effdet in the wrong notation (H, W instead of W, H).\r\n\r\nI applied that fix and the result is working as expected:\r\n![image](https://user-images.githubusercontent.com/52150545/130606249-2f6610bf-1044-41d1-abf8-597fbf3562a5.png)\r\n\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Train efficientdet model in rectangular image input shape\r\n2. Run inference\r\n\r\n\n", "before_files": [{"content": "__all__ = [\n    \"build_train_batch\",\n    \"build_valid_batch\",\n    \"build_infer_batch\",\n    \"train_dl\",\n    \"valid_dl\",\n    \"infer_dl\",\n]\n\nfrom icevision.imports import *\nfrom icevision.models.utils import *\n\n\ndef train_dl(dataset, batch_tfms=None, **dataloader_kwargs) -> DataLoader:\n    \"\"\"A `DataLoader` with a custom `collate_fn` that batches items as required for training the model.\n\n    # Arguments\n        dataset: Possibly a `Dataset` object, but more generally, any `Sequence` that returns records.\n        batch_tfms: Transforms to be applied at the batch level.\n        **dataloader_kwargs: Keyword arguments that will be internally passed to a Pytorch `DataLoader`.\n        The parameter `collate_fn` is already defined internally and cannot be passed here.\n\n    # Returns\n        A Pytorch `DataLoader`.\n    \"\"\"\n    return transform_dl(\n        dataset=dataset,\n        build_batch=build_train_batch,\n        batch_tfms=batch_tfms,\n        **dataloader_kwargs\n    )\n\n\ndef valid_dl(dataset, batch_tfms=None, **dataloader_kwargs) -> DataLoader:\n    \"\"\"A `DataLoader` with a custom `collate_fn` that batches items as required for validating the model.\n\n    # Arguments\n        dataset: Possibly a `Dataset` object, but more generally, any `Sequence` that returns records.\n        batch_tfms: Transforms to be applied at the batch level.\n        **dataloader_kwargs: Keyword arguments that will be internally passed to a Pytorch `DataLoader`.\n        The parameter `collate_fn` is already defined internally and cannot be passed here.\n\n    # Returns\n        A Pytorch `DataLoader`.\n    \"\"\"\n    return transform_dl(\n        dataset=dataset,\n        build_batch=build_valid_batch,\n        batch_tfms=batch_tfms,\n        **dataloader_kwargs\n    )\n\n\ndef infer_dl(dataset, batch_tfms=None, **dataloader_kwargs) -> DataLoader:\n    \"\"\"A `DataLoader` with a custom `collate_fn` that batches items as required for inferring the model.\n\n    # Arguments\n        dataset: Possibly a `Dataset` object, but more generally, any `Sequence` that returns records.\n        batch_tfms: Transforms to be applied at the batch level.\n        **dataloader_kwargs: Keyword arguments that will be internally passed to a Pytorch `DataLoader`.\n        The parameter `collate_fn` is already defined internally and cannot be passed here.\n\n    # Returns\n        A Pytorch `DataLoader`.\n    \"\"\"\n    return transform_dl(\n        dataset=dataset,\n        build_batch=build_infer_batch,\n        batch_tfms=batch_tfms,\n        **dataloader_kwargs\n    )\n\n\ndef build_train_batch(records):\n    \"\"\"Builds a batch in the format required by the model when training.\n\n    # Arguments\n        records: A `Sequence` of records.\n\n    # Returns\n        A tuple with two items. The first will be a tuple like `(images, targets)`,\n        in the input format required by the model. The second will be a list\n        of the input records.\n\n    # Examples\n\n    Use the result of this function to feed the model.\n    ```python\n    batch, records = build_train_batch(records)\n    outs = model(*batch)\n    ```\n    \"\"\"\n    batch_images, batch_bboxes, batch_classes = zip(\n        *(process_train_record(record) for record in records)\n    )\n\n    # convert to tensors\n    batch_images = torch.stack(batch_images)\n    batch_bboxes = [tensor(bboxes, dtype=torch.float32) for bboxes in batch_bboxes]\n    batch_classes = [tensor(classes, dtype=torch.float32) for classes in batch_classes]\n\n    # convert to EffDet interface\n    targets = dict(bbox=batch_bboxes, cls=batch_classes)\n\n    return (batch_images, targets), records\n\n\ndef build_valid_batch(records):\n    \"\"\"Builds a batch in the format required by the model when validating.\n\n    # Arguments\n        records: A `Sequence` of records.\n\n    # Returns\n        A tuple with two items. The first will be a tuple like `(images, targets)`,\n        in the input format required by the model. The second will be a list\n        of the input records.\n\n    # Examples\n\n    Use the result of this function to feed the model.\n    ```python\n    batch, records = build_valid_batch(records)\n    outs = model(*batch)\n    ```\n    \"\"\"\n    (batch_images, targets), records = build_train_batch(records)\n\n    # convert to EffDet interface, when not training, dummy size and scale is required\n    targets = dict(img_size=None, img_scale=None, **targets)\n\n    return (batch_images, targets), records\n\n\ndef build_infer_batch(records):\n    \"\"\"Builds a batch in the format required by the model when doing inference.\n\n    # Arguments\n        records: A `Sequence` of records.\n\n    # Returns\n        A tuple with two items. The first will be a tuple like `(images, targets)`,\n        in the input format required by the model. The second will be a list\n        of the input records.\n    Use the result of this function to feed the model.\n    ```python\n    batch, records = build_infer_batch(records)\n    outs = model(*batch)\n    ```\n    \"\"\"\n    batch_images, batch_sizes, batch_scales = zip(\n        *(process_infer_record(record) for record in records)\n    )\n\n    # convert to tensors\n    batch_images = torch.stack(batch_images)\n    batch_sizes = tensor(batch_sizes, dtype=torch.float32)\n    batch_scales = tensor(batch_scales, dtype=torch.float32)\n\n    # convert to EffDet interface\n    targets = dict(img_size=batch_sizes, img_scale=batch_scales)\n\n    return (batch_images, targets), records\n\n\ndef process_train_record(record) -> tuple:\n    \"\"\"Extracts information from record and prepares a format required by the EffDet training\"\"\"\n    image = im2tensor(record.img)\n    # background and dummy if no label in record\n    classes = record.detection.label_ids if record.detection.label_ids else [0]\n    bboxes = (\n        [bbox.yxyx for bbox in record.detection.bboxes]\n        if len(record.detection.label_ids) > 0\n        else [[0, 0, 0, 0]]\n    )\n    return image, bboxes, classes\n\n\ndef process_infer_record(record) -> tuple:\n    \"\"\"Extracts information from record and prepares a format required by the EffDet inference\"\"\"\n    image = im2tensor(record.img)\n    image_size = image.shape[-2:]\n    image_scale = 1.0\n\n    return image, image_size, image_scale\n", "path": "icevision/models/ross/efficientdet/dataloaders.py"}], "after_files": [{"content": "__all__ = [\n    \"build_train_batch\",\n    \"build_valid_batch\",\n    \"build_infer_batch\",\n    \"train_dl\",\n    \"valid_dl\",\n    \"infer_dl\",\n]\n\nfrom icevision.imports import *\nfrom icevision.models.utils import *\n\n\ndef train_dl(dataset, batch_tfms=None, **dataloader_kwargs) -> DataLoader:\n    \"\"\"A `DataLoader` with a custom `collate_fn` that batches items as required for training the model.\n\n    # Arguments\n        dataset: Possibly a `Dataset` object, but more generally, any `Sequence` that returns records.\n        batch_tfms: Transforms to be applied at the batch level.\n        **dataloader_kwargs: Keyword arguments that will be internally passed to a Pytorch `DataLoader`.\n        The parameter `collate_fn` is already defined internally and cannot be passed here.\n\n    # Returns\n        A Pytorch `DataLoader`.\n    \"\"\"\n    return transform_dl(\n        dataset=dataset,\n        build_batch=build_train_batch,\n        batch_tfms=batch_tfms,\n        **dataloader_kwargs\n    )\n\n\ndef valid_dl(dataset, batch_tfms=None, **dataloader_kwargs) -> DataLoader:\n    \"\"\"A `DataLoader` with a custom `collate_fn` that batches items as required for validating the model.\n\n    # Arguments\n        dataset: Possibly a `Dataset` object, but more generally, any `Sequence` that returns records.\n        batch_tfms: Transforms to be applied at the batch level.\n        **dataloader_kwargs: Keyword arguments that will be internally passed to a Pytorch `DataLoader`.\n        The parameter `collate_fn` is already defined internally and cannot be passed here.\n\n    # Returns\n        A Pytorch `DataLoader`.\n    \"\"\"\n    return transform_dl(\n        dataset=dataset,\n        build_batch=build_valid_batch,\n        batch_tfms=batch_tfms,\n        **dataloader_kwargs\n    )\n\n\ndef infer_dl(dataset, batch_tfms=None, **dataloader_kwargs) -> DataLoader:\n    \"\"\"A `DataLoader` with a custom `collate_fn` that batches items as required for inferring the model.\n\n    # Arguments\n        dataset: Possibly a `Dataset` object, but more generally, any `Sequence` that returns records.\n        batch_tfms: Transforms to be applied at the batch level.\n        **dataloader_kwargs: Keyword arguments that will be internally passed to a Pytorch `DataLoader`.\n        The parameter `collate_fn` is already defined internally and cannot be passed here.\n\n    # Returns\n        A Pytorch `DataLoader`.\n    \"\"\"\n    return transform_dl(\n        dataset=dataset,\n        build_batch=build_infer_batch,\n        batch_tfms=batch_tfms,\n        **dataloader_kwargs\n    )\n\n\ndef build_train_batch(records):\n    \"\"\"Builds a batch in the format required by the model when training.\n\n    # Arguments\n        records: A `Sequence` of records.\n\n    # Returns\n        A tuple with two items. The first will be a tuple like `(images, targets)`,\n        in the input format required by the model. The second will be a list\n        of the input records.\n\n    # Examples\n\n    Use the result of this function to feed the model.\n    ```python\n    batch, records = build_train_batch(records)\n    outs = model(*batch)\n    ```\n    \"\"\"\n    batch_images, batch_bboxes, batch_classes = zip(\n        *(process_train_record(record) for record in records)\n    )\n\n    # convert to tensors\n    batch_images = torch.stack(batch_images)\n    batch_bboxes = [tensor(bboxes, dtype=torch.float32) for bboxes in batch_bboxes]\n    batch_classes = [tensor(classes, dtype=torch.float32) for classes in batch_classes]\n\n    # convert to EffDet interface\n    targets = dict(bbox=batch_bboxes, cls=batch_classes)\n\n    return (batch_images, targets), records\n\n\ndef build_valid_batch(records):\n    \"\"\"Builds a batch in the format required by the model when validating.\n\n    # Arguments\n        records: A `Sequence` of records.\n\n    # Returns\n        A tuple with two items. The first will be a tuple like `(images, targets)`,\n        in the input format required by the model. The second will be a list\n        of the input records.\n\n    # Examples\n\n    Use the result of this function to feed the model.\n    ```python\n    batch, records = build_valid_batch(records)\n    outs = model(*batch)\n    ```\n    \"\"\"\n    (batch_images, targets), records = build_train_batch(records)\n\n    # convert to EffDet interface, when not training, dummy size and scale is required\n    targets = dict(img_size=None, img_scale=None, **targets)\n\n    return (batch_images, targets), records\n\n\ndef build_infer_batch(records):\n    \"\"\"Builds a batch in the format required by the model when doing inference.\n\n    # Arguments\n        records: A `Sequence` of records.\n\n    # Returns\n        A tuple with two items. The first will be a tuple like `(images, targets)`,\n        in the input format required by the model. The second will be a list\n        of the input records.\n    Use the result of this function to feed the model.\n    ```python\n    batch, records = build_infer_batch(records)\n    outs = model(*batch)\n    ```\n    \"\"\"\n    batch_images, batch_sizes, batch_scales = zip(\n        *(process_infer_record(record) for record in records)\n    )\n\n    # convert to tensors\n    batch_images = torch.stack(batch_images)\n    batch_sizes = tensor(batch_sizes, dtype=torch.float32)\n    batch_scales = tensor(batch_scales, dtype=torch.float32)\n\n    # convert to EffDet interface\n    targets = dict(img_size=batch_sizes, img_scale=batch_scales)\n\n    return (batch_images, targets), records\n\n\ndef process_train_record(record) -> tuple:\n    \"\"\"Extracts information from record and prepares a format required by the EffDet training\"\"\"\n    image = im2tensor(record.img)\n    # background and dummy if no label in record\n    classes = record.detection.label_ids if record.detection.label_ids else [0]\n    bboxes = (\n        [bbox.yxyx for bbox in record.detection.bboxes]\n        if len(record.detection.label_ids) > 0\n        else [[0, 0, 0, 0]]\n    )\n    return image, bboxes, classes\n\n\ndef process_infer_record(record) -> tuple:\n    \"\"\"Extracts information from record and prepares a format required by the EffDet inference\"\"\"\n    image = im2tensor(record.img)\n    n_channels, image_height, image_width = image.shape\n    image_scale = 1.0\n    # EffDet expects image size to be passed in W, H notation\n    return image, (image_width, image_height), image_scale\n", "path": "icevision/models/ross/efficientdet/dataloaders.py"}]}