We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
model ensembling isn't working
## 🐛 Bug
When I detect some image by using ensembling, it doesn't work.

## To Reproduce (REQUIRED)
Input:
```
!git clone https://github.com/ultralytics/yolov5  # clone repo
%cd yolov5
%pip install -qr requirements.txt  # install dependencies

import torch
from IPython.display import Image, clear_output  # to display images
import urllib

clear_output()
print(f"Setup complete. Using torch {torch.__version__} ({torch.cuda.get_device_properties(0).name if torch.cuda.is_available() else 'CPU'})")

def download_file(url, dst_path):
    try:
        with urllib.request.urlopen(url) as web_file:
            data = web_file.read()
            with open(dst_path, mode='wb') as local_file:
                local_file.write(data)
    except urllib.error.URLError as e:
        print(e)

download_file('https://user-images.githubusercontent.com/26833433/124489091-ea4f9a00-ddb0-11eb-8ef1-d6f335c97f6f.jpg', "zidane.jpg")

!python detect.py --weights yolov5x.pt yolov5s.pt --img 640 --conf 0.25 --source data/images/
Image(filename='zidane.jpg', width=600)
```

Output:
```
image 1/2 /content/yolov5/yolov5/yolov5/yolov5/data/images/bus.jpg: Traceback (most recent call last):
  File "detect.py", line 228, in <module>
    main(opt)
  File "detect.py", line 223, in main
    run(**vars(opt))
  File "/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
    return func(*args, **kwargs)
  File "detect.py", line 106, in run
    visualize=increment_path(save_dir / Path(path).stem, mkdir=True) if visualize else False)[0]
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'visualize'
```
<img width="1093" alt="スクリーンショット 2021-07-12 1 31 10" src="https://user-images.githubusercontent.com/33506506/125202974-31f28c00-e2b1-11eb-8d50-ff518011c32e.png">


## Expected behavior
detect image with ensembling correctly.

## Environment
If applicable, add screenshots to help explain your problem.

google colab

https://colab.research.google.com/drive/1rXRjuFTiHdJwbxhSIY8EywwQMrg3zCbV?usp=sharing

 - OS: [e.g. Ubuntu]
 - GPU Tesla P100

