Skip to content

Commit f5b8f7d

Browse files
authored
YOLOv5 v5.0 Release (#2762)
1 parent e2b7bc0 commit f5b8f7d

File tree

3 files changed

+66
-75
lines changed

3 files changed

+66
-75
lines changed

README.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,43 @@
66

77
This repository represents Ultralytics open-source research into future object detection methods, and incorporates lessons learned and best practices evolved over thousands of hours of training and evolution on anonymized client datasets. **All code and models are under active development, and are subject to modification or deletion without notice.** Use at your own risk.
88

9-
<p align="center"><img width="800" src="https://user-images.githubusercontent.com/26833433/103594689-455e0e00-4eae-11eb-9cdf-7d753e2ceeeb.png"></p>
9+
<p align="center"><img width="800" src="https://user-images.githubusercontent.com/26833433/114313216-f0a5e100-9af5-11eb-8445-c682b60da2e3.png"></p>
10+
<details>
11+
<summary>YOLOv5-P5 640 Figure (click to expand)</summary>
12+
13+
<p align="center"><img width="800" src="https://user-images.githubusercontent.com/26833433/114313219-f1d70e00-9af5-11eb-9973-52b1f98d321a.png"></p>
14+
</details>
1015
<details>
1116
<summary>Figure Notes (click to expand)</summary>
1217

1318
* GPU Speed measures end-to-end time per image averaged over 5000 COCO val2017 images using a V100 GPU with batch size 32, and includes image preprocessing, PyTorch FP16 inference, postprocessing and NMS.
1419
* EfficientDet data from [google/automl](https://github.com/google/automl) at batch size 8.
20+
* **Reproduce** by `python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s6.pt yolov5m6.pt yolov5l6.pt yolov5x6.pt`
1521
</details>
1622

23+
- **April 11, 2021**: [v5.0 release](https://github.com/ultralytics/yolov5/releases/tag/v5.0): YOLOv5-P6 1280 models, [AWS](https://github.com/ultralytics/yolov5/wiki/AWS-Quickstart), [Supervise.ly](https://github.com/ultralytics/yolov5/issues/2518) and [YouTube](https://github.com/ultralytics/yolov5/pull/2752) integrations.
1724
- **January 5, 2021**: [v4.0 release](https://github.com/ultralytics/yolov5/releases/tag/v4.0): nn.SiLU() activations, [Weights & Biases](https://wandb.ai/site?utm_campaign=repo_yolo_readme) logging, [PyTorch Hub](https://pytorch.org/hub/ultralytics_yolov5/) integration.
1825
- **August 13, 2020**: [v3.0 release](https://github.com/ultralytics/yolov5/releases/tag/v3.0): nn.Hardswish() activations, data autodownload, native AMP.
1926
- **July 23, 2020**: [v2.0 release](https://github.com/ultralytics/yolov5/releases/tag/v2.0): improved model definition, training and mAP.
20-
- **June 22, 2020**: [PANet](https://arxiv.org/abs/1803.01534) updates: new heads, reduced parameters, improved speed and mAP [364fcfd](https://github.com/ultralytics/yolov5/commit/364fcfd7dba53f46edd4f04c037a039c0a287972).
21-
- **June 19, 2020**: [FP16](https://pytorch.org/docs/stable/nn.html#torch.nn.Module.half) as new default for smaller checkpoints and faster inference [d4c6674](https://github.com/ultralytics/yolov5/commit/d4c6674c98e19df4c40e33a777610a18d1961145).
2227

2328

2429
## Pretrained Checkpoints
2530

26-
| Model | size | AP<sup>val</sup> | AP<sup>test</sup> | AP<sub>50</sub> | Speed<sub>V100</sub> | FPS<sub>V100</sub> || params | GFLOPS |
27-
|---------- |------ |------ |------ |------ | -------- | ------| ------ |------ | :------: |
28-
| [YOLOv5s](https://github.com/ultralytics/yolov5/releases) |640 |36.8 |36.8 |55.6 |**2.2ms** |**455** ||7.3M |17.0
29-
| [YOLOv5m](https://github.com/ultralytics/yolov5/releases) |640 |44.5 |44.5 |63.1 |2.9ms |345 ||21.4M |51.3
30-
| [YOLOv5l](https://github.com/ultralytics/yolov5/releases) |640 |48.1 |48.1 |66.4 |3.8ms |264 ||47.0M |115.4
31-
| [YOLOv5x](https://github.com/ultralytics/yolov5/releases) |640 |**50.1** |**50.1** |**68.7** |6.0ms |167 ||87.7M |218.8
32-
| | | | | | | || |
33-
| [YOLOv5x](https://github.com/ultralytics/yolov5/releases) + TTA |832 |**51.9** |**51.9** |**69.6** |24.9ms |40 ||87.7M |1005.3
34-
35-
<!---
36-
| [YOLOv5l6](https://github.com/ultralytics/yolov5/releases) |640 |49.0 |49.0 |67.4 |4.1ms |244 ||77.2M |117.7
37-
| [YOLOv5l6](https://github.com/ultralytics/yolov5/releases) |1280 |53.0 |53.0 |70.8 |12.3ms |81 ||77.2M |117.7
38-
--->
31+
[assets]: https://github.com/ultralytics/yolov5/releases
32+
33+
Model |size<br><sup>(pixels) |mAP<sup>val<br>0.5:0.95 |mAP<sup>test<br>0.5:0.95 |mAP<sup>val<br>0.5 |Speed<br><sup>V100 (ms) | |params<br><sup>(M) |FLOPS<br><sup>640 (B)
34+
--- |--- |--- |--- |--- |--- |---|--- |---
35+
[YOLOv5s][assets] |640 |36.7 |36.7 |55.4 |**2.0** | |7.3 |17.0
36+
[YOLOv5m][assets] |640 |44.5 |44.5 |63.3 |2.7 | |21.4 |51.3
37+
[YOLOv5l][assets] |640 |48.2 |48.2 |66.9 |3.8 | |47.0 |115.4
38+
[YOLOv5x][assets] |640 |**50.4** |**50.4** |**68.8** |6.1 | |87.7 |218.8
39+
| | | | | | || |
40+
[YOLOv5s6][assets] |1280 |43.3 |43.3 |61.9 |**4.3** | |12.7 |17.4
41+
[YOLOv5m6][assets] |1280 |50.5 |50.5 |68.7 |8.4 | |35.9 |52.4
42+
[YOLOv5l6][assets] |1280 |53.4 |53.4 |71.1 |12.3 | |77.2 |117.7
43+
[YOLOv5x6][assets] |1280 |**54.4** |**54.4** |**72.0** |22.4 | |141.8 |222.9
44+
| | | | | | || |
45+
[YOLOv5x6][assets] TTA |1280 |**55.0** |**55.0** |**72.0** |70.8 | |- |-
3946

4047
<details>
4148
<summary>Table Notes (click to expand)</summary>
@@ -44,7 +51,7 @@ This repository represents Ultralytics open-source research into future object d
4451
* AP values are for single-model single-scale unless otherwise noted. **Reproduce mAP** by `python test.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65`
4552
* Speed<sub>GPU</sub> averaged over 5000 COCO val2017 images using a GCP [n1-standard-16](https://cloud.google.com/compute/docs/machine-types#n1_standard_machine_types) V100 instance, and includes FP16 inference, postprocessing and NMS. **Reproduce speed** by `python test.py --data coco.yaml --img 640 --conf 0.25 --iou 0.45`
4653
* All checkpoints are trained to 300 epochs with default settings and hyperparameters (no autoaugmentation).
47-
* Test Time Augmentation ([TTA](https://github.com/ultralytics/yolov5/issues/303)) includes reflection and scale augmentation. **Reproduce TTA** by `python test.py --data coco.yaml --img 832 --iou 0.65 --augment`
54+
* Test Time Augmentation ([TTA](https://github.com/ultralytics/yolov5/issues/303)) includes reflection and scale augmentation. **Reproduce TTA** by `python test.py --data coco.yaml --img 1536 --iou 0.7 --augment`
4855
</details>
4956

5057

@@ -85,7 +92,7 @@ YOLOv5 may be run in any of the following up-to-date verified environments (with
8592

8693
## Inference
8794

88-
detect.py runs inference on a variety of sources, downloading models automatically from the [latest YOLOv5 release](https://github.com/ultralytics/yolov5/releases) and saving results to `runs/detect`.
95+
`detect.py` runs inference on a variety of sources, downloading models automatically from the [latest YOLOv5 release](https://github.com/ultralytics/yolov5/releases) and saving results to `runs/detect`.
8996
```bash
9097
$ python detect.py --source 0 # webcam
9198
file.jpg # image

hubconf.py

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -55,84 +55,68 @@ def create(name, pretrained, channels, classes, autoshape):
5555
raise Exception(s) from e
5656

5757

58-
def yolov5s(pretrained=True, channels=3, classes=80, autoshape=True):
59-
"""YOLOv5-small model from https://github.com/ultralytics/yolov5
58+
def custom(path_or_model='path/to/model.pt', autoshape=True):
59+
"""YOLOv5-custom model https://github.com/ultralytics/yolov5
6060
61-
Arguments:
62-
pretrained (bool): load pretrained weights into the model, default=False
63-
channels (int): number of input channels, default=3
64-
classes (int): number of model classes, default=80
61+
Arguments (3 options):
62+
path_or_model (str): 'path/to/model.pt'
63+
path_or_model (dict): torch.load('path/to/model.pt')
64+
path_or_model (nn.Module): torch.load('path/to/model.pt')['model']
6565
6666
Returns:
6767
pytorch model
6868
"""
69-
return create('yolov5s', pretrained, channels, classes, autoshape)
69+
model = torch.load(path_or_model) if isinstance(path_or_model, str) else path_or_model # load checkpoint
70+
if isinstance(model, dict):
71+
model = model['ema' if model.get('ema') else 'model'] # load model
7072

73+
hub_model = Model(model.yaml).to(next(model.parameters()).device) # create
74+
hub_model.load_state_dict(model.float().state_dict()) # load state_dict
75+
hub_model.names = model.names # class names
76+
if autoshape:
77+
hub_model = hub_model.autoshape() # for file/URI/PIL/cv2/np inputs and NMS
78+
device = select_device('0' if torch.cuda.is_available() else 'cpu') # default to GPU if available
79+
return hub_model.to(device)
7180

72-
def yolov5m(pretrained=True, channels=3, classes=80, autoshape=True):
73-
"""YOLOv5-medium model from https://github.com/ultralytics/yolov5
7481

75-
Arguments:
76-
pretrained (bool): load pretrained weights into the model, default=False
77-
channels (int): number of input channels, default=3
78-
classes (int): number of model classes, default=80
82+
def yolov5s(pretrained=True, channels=3, classes=80, autoshape=True):
83+
# YOLOv5-small model https://github.com/ultralytics/yolov5
84+
return create('yolov5s', pretrained, channels, classes, autoshape)
7985

80-
Returns:
81-
pytorch model
82-
"""
86+
87+
def yolov5m(pretrained=True, channels=3, classes=80, autoshape=True):
88+
# YOLOv5-medium model https://github.com/ultralytics/yolov5
8389
return create('yolov5m', pretrained, channels, classes, autoshape)
8490

8591

8692
def yolov5l(pretrained=True, channels=3, classes=80, autoshape=True):
87-
"""YOLOv5-large model from https://github.com/ultralytics/yolov5
88-
89-
Arguments:
90-
pretrained (bool): load pretrained weights into the model, default=False
91-
channels (int): number of input channels, default=3
92-
classes (int): number of model classes, default=80
93-
94-
Returns:
95-
pytorch model
96-
"""
93+
# YOLOv5-large model https://github.com/ultralytics/yolov5
9794
return create('yolov5l', pretrained, channels, classes, autoshape)
9895

9996

10097
def yolov5x(pretrained=True, channels=3, classes=80, autoshape=True):
101-
"""YOLOv5-xlarge model from https://github.com/ultralytics/yolov5
98+
# YOLOv5-xlarge model https://github.com/ultralytics/yolov5
99+
return create('yolov5x', pretrained, channels, classes, autoshape)
102100

103-
Arguments:
104-
pretrained (bool): load pretrained weights into the model, default=False
105-
channels (int): number of input channels, default=3
106-
classes (int): number of model classes, default=80
107101

108-
Returns:
109-
pytorch model
110-
"""
111-
return create('yolov5x', pretrained, channels, classes, autoshape)
102+
def yolov5s6(pretrained=True, channels=3, classes=80, autoshape=True):
103+
# YOLOv5-small model https://github.com/ultralytics/yolov5
104+
return create('yolov5s6', pretrained, channels, classes, autoshape)
112105

113106

114-
def custom(path_or_model='path/to/model.pt', autoshape=True):
115-
"""YOLOv5-custom model from https://github.com/ultralytics/yolov5
107+
def yolov5m6(pretrained=True, channels=3, classes=80, autoshape=True):
108+
# YOLOv5-medium model https://github.com/ultralytics/yolov5
109+
return create('yolov5m6', pretrained, channels, classes, autoshape)
116110

117-
Arguments (3 options):
118-
path_or_model (str): 'path/to/model.pt'
119-
path_or_model (dict): torch.load('path/to/model.pt')
120-
path_or_model (nn.Module): torch.load('path/to/model.pt')['model']
121111

122-
Returns:
123-
pytorch model
124-
"""
125-
model = torch.load(path_or_model) if isinstance(path_or_model, str) else path_or_model # load checkpoint
126-
if isinstance(model, dict):
127-
model = model['ema' if model.get('ema') else 'model'] # load model
112+
def yolov5l6(pretrained=True, channels=3, classes=80, autoshape=True):
113+
# YOLOv5-large model https://github.com/ultralytics/yolov5
114+
return create('yolov5l6', pretrained, channels, classes, autoshape)
128115

129-
hub_model = Model(model.yaml).to(next(model.parameters()).device) # create
130-
hub_model.load_state_dict(model.float().state_dict()) # load state_dict
131-
hub_model.names = model.names # class names
132-
if autoshape:
133-
hub_model = hub_model.autoshape() # for file/URI/PIL/cv2/np inputs and NMS
134-
device = select_device('0' if torch.cuda.is_available() else 'cpu') # default to GPU if available
135-
return hub_model.to(device)
116+
117+
def yolov5x6(pretrained=True, channels=3, classes=80, autoshape=True):
118+
# YOLOv5-xlarge model https://github.com/ultralytics/yolov5
119+
return create('yolov5x6', pretrained, channels, classes, autoshape)
136120

137121

138122
if __name__ == '__main__':

utils/plots.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def plot_study_txt(path='', x=None): # from utils.plots import *; plot_study_tx
243243
# ax = ax.ravel()
244244

245245
fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True)
246-
# for f in [Path(path) / f'study_coco_{x}.txt' for x in ['yolov5s', 'yolov5m', 'yolov5l', 'yolov5x']]:
246+
# for f in [Path(path) / f'study_coco_{x}.txt' for x in ['yolov5s6', 'yolov5m6', 'yolov5l6', 'yolov5x6']]:
247247
for f in sorted(Path(path).glob('study*.txt')):
248248
y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T
249249
x = np.arange(y.shape[1]) if x is None else np.array(x)
@@ -253,15 +253,15 @@ def plot_study_txt(path='', x=None): # from utils.plots import *; plot_study_tx
253253
# ax[i].set_title(s[i])
254254

255255
j = y[3].argmax() + 1
256-
ax2.plot(y[6, :j], y[3, :j] * 1E2, '.-', linewidth=2, markersize=8,
256+
ax2.plot(y[6, 1:j], y[3, 1:j] * 1E2, '.-', linewidth=2, markersize=8,
257257
label=f.stem.replace('study_coco_', '').replace('yolo', 'YOLO'))
258258

259259
ax2.plot(1E3 / np.array([209, 140, 97, 58, 35, 18]), [34.6, 40.5, 43.0, 47.5, 49.7, 51.5],
260260
'k.-', linewidth=2, markersize=8, alpha=.25, label='EfficientDet')
261261

262262
ax2.grid(alpha=0.2)
263263
ax2.set_yticks(np.arange(20, 60, 5))
264-
ax2.set_xlim(0, 30)
264+
ax2.set_xlim(0, 57)
265265
ax2.set_ylim(30, 55)
266266
ax2.set_xlabel('GPU Speed (ms/img)')
267267
ax2.set_ylabel('COCO AP val')

0 commit comments

Comments
 (0)