Skip to content

Commit 9969677

Browse files
glenn-jocherJoshua Friedrich
authored andcommitted
Merge develop branch into master (ultralytics#3518)
* update ci-testing.yml (ultralytics#3322) * update ci-testing.yml * update greetings.yml * bring back os matrix * update ci-testing.yml (ultralytics#3322) * update ci-testing.yml * update greetings.yml * bring back os matrix * Enable direct `--weights URL` definition (ultralytics#3373) * Enable direct `--weights URL` definition @kalenmike this PR will enable direct --weights URL definition. Example use case: ``` python train.py --weights https://storage.googleapis.com/bucket/dir/model.pt ``` * cleanup * bug fixes * weights = attempt_download(weights) * Update experimental.py * Update hubconf.py * return bug fix * comment mirror * min_bytes * Update tutorial.ipynb (ultralytics#3368) add Open in Kaggle badge * `cv2.imread(img, -1)` for IMREAD_UNCHANGED (ultralytics#3379) * Update datasets.py * comment Co-authored-by: Glenn Jocher <[email protected]> * COCO evolution fix (ultralytics#3388) * COCO evolution fix * cleanup * update print * print fix * Create `is_pip()` function (ultralytics#3391) Returns `True` if file is part of pip package. Useful for contextual behavior modification. ```python def is_pip(): # Is file in a pip package? return 'site-packages' in Path(__file__).absolute().parts ``` * Revert "`cv2.imread(img, -1)` for IMREAD_UNCHANGED (ultralytics#3379)" (ultralytics#3395) This reverts commit 21a9607. * Update FLOPs description (ultralytics#3422) * Update README.md * Changing FLOPS to FLOPs. Co-authored-by: BuildTools <[email protected]> * Parse URL authentication (ultralytics#3424) * Parse URL authentication * urllib.parse.unquote() * improved error handling * improved error handling * remove %3F * update check_file() * Add FLOPs title to table (ultralytics#3453) * Suppress jit trace warning + graph once (ultralytics#3454) * Suppress jit trace warning + graph once Suppress harmless jit trace warning on TensorBoard add_graph call. Also fix multiple add_graph() calls bug, now only on batch 0. * Update train.py * Update MixUp augmentation `alpha=beta=32.0` (ultralytics#3455) Per VOC empirical results ultralytics#3380 (comment) by @developer0hye * Add `timeout()` class (ultralytics#3460) * Add `timeout()` class * rearrange order * Faster HSV augmentation (ultralytics#3462) remove datatype conversion process that can be skipped * Add `check_git_status()` 5 second timeout (ultralytics#3464) * Add check_git_status() 5 second timeout This should prevent the SSH Git bug that we were discussing @kalenmike * cleanup * replace timeout with check_output built-in timeout * Improved `check_requirements()` offline-handling (ultralytics#3466) Improve robustness of `check_requirements()` function to offline environments (do not attempt pip installs when offline). * Add `output_names` argument for ONNX export with dynamic axes (ultralytics#3456) * Add output names & dynamic axes for onnx export Add output_names and dynamic_axes names for all outputs in torch.onnx.export. The first four outputs of the model will have names output0, output1, output2, output3 * use first output only + cleanup Co-authored-by: Samridha Shrestha <[email protected]> Co-authored-by: Glenn Jocher <[email protected]> * Revert FP16 `test.py` and `detect.py` inference to FP32 default (ultralytics#3423) * fixed inference bug ,while use half precision * replace --use-half with --half * replace space and PEP8 in detect.py * PEP8 detect.py * update --half help comment * Update test.py * revert space Co-authored-by: Glenn Jocher <[email protected]> * Add additional links/resources to stale.yml message (ultralytics#3467) * Update stale.yml * cleanup * Update stale.yml * reformat * Update stale.yml HUB URL (ultralytics#3468) * Stale `github.actor` bug fix (ultralytics#3483) * Explicit `model.eval()` call `if opt.train=False` (ultralytics#3475) * call model.eval() when opt.train is False call model.eval() when opt.train is False * single-line if statement * cleanup Co-authored-by: Glenn Jocher <[email protected]> * check_requirements() exclude `opencv-python` (ultralytics#3495) Fix for 3rd party or contrib versions of installed OpenCV as in ultralytics#3494. * Earlier `assert` for cpu and half option (ultralytics#3508) * early assert for cpu and half option early assert for cpu and half option * Modified comment Modified comment * Update tutorial.ipynb (ultralytics#3510) * Reduce test.py results spacing (ultralytics#3511) * Update README.md (ultralytics#3512) * Update README.md Minor modifications * 850 width * Update greetings.yml revert greeting change as PRs will now merge to master. Co-authored-by: Piotr Skalski <[email protected]> Co-authored-by: SkalskiP <[email protected]> Co-authored-by: Peretz Cohen <[email protected]> Co-authored-by: tudoulei <[email protected]> Co-authored-by: chocosaj <[email protected]> Co-authored-by: BuildTools <[email protected]> Co-authored-by: Yonghye Kwon <[email protected]> Co-authored-by: Sam_S <[email protected]> Co-authored-by: Samridha Shrestha <[email protected]> Co-authored-by: edificewang <[email protected]> (cherry picked from commit f3c3d2c)
1 parent 238b924 commit 9969677

File tree

16 files changed

+187
-124
lines changed

16 files changed

+187
-124
lines changed

.github/workflows/ci-testing.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ name: CI CPU testing
22

33
on: # https://help.github.com/en/actions/reference/events-that-trigger-workflows
44
push:
5-
branches: [ master ]
5+
branches: [ master, develop ]
66
pull_request:
77
# The branches below must be a subset of the branches above
8-
branches: [ master ]
9-
schedule:
10-
- cron: '0 0 * * *' # Runs at 00:00 UTC every day
8+
branches: [ master, develop ]
119

1210
jobs:
1311
cpu-tests:

.github/workflows/stale.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,26 @@ jobs:
1010
- uses: actions/stale@v3
1111
with:
1212
repo-token: ${{ secrets.GITHUB_TOKEN }}
13-
stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
14-
stale-pr-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
13+
stale-issue-message: |
14+
👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.
15+
16+
Access additional [YOLOv5](https://ultralytics.com/yolov5) 🚀 resources:
17+
- **Wiki** – https://github.com/ultralytics/yolov5/wiki
18+
- **Tutorials** – https://github.com/ultralytics/yolov5#tutorials
19+
- **Docs** – https://docs.ultralytics.com
20+
21+
Access additional [Ultralytics](https://ultralytics.com) ⚡ resources:
22+
- **Ultralytics HUB** – https://ultralytics.com/pricing
23+
- **Vision API** – https://ultralytics.com/yolov5
24+
- **About Us** – https://ultralytics.com/about
25+
- **Join Our Team** – https://ultralytics.com/work
26+
- **Contact Us** – https://ultralytics.com/contact
27+
28+
Feel free to inform us of any other **issues** you discover or **feature requests** that come to mind in the future. Pull Requests (PRs) are also always welcomed!
29+
30+
Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!
31+
32+
stale-pr-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions YOLOv5 🚀 and Vision AI ⭐.'
1533
days-before-stale: 30
1634
days-before-close: 5
1735
exempt-issue-labels: 'documentation,tutorial'

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<a align="left" href="https://apps.apple.com/app/id1452689527" target="_blank">
2-
<img width="800" src="https://user-images.githubusercontent.com/26833433/98699617-a1595a00-2377-11eb-8145-fc674eb9b1a7.jpg"></a>
2+
<img width="850" src="https://user-images.githubusercontent.com/26833433/121094150-72607500-c7ee-11eb-9f39-1d9e4ce89a9e.jpg"></a>
33
&nbsp
44

55
<a href="https://github.com/ultralytics/yolov5/actions"><img src="https://github.com/ultralytics/yolov5/workflows/CI%20CPU%20testing/badge.svg" alt="CI CPU testing"></a>
@@ -30,19 +30,19 @@ This repository represents Ultralytics open-source research into future object d
3030

3131
[assets]: https://github.com/ultralytics/yolov5/releases
3232

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.1 |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
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.1 |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
3939
| | | | | | || |
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
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
4444
| | | | | | || |
45-
[YOLOv5x6][assets] TTA |1280 |**55.0** |**55.0** |**72.0** |70.8 | |- |-
45+
|[YOLOv5x6][assets] TTA |1280 |**55.0** |**55.0** |**72.0** |70.8 | |- |-
4646

4747
<details>
4848
<summary>Table Notes (click to expand)</summary>
@@ -112,7 +112,7 @@ Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, devi
112112
YOLOv5 v4.0-96-g83dc1b4 torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16160.5MB)
113113

114114
Fusing layers...
115-
Model Summary: 224 layers, 7266973 parameters, 0 gradients, 17.0 GFLOPS
115+
Model Summary: 224 layers, 7266973 parameters, 0 gradients, 17.0 GFLOPs
116116
image 1/2 /content/yolov5/data/images/bus.jpg: 640x480 4 persons, 1 bus, Done. (0.010s)
117117
image 2/2 /content/yolov5/data/images/zidane.jpg: 384x640 2 persons, 1 tie, Done. (0.011s)
118118
Results saved to runs/detect/exp2

detect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def detect(opt):
2828
# Initialize
2929
set_logging()
3030
device = select_device(opt.device)
31-
half = device.type != 'cpu' # half precision only supported on CUDA
31+
half = opt.half and device.type != 'cpu' # half precision only supported on CUDA
3232

3333
# Load model
3434
model = attempt_load(weights, map_location=device) # load FP32 model
@@ -172,6 +172,7 @@ def detect(opt):
172172
parser.add_argument('--line-thickness', default=3, type=int, help='bounding box thickness (pixels)')
173173
parser.add_argument('--hide-labels', default=False, action='store_true', help='hide labels')
174174
parser.add_argument('--hide-conf', default=False, action='store_true', help='hide confidences')
175+
parser.add_argument('--half', type=bool, default=False, help='use FP16 half-precision inference')
175176
opt = parser.parse_args()
176177
print(opt)
177178
check_requirements(exclude=('tensorboard', 'pycocotools', 'thop'))

hubconf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
4242
cfg = list((Path(__file__).parent / 'models').rglob(f'{name}.yaml'))[0] # model.yaml path
4343
model = Model(cfg, channels, classes) # create model
4444
if pretrained:
45-
attempt_download(fname) # download if not found locally
46-
ckpt = torch.load(fname, map_location=torch.device('cpu')) # load
45+
ckpt = torch.load(attempt_download(fname), map_location=torch.device('cpu')) # load
4746
msd = model.state_dict() # model state_dict
4847
csd = ckpt['model'].float().state_dict() # checkpoint state_dict as FP32
4948
csd = {k: v for k, v in csd.items() if msd[k].shape == v.shape} # filter

models/experimental.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ def attempt_load(weights, map_location=None, inplace=True):
116116
# Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a
117117
model = Ensemble()
118118
for w in weights if isinstance(weights, list) else [weights]:
119-
attempt_download(w)
120-
ckpt = torch.load(w, map_location=map_location) # load
119+
ckpt = torch.load(attempt_download(w), map_location=map_location) # load
121120
model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval()) # FP32 model
122121

123122
# Compatibility updates

models/export.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,19 @@
4444

4545
# Load PyTorch model
4646
device = select_device(opt.device)
47+
assert not (opt.device.lower() == 'cpu' and opt.half), '--half only compatible with GPU export, i.e. use --device 0'
4748
model = attempt_load(opt.weights, map_location=device) # load FP32 model
4849
labels = model.names
4950

50-
# Checks
51+
# Input
5152
gs = int(max(model.stride)) # grid size (max stride)
5253
opt.img_size = [check_img_size(x, gs) for x in opt.img_size] # verify img_size are gs-multiples
53-
assert not (opt.device.lower() == 'cpu' and opt.half), '--half only compatible with GPU export, i.e. use --device 0'
54-
55-
# Input
5654
img = torch.zeros(opt.batch_size, 3, *opt.img_size).to(device) # image size(1,3,320,192) iDetection
5755

5856
# Update model
5957
if opt.half:
6058
img, model = img.half(), model.half() # to FP16
61-
if opt.train:
62-
model.train() # training mode (no grid construction in Detect layer)
59+
model.train() if opt.train else model.eval() # training mode = no Detect() layer grid construction
6360
for k, m in model.named_modules():
6461
m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatibility
6562
if isinstance(m, models.common.Conv): # assign export-friendly activations
@@ -96,11 +93,14 @@
9693

9794
print(f'{prefix} starting export with onnx {onnx.__version__}...')
9895
f = opt.weights.replace('.pt', '.onnx') # filename
99-
torch.onnx.export(model, img, f, verbose=False, opset_version=opt.opset_version, input_names=['images'],
96+
torch.onnx.export(model, img, f, verbose=False, opset_version=opt.opset_version,
10097
training=torch.onnx.TrainingMode.TRAINING if opt.train else torch.onnx.TrainingMode.EVAL,
10198
do_constant_folding=not opt.train,
102-
dynamic_axes={'images': {0: 'batch', 2: 'height', 3: 'width'}, # size(1,3,640,640)
103-
'output': {0: 'batch', 2: 'y', 3: 'x'}} if opt.dynamic else None)
99+
input_names=['images'],
100+
output_names=['output'],
101+
dynamic_axes={'images': {0: 'batch', 2: 'height', 3: 'width'}, # shape(1,3,640,640)
102+
'output': {0: 'batch', 1: 'anchors'} # shape(1,25200,85)
103+
} if opt.dynamic else None)
104104

105105
# Checks
106106
model_onnx = onnx.load(f) # load onnx model

models/yolo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
select_device, copy_attr
2222

2323
try:
24-
import thop # for FLOPS computation
24+
import thop # for FLOPs computation
2525
except ImportError:
2626
thop = None
2727

@@ -140,13 +140,13 @@ def forward_once(self, x, profile=False):
140140
x = y[m.f] if isinstance(m.f, int) else [x if j == -1 else y[j] for j in m.f] # from earlier layers
141141

142142
if profile:
143-
o = thop.profile(m, inputs=(x,), verbose=False)[0] / 1E9 * 2 if thop else 0 # FLOPS
143+
o = thop.profile(m, inputs=(x,), verbose=False)[0] / 1E9 * 2 if thop else 0 # FLOPs
144144
t = time_synchronized()
145145
for _ in range(10):
146146
_ = m(x)
147147
dt.append((time_synchronized() - t) * 100)
148148
if m == self.model[0]:
149-
logger.info(f"{'time (ms)':>10s} {'GFLOPS':>10s} {'params':>10s} {'module'}")
149+
logger.info(f"{'time (ms)':>10s} {'GFLOPs':>10s} {'params':>10s} {'module'}")
150150
logger.info(f'{dt[-1]:10.2f} {o:10.2f} {m.np:10.0f} {m.type}')
151151

152152
x = m(x) # run

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pandas
2727
# extras --------------------------------------
2828
# Cython # for pycocotools https://github.com/cocodataset/cocoapi/issues/172
2929
pycocotools>=2.0 # COCO mAP
30-
thop # FLOPS computation
30+
thop # FLOPs computation
3131

3232

3333
# Joshua Friedrich

test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test(data,
9595
confusion_matrix = ConfusionMatrix(nc=nc)
9696
names = {k: v for k, v in enumerate(model.names if hasattr(model, 'names') else model.module.names)}
9797
coco91class = coco80_to_coco91_class()
98-
s = ('%20s' + '%12s' * 6) % ('Class', 'Images', 'Labels', 'P', 'R', '[email protected]', '[email protected]:.95')
98+
s = ('%20s' + '%11s' * 6) % ('Class', 'Images', 'Labels', 'P', 'R', '[email protected]', '[email protected]:.95')
9999
p, r, f1, mp, mr, map50, map, t0, t1 = 0., 0., 0., 0., 0., 0., 0., 0., 0.
100100
loss = torch.zeros(3, device=device)
101101
jdict, stats, ap, ap_class, wandb_images = [], [], [], [], []
@@ -228,7 +228,7 @@ def test(data,
228228
nt = torch.zeros(1)
229229

230230
# Print results
231-
pf = '%20s' + '%12i' * 2 + '%12.3g' * 4 # print format
231+
pf = '%20s' + '%11i' * 2 + '%11.3g' * 4 # print format
232232
print(pf % ('all', seen, nt.sum(), mp, mr, map50, map))
233233

234234
# Print results per class
@@ -306,6 +306,7 @@ def test(data,
306306
parser.add_argument('--project', default='runs/test', help='save to project/name')
307307
parser.add_argument('--name', default='exp', help='save to project/name')
308308
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
309+
parser.add_argument('--half', type=bool, default=False, help='use FP16 half-precision inference')
309310
opt = parser.parse_args()
310311
opt.save_json |= opt.data.endswith('coco.yaml')
311312
opt.data = check_file(opt.data) # check file
@@ -326,6 +327,7 @@ def test(data,
326327
save_txt=opt.save_txt | opt.save_hybrid,
327328
save_hybrid=opt.save_hybrid,
328329
save_conf=opt.save_conf,
330+
half_precision=opt.half,
329331
opt=opt
330332
)
331333

0 commit comments

Comments
 (0)