## Additional context
I'm trying to fix it now. might be one day from now I will make pull request


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `models/experimental.py`
Content:
```
1 # YOLOv5 experimental modules
2 
3 import numpy as np
4 import torch
5 import torch.nn as nn
6 
7 from models.common import Conv, DWConv
8 from utils.google_utils import attempt_download
9 
10 
11 class CrossConv(nn.Module):
12     # Cross Convolution Downsample
13     def __init__(self, c1, c2, k=3, s=1, g=1, e=1.0, shortcut=False):
14         # ch_in, ch_out, kernel, stride, groups, expansion, shortcut
15         super(CrossConv, self).__init__()
16         c_ = int(c2 * e)  # hidden channels
17         self.cv1 = Conv(c1, c_, (1, k), (1, s))
18         self.cv2 = Conv(c_, c2, (k, 1), (s, 1), g=g)
19         self.add = shortcut and c1 == c2
20 
21     def forward(self, x):
22         return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))
23 
24 
25 class Sum(nn.Module):
26     # Weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070
27     def __init__(self, n, weight=False):  # n: number of inputs
28         super(Sum, self).__init__()
29         self.weight = weight  # apply weights boolean
30         self.iter = range(n - 1)  # iter object
31         if weight:
32             self.w = nn.Parameter(-torch.arange(1., n) / 2, requires_grad=True)  # layer weights
33 
34     def forward(self, x):
35         y = x[0]  # no weight
36         if self.weight:
37             w = torch.sigmoid(self.w) * 2
38             for i in self.iter:
39                 y = y + x[i + 1] * w[i]
40         else:
41             for i in self.iter:
42                 y = y + x[i + 1]
43         return y
44 
45 
46 class GhostConv(nn.Module):
47     # Ghost Convolution https://github.com/huawei-noah/ghostnet
48     def __init__(self, c1, c2, k=1, s=1, g=1, act=True):  # ch_in, ch_out, kernel, stride, groups
49         super(GhostConv, self).__init__()
50         c_ = c2 // 2  # hidden channels
51         self.cv1 = Conv(c1, c_, k, s, None, g, act)
52         self.cv2 = Conv(c_, c_, 5, 1, None, c_, act)
53 
54     def forward(self, x):
55         y = self.cv1(x)
56         return torch.cat([y, self.cv2(y)], 1)
57 
58 
59 class GhostBottleneck(nn.Module):
60     # Ghost Bottleneck https://github.com/huawei-noah/ghostnet
61     def __init__(self, c1, c2, k=3, s=1):  # ch_in, ch_out, kernel, stride
62         super(GhostBottleneck, self).__init__()
63         c_ = c2 // 2
64         self.conv = nn.Sequential(GhostConv(c1, c_, 1, 1),  # pw
65                                   DWConv(c_, c_, k, s, act=False) if s == 2 else nn.Identity(),  # dw
66                                   GhostConv(c_, c2, 1, 1, act=False))  # pw-linear
67         self.shortcut = nn.Sequential(DWConv(c1, c1, k, s, act=False),
68                                       Conv(c1, c2, 1, 1, act=False)) if s == 2 else nn.Identity()
69 
70     def forward(self, x):
71         return self.conv(x) + self.shortcut(x)
72 
73 
74 class MixConv2d(nn.Module):
75     # Mixed Depthwise Conv https://arxiv.org/abs/1907.09595
76     def __init__(self, c1, c2, k=(1, 3), s=1, equal_ch=True):
77         super(MixConv2d, self).__init__()
78         groups = len(k)
79         if equal_ch:  # equal c_ per group
80             i = torch.linspace(0, groups - 1E-6, c2).floor()  # c2 indices
81             c_ = [(i == g).sum() for g in range(groups)]  # intermediate channels
82         else:  # equal weight.numel() per group
83             b = [c2] + [0] * groups
84             a = np.eye(groups + 1, groups, k=-1)
85             a -= np.roll(a, 1, axis=1)
86             a *= np.array(k) ** 2
87             a[0] = 1
88             c_ = np.linalg.lstsq(a, b, rcond=None)[0].round()  # solve for equal weight indices, ax = b
89 
90         self.m = nn.ModuleList([nn.Conv2d(c1, int(c_[g]), k[g], s, k[g] // 2, bias=False) for g in range(groups)])
91         self.bn = nn.BatchNorm2d(c2)
92         self.act = nn.LeakyReLU(0.1, inplace=True)
93 
94     def forward(self, x):
95         return x + self.act(self.bn(torch.cat([m(x) for m in self.m], 1)))
96 
97 
98 class Ensemble(nn.ModuleList):
99     # Ensemble of models
100     def __init__(self):
101         super(Ensemble, self).__init__()
102 
103     def forward(self, x, augment=False):
104         y = []
105         for module in self:
106             y.append(module(x, augment)[0])
107         # y = torch.stack(y).max(0)[0]  # max ensemble
108         # y = torch.stack(y).mean(0)  # mean ensemble
109         y = torch.cat(y, 1)  # nms ensemble
110         return y, None  # inference, train output
111 
112 
113 def attempt_load(weights, map_location=None, inplace=True):
114     from models.yolo import Detect, Model
115 
116     # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a
117     model = Ensemble()
118     for w in weights if isinstance(weights, list) else [weights]:
119         ckpt = torch.load(attempt_download(w), map_location=map_location)  # load
120         model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval())  # FP32 model
121 
122     # Compatibility updates
123     for m in model.modules():
124         if type(m) in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model]:
125             m.inplace = inplace  # pytorch 1.7.0 compatibility
126         elif type(m) is Conv:
127             m._non_persistent_buffers_set = set()  # pytorch 1.6.0 compatibility
128 
129     if len(model) == 1:
130         return model[-1]  # return model
131     else:
132         print(f'Ensemble created with {weights}\n')
133         for k in ['names']:
134             setattr(model, k, getattr(model[-1], k))
135         model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride  # max stride
136         return model  # return ensemble
137
```
--- 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/models/experimental.py b/models/experimental.py
--- a/models/experimental.py
+++ b/models/experimental.py
@@ -100,10 +100,10 @@
     def __init__(self):
         super(Ensemble, self).__init__()
 
-    def forward(self, x, augment=False):
+    def forward(self, x, augment=False, profile=False, visualize=False):
         y = []
         for module in self:
-            y.append(module(x, augment)[0])
+            y.append(module(x, augment, profile, visualize)[0])
         # y = torch.stack(y).max(0)[0]  # max ensemble
         # y = torch.stack(y).mean(0)  # mean ensemble
         y = torch.cat(y, 1)  # nms ensemble

{"golden_diff": "diff --git a/models/experimental.py b/models/experimental.py\n--- a/models/experimental.py\n+++ b/models/experimental.py\n@@ -100,10 +100,10 @@\n     def __init__(self):\n         super(Ensemble, self).__init__()\n \n-    def forward(self, x, augment=False):\n+    def forward(self, x, augment=False, profile=False, visualize=False):\n         y = []\n         for module in self:\n-            y.append(module(x, augment)[0])\n+            y.append(module(x, augment, profile, visualize)[0])\n         # y = torch.stack(y).max(0)[0]  # max ensemble\n         # y = torch.stack(y).mean(0)  # mean ensemble\n         y = torch.cat(y, 1)  # nms ensemble\n", "issue": "model ensembling isn't working\n## \ud83d\udc1b Bug\r\nWhen I detect some image by using ensembling, it doesn't work.\r\n\r\n## To Reproduce (REQUIRED)\r\nInput:\r\n```\r\n!git clone https://github.com/ultralytics/yolov5  # clone repo\r\n%cd yolov5\r\n%pip install -qr requirements.txt  # install dependencies\r\n\r\nimport torch\r\nfrom IPython.display import Image, clear_output  # to display images\r\nimport urllib\r\n\r\nclear_output()\r\nprint(f\"Setup complete. Using torch {torch.__version__} ({torch.cuda.get_device_properties(0).name if torch.cuda.is_available() else 'CPU'})\")\r\n\r\ndef download_file(url, dst_path):\r\n    try:\r\n        with urllib.request.urlopen(url) as web_file:\r\n            data = web_file.read()\r\n            with open(dst_path, mode='wb') as local_file:\r\n                local_file.write(data)\r\n    except urllib.error.URLError as e:\r\n        print(e)\r\n\r\ndownload_file('https://user-images.githubusercontent.com/26833433/124489091-ea4f9a00-ddb0-11eb-8ef1-d6f335c97f6f.jpg', \"zidane.jpg\")\r\n\r\n!python detect.py --weights yolov5x.pt yolov5s.pt --img 640 --conf 0.25 --source data/images/\r\nImage(filename='zidane.jpg', width=600)\r\n```\r\n\r\nOutput:\r\n```\r\nimage 1/2 /content/yolov5/yolov5/yolov5/yolov5/data/images/bus.jpg: Traceback (most recent call last):\r\n  File \"detect.py\", line 228, in <module>\r\n    main(opt)\r\n  File \"detect.py\", line 223, in main\r\n    run(**vars(opt))\r\n  File \"/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py\", line 28, in decorate_context\r\n    return func(*args, **kwargs)\r\n  File \"detect.py\", line 106, in run\r\n    visualize=increment_path(save_dir / Path(path).stem, mkdir=True) if visualize else False)[0]\r\n  File \"/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py\", line 1051, in _call_impl\r\n    return forward_call(*input, **kwargs)\r\nTypeError: forward() got an unexpected keyword argument 'visualize'\r\n```\r\n<img width=\"1093\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-07-12 1 31 10\" src=\"https://user-images.githubusercontent.com/33506506/125202974-31f28c00-e2b1-11eb-8d50-ff518011c32e.png\">\r\n\r\n\r\n## Expected behavior\r\ndetect image with ensembling correctly.\r\n\r\n## Environment\r\nIf applicable, add screenshots to help explain your problem.\r\n\r\ngoogle colab\r\n\r\nhttps://colab.research.google.com/drive/1rXRjuFTiHdJwbxhSIY8EywwQMrg3zCbV?usp=sharing\r\n\r\n - OS: [e.g. Ubuntu]\r\n - GPU Tesla P100\r\n\r\n## Additional context\r\nI'm trying to fix it now. might be one day from now I will make pull request\r\n\n", "before_files": [{"content": "# YOLOv5 experimental modules\n\nimport numpy as np\nimport torch\nimport torch.nn as nn\n\nfrom models.common import Conv, DWConv\nfrom utils.google_utils import attempt_download\n\n\nclass CrossConv(nn.Module):\n    # Cross Convolution Downsample\n    def __init__(self, c1, c2, k=3, s=1, g=1, e=1.0, shortcut=False):\n        # ch_in, ch_out, kernel, stride, groups, expansion, shortcut\n        super(CrossConv, self).__init__()\n        c_ = int(c2 * e)  # hidden channels\n        self.cv1 = Conv(c1, c_, (1, k), (1, s))\n        self.cv2 = Conv(c_, c2, (k, 1), (s, 1), g=g)\n        self.add = shortcut and c1 == c2\n\n    def forward(self, x):\n        return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))\n\n\nclass Sum(nn.Module):\n    # Weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070\n    def __init__(self, n, weight=False):  # n: number of inputs\n        super(Sum, self).__init__()\n        self.weight = weight  # apply weights boolean\n        self.iter = range(n - 1)  # iter object\n        if weight:\n            self.w = nn.Parameter(-torch.arange(1., n) / 2, requires_grad=True)  # layer weights\n\n    def forward(self, x):\n        y = x[0]  # no weight\n        if self.weight:\n            w = torch.sigmoid(self.w) * 2\n            for i in self.iter:\n                y = y + x[i + 1] * w[i]\n        else:\n            for i in self.iter:\n                y = y + x[i + 1]\n        return y\n\n\nclass GhostConv(nn.Module):\n    # Ghost Convolution https://github.com/huawei-noah/ghostnet\n    def __init__(self, c1, c2, k=1, s=1, g=1, act=True):  # ch_in, ch_out, kernel, stride, groups\n        super(GhostConv, self).__init__()\n        c_ = c2 // 2  # hidden channels\n        self.cv1 = Conv(c1, c_, k, s, None, g, act)\n        self.cv2 = Conv(c_, c_, 5, 1, None, c_, act)\n\n    def forward(self, x):\n        y = self.cv1(x)\n        return torch.cat([y, self.cv2(y)], 1)\n\n\nclass GhostBottleneck(nn.Module):\n    # Ghost Bottleneck https://github.com/huawei-noah/ghostnet\n    def __init__(self, c1, c2, k=3, s=1):  # ch_in, ch_out, kernel, stride\n        super(GhostBottleneck, self).__init__()\n        c_ = c2 // 2\n        self.conv = nn.Sequential(GhostConv(c1, c_, 1, 1),  # pw\n                                  DWConv(c_, c_, k, s, act=False) if s == 2 else nn.Identity(),  # dw\n                                  GhostConv(c_, c2, 1, 1, act=False))  # pw-linear\n        self.shortcut = nn.Sequential(DWConv(c1, c1, k, s, act=False),\n                                      Conv(c1, c2, 1, 1, act=False)) if s == 2 else nn.Identity()\n\n    def forward(self, x):\n        return self.conv(x) + self.shortcut(x)\n\n\nclass MixConv2d(nn.Module):\n    # Mixed Depthwise Conv https://arxiv.org/abs/1907.09595\n    def __init__(self, c1, c2, k=(1, 3), s=1, equal_ch=True):\n        super(MixConv2d, self).__init__()\n        groups = len(k)\n        if equal_ch:  # equal c_ per group\n            i = torch.linspace(0, groups - 1E-6, c2).floor()  # c2 indices\n            c_ = [(i == g).sum() for g in range(groups)]  # intermediate channels\n        else:  # equal weight.numel() per group\n            b = [c2] + [0] * groups\n            a = np.eye(groups + 1, groups, k=-1)\n            a -= np.roll(a, 1, axis=1)\n            a *= np.array(k) ** 2\n            a[0] = 1\n            c_ = np.linalg.lstsq(a, b, rcond=None)[0].round()  # solve for equal weight indices, ax = b\n\n        self.m = nn.ModuleList([nn.Conv2d(c1, int(c_[g]), k[g], s, k[g] // 2, bias=False) for g in range(groups)])\n        self.bn = nn.BatchNorm2d(c2)\n        self.act = nn.LeakyReLU(0.1, inplace=True)\n\n    def forward(self, x):\n        return x + self.act(self.bn(torch.cat([m(x) for m in self.m], 1)))\n\n\nclass Ensemble(nn.ModuleList):\n    # Ensemble of models\n    def __init__(self):\n        super(Ensemble, self).__init__()\n\n    def forward(self, x, augment=False):\n        y = []\n        for module in self:\n            y.append(module(x, augment)[0])\n        # y = torch.stack(y).max(0)[0]  # max ensemble\n        # y = torch.stack(y).mean(0)  # mean ensemble\n        y = torch.cat(y, 1)  # nms ensemble\n        return y, None  # inference, train output\n\n\ndef attempt_load(weights, map_location=None, inplace=True):\n    from models.yolo import Detect, Model\n\n    # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a\n    model = Ensemble()\n    for w in weights if isinstance(weights, list) else [weights]:\n        ckpt = torch.load(attempt_download(w), map_location=map_location)  # load\n        model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval())  # FP32 model\n\n    # Compatibility updates\n    for m in model.modules():\n        if type(m) in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model]:\n            m.inplace = inplace  # pytorch 1.7.0 compatibility\n        elif type(m) is Conv:\n            m._non_persistent_buffers_set = set()  # pytorch 1.6.0 compatibility\n\n    if len(model) == 1:\n        return model[-1]  # return model\n    else:\n        print(f'Ensemble created with {weights}\\n')\n        for k in ['names']:\n            setattr(model, k, getattr(model[-1], k))\n        model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride  # max stride\n        return model  # return ensemble\n", "path": "models/experimental.py"}], "after_files": [{"content": "# YOLOv5 experimental modules\n\nimport numpy as np\nimport torch\nimport torch.nn as nn\n\nfrom models.common import Conv, DWConv\nfrom utils.google_utils import attempt_download\n\n\nclass CrossConv(nn.Module):\n    # Cross Convolution Downsample\n    def __init__(self, c1, c2, k=3, s=1, g=1, e=1.0, shortcut=False):\n        # ch_in, ch_out, kernel, stride, groups, expansion, shortcut\n        super(CrossConv, self).__init__()\n        c_ = int(c2 * e)  # hidden channels\n        self.cv1 = Conv(c1, c_, (1, k), (1, s))\n        self.cv2 = Conv(c_, c2, (k, 1), (s, 1), g=g)\n        self.add = shortcut and c1 == c2\n\n    def forward(self, x):\n        return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))\n\n\nclass Sum(nn.Module):\n    # Weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070\n    def __init__(self, n, weight=False):  # n: number of inputs\n        super(Sum, self).__init__()\n        self.weight = weight  # apply weights boolean\n        self.iter = range(n - 1)  # iter object\n        if weight:\n            self.w = nn.Parameter(-torch.arange(1., n) / 2, requires_grad=True)  # layer weights\n\n    def forward(self, x):\n        y = x[0]  # no weight\n        if self.weight:\n            w = torch.sigmoid(self.w) * 2\n            for i in self.iter:\n                y = y + x[i + 1] * w[i]\n        else:\n            for i in self.iter:\n                y = y + x[i + 1]\n        return y\n\n\nclass GhostConv(nn.Module):\n    # Ghost Convolution https://github.com/huawei-noah/ghostnet\n    def __init__(self, c1, c2, k=1, s=1, g=1, act=True):  # ch_in, ch_out, kernel, stride, groups\n        super(GhostConv, self).__init__()\n        c_ = c2 // 2  # hidden channels\n        self.cv1 = Conv(c1, c_, k, s, None, g, act)\n        self.cv2 = Conv(c_, c_, 5, 1, None, c_, act)\n\n    def forward(self, x):\n        y = self.cv1(x)\n        return torch.cat([y, self.cv2(y)], 1)\n\n\nclass GhostBottleneck(nn.Module):\n    # Ghost Bottleneck https://github.com/huawei-noah/ghostnet\n    def __init__(self, c1, c2, k=3, s=1):  # ch_in, ch_out, kernel, stride\n        super(GhostBottleneck, self).__init__()\n        c_ = c2 // 2\n        self.conv = nn.Sequential(GhostConv(c1, c_, 1, 1),  # pw\n                                  DWConv(c_, c_, k, s, act=False) if s == 2 else nn.Identity(),  # dw\n                                  GhostConv(c_, c2, 1, 1, act=False))  # pw-linear\n        self.shortcut = nn.Sequential(DWConv(c1, c1, k, s, act=False),\n                                      Conv(c1, c2, 1, 1, act=False)) if s == 2 else nn.Identity()\n\n    def forward(self, x):\n        return self.conv(x) + self.shortcut(x)\n\n\nclass MixConv2d(nn.Module):\n    # Mixed Depthwise Conv https://arxiv.org/abs/1907.09595\n    def __init__(self, c1, c2, k=(1, 3), s=1, equal_ch=True):\n        super(MixConv2d, self).__init__()\n        groups = len(k)\n        if equal_ch:  # equal c_ per group\n            i = torch.linspace(0, groups - 1E-6, c2).floor()  # c2 indices\n            c_ = [(i == g).sum() for g in range(groups)]  # intermediate channels\n        else:  # equal weight.numel() per group\n            b = [c2] + [0] * groups\n            a = np.eye(groups + 1, groups, k=-1)\n            a -= np.roll(a, 1, axis=1)\n            a *= np.array(k) ** 2\n            a[0] = 1\n            c_ = np.linalg.lstsq(a, b, rcond=None)[0].round()  # solve for equal weight indices, ax = b\n\n        self.m = nn.ModuleList([nn.Conv2d(c1, int(c_[g]), k[g], s, k[g] // 2, bias=False) for g in range(groups)])\n        self.bn = nn.BatchNorm2d(c2)\n        self.act = nn.LeakyReLU(0.1, inplace=True)\n\n    def forward(self, x):\n        return x + self.act(self.bn(torch.cat([m(x) for m in self.m], 1)))\n\n\nclass Ensemble(nn.ModuleList):\n    # Ensemble of models\n    def __init__(self):\n        super(Ensemble, self).__init__()\n\n    def forward(self, x, augment=False, profile=False, visualize=False):\n        y = []\n        for module in self:\n            y.append(module(x, augment, profile, visualize)[0])\n        # y = torch.stack(y).max(0)[0]  # max ensemble\n        # y = torch.stack(y).mean(0)  # mean ensemble\n        y = torch.cat(y, 1)  # nms ensemble\n        return y, None  # inference, train output\n\n\ndef attempt_load(weights, map_location=None, inplace=True):\n    from models.yolo import Detect, Model\n\n    # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a\n    model = Ensemble()\n    for w in weights if isinstance(weights, list) else [weights]:\n        ckpt = torch.load(attempt_download(w), map_location=map_location)  # load\n        model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval())  # FP32 model\n\n    # Compatibility updates\n    for m in model.modules():\n        if type(m) in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model]:\n            m.inplace = inplace  # pytorch 1.7.0 compatibility\n        elif type(m) is Conv:\n            m._non_persistent_buffers_set = set()  # pytorch 1.6.0 compatibility\n\n    if len(model) == 1:\n        return model[-1]  # return model\n    else:\n        print(f'Ensemble created with {weights}\\n')\n        for k in ['names']:\n            setattr(model, k, getattr(model[-1], k))\n        model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride  # max stride\n        return model  # return ensemble\n", "path": "models/experimental.py"}]}