Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YOLOv5 segmentation model support #9052

Merged
merged 344 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
344 commits
Select commit Hold shift + click to select a range
c7756b0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 20, 2022
8643c17
Fix duplicate plots.py
glenn-jocher Aug 20, 2022
2298fcf
Fix check_font()
glenn-jocher Aug 20, 2022
c9b376d
# torch.use_deterministic_algorithms(True)
glenn-jocher Aug 20, 2022
ab00c7b
update doc detect->predict
AyushExel Aug 20, 2022
9809de8
Merge branch 'instance_seg' of https://github.com/AyushExel/yolov5 in…
AyushExel Aug 20, 2022
38d210e
Resolve precommit for segment/train and segment/val
glenn-jocher Aug 20, 2022
e56df79
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 20, 2022
28de97b
Resolve precommit for utils/segment
glenn-jocher Aug 20, 2022
2ab9f3c
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 20, 2022
1f71387
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 20, 2022
fd9ffb0
Resolve precommit min_wh
glenn-jocher Aug 20, 2022
74eabbf
Resolve precommit utils/segment/plots
glenn-jocher Aug 20, 2022
791a905
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 20, 2022
a752e67
Resolve precommit utils/segment/general
glenn-jocher Aug 20, 2022
2d9394d
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 20, 2022
1a84f47
Align NMS-seg closer to NMS
glenn-jocher Aug 20, 2022
8b70e64
restore deterministic init_seeds code
glenn-jocher Aug 20, 2022
517e1ec
Merge branch 'master' into instance_seg
glenn-jocher Aug 20, 2022
33c10b5
Merge branch 'master' into instance_seg
glenn-jocher Aug 21, 2022
6e4fbeb
remove easydict dependency
AyushExel Aug 21, 2022
82735e5
Merge branch 'instance_seg' of https://github.com/AyushExel/yolov5 in…
AyushExel Aug 21, 2022
c6f3b6e
update
AyushExel Aug 21, 2022
d1327d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 21, 2022
466ab71
restore output_to_target mask
AyushExel Aug 21, 2022
7724c71
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 21, 2022
08735aa
update
AyushExel Aug 21, 2022
e7273ba
Merge branch 'instance_seg' of https://github.com/AyushExel/yolov5 in…
AyushExel Aug 21, 2022
affb812
Merge branch 'master' into instance_seg
AyushExel Aug 21, 2022
f035ba9
Merge branch 'master' into instance_seg
AyushExel Aug 21, 2022
fb1614d
Merge branch 'master' into instance_seg
AyushExel Aug 21, 2022
75f617f
cleanup
AyushExel Aug 21, 2022
ccd05a2
Merge branch 'instance_seg' of https://github.com/AyushExel/yolov5 in…
AyushExel Aug 21, 2022
ba62c62
Remove unused ImageFont import
glenn-jocher Aug 21, 2022
55ef06a
Unified NMS
glenn-jocher Aug 21, 2022
7ce7378
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 21, 2022
eddc9b5
Merge branch 'master' into instance_seg
glenn-jocher Aug 21, 2022
7ebd19d
DetectMultiBackend compatibility
glenn-jocher Aug 21, 2022
261bec1
segment/predict.py update
glenn-jocher Aug 21, 2022
0095547
update plot colors
Laughing-q Aug 22, 2022
139640c
fix bbox shifted
Laughing-q Aug 22, 2022
cabb99d
sort bbox by confidence
Laughing-q Aug 22, 2022
ebc0bcb
Merge pull request #19 from Laughing-q/instance_seg
AyushExel Aug 22, 2022
63daead
enable overlap by default
AyushExel Aug 22, 2022
422c7ad
Merge branch 'instance_seg' of https://github.com/AyushExel/yolov5 in…
AyushExel Aug 22, 2022
28ff5fe
Merge detect/segment output_to_target() function
glenn-jocher Aug 22, 2022
8c0eb6d
Start segmentation CI
glenn-jocher Aug 22, 2022
0c7e7cf
fix plots
AyushExel Aug 23, 2022
17a979c
Update ci-testing.yml
glenn-jocher Aug 23, 2022
235ea77
Merge branch 'master' into instance_seg
glenn-jocher Aug 23, 2022
8b8ea38
fix training whitespace
glenn-jocher Aug 23, 2022
b2c6d09
optimize process mask functions (can we merge both?)
glenn-jocher Aug 23, 2022
d189aab
Update predict/detect
glenn-jocher Aug 23, 2022
4cf5775
Update plot_images
glenn-jocher Aug 23, 2022
00a7117
Update plot_images_and_masks
glenn-jocher Aug 23, 2022
1c94b4d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 23, 2022
75cbbbb
fix
glenn-jocher Aug 23, 2022
b0d1067
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 23, 2022
56be6c4
Add train to CI
glenn-jocher Aug 23, 2022
f820f32
fix precommit
glenn-jocher Aug 23, 2022
5dc63fa
fix precommit CI
glenn-jocher Aug 23, 2022
f6b0c84
fix precommit pycocotools
glenn-jocher Aug 23, 2022
492c891
fix val float issues
glenn-jocher Aug 23, 2022
a863114
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 23, 2022
ba46f44
fix masks float float issues
glenn-jocher Aug 23, 2022
bdb79e4
suppress errors
glenn-jocher Aug 23, 2022
3367da0
Merge branch 'master' into instance_seg
glenn-jocher Aug 23, 2022
e66c15c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 23, 2022
d6979ba
fix no-predictions plotting bug
glenn-jocher Aug 24, 2022
034b1a6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 24, 2022
5035ebd
Add CSV Logger
glenn-jocher Aug 24, 2022
26fbf08
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 24, 2022
be5a244
fix val len(plot_masks)
glenn-jocher Aug 24, 2022
4fad59c
speed up evaluation
Laughing-q Aug 24, 2022
ce6d849
fix process_mask
Laughing-q Aug 24, 2022
61212a6
fix plots
Laughing-q Aug 24, 2022
2eb1a71
Merge pull request #20 from Laughing-q/instance_seg
AyushExel Aug 24, 2022
93f2dfa
Merge branch 'master' into instance_seg
AyushExel Aug 24, 2022
8322d79
Merge branch 'master' into instance_seg
glenn-jocher Aug 24, 2022
c00c632
update segment/utils build_targets
glenn-jocher Aug 24, 2022
a96c832
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 24, 2022
bd277b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 24, 2022
c37820f
optimize utils/segment/general crop()
glenn-jocher Aug 24, 2022
c73505b
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 24, 2022
bf9e19a
optimize utils/segment/general crop() 2
glenn-jocher Aug 24, 2022
d276b67
minor updates
glenn-jocher Aug 24, 2022
854f728
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 24, 2022
f1a533d
torch.where revert
glenn-jocher Aug 24, 2022
e0e256d
downsample only if different shape
glenn-jocher Aug 24, 2022
da11068
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 24, 2022
95a9994
loss cleanup
glenn-jocher Aug 24, 2022
c8c331c
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 24, 2022
868385f
loss cleanup 2
glenn-jocher Aug 24, 2022
226c96a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 24, 2022
5b52c94
loss cleanup 3
glenn-jocher Aug 24, 2022
cf40b17
update project names
glenn-jocher Aug 24, 2022
dae6549
Rename -seg yamls from _underscore to -dash
glenn-jocher Aug 24, 2022
5329585
prepare for yolov5n-seg.pt
glenn-jocher Aug 24, 2022
5c93069
precommit space fix
glenn-jocher Aug 24, 2022
156c012
add coco128-seg.yaml
glenn-jocher Aug 24, 2022
92a3ff0
update coco128-seg comments
glenn-jocher Aug 24, 2022
e2b0702
cleanup val.py
glenn-jocher Aug 24, 2022
c4e84f1
Major val.py cleanup
glenn-jocher Aug 24, 2022
4710a40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 24, 2022
744058e
precommit fix
glenn-jocher Aug 24, 2022
6be9f54
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 24, 2022
858db34
precommit fix
glenn-jocher Aug 24, 2022
1a00dda
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 24, 2022
6820f84
optional pycocotools
glenn-jocher Aug 24, 2022
8d81d13
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 24, 2022
114485b
remove CI pip install pycocotools (auto-installed now)
glenn-jocher Aug 24, 2022
d4e0417
Merge branch 'master' into instance_seg
glenn-jocher Aug 24, 2022
0acd727
seg yaml fix
glenn-jocher Aug 24, 2022
2c9719d
optimize mask_iou() and masks_iou()
glenn-jocher Aug 25, 2022
63a1860
Merge branch 'master' into instance_seg
glenn-jocher Aug 25, 2022
4863beb
threaded fix
glenn-jocher Aug 25, 2022
27f785b
Merge branch 'master' into instance_seg
glenn-jocher Aug 25, 2022
347968b
Major train.py update
glenn-jocher Aug 25, 2022
5956e7d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 25, 2022
252b8b3
Major segments/val/process_batch() update
glenn-jocher Aug 25, 2022
740301d
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 25, 2022
0d08e0e
yolov5/val updates from segment
glenn-jocher Aug 25, 2022
865dfa7
process_batch numpy/tensor fix
glenn-jocher Aug 25, 2022
29b8093
Merge branch 'master' into instance_seg
AyushExel Aug 25, 2022
43ca2f2
opt-in to pycocotools with --save-json
glenn-jocher Aug 25, 2022
8c9f906
threaded pycocotools ops for 2x speed increase
glenn-jocher Aug 26, 2022
db545f9
Avoid permute contiguous if possible
glenn-jocher Aug 26, 2022
2065337
Add max_det=300 argument to both val.py and segment/val.py
glenn-jocher Aug 26, 2022
b4fd724
Merge branch 'master' into instance_seg
glenn-jocher Aug 26, 2022
f21e349
fix onnx_dynamic
glenn-jocher Aug 26, 2022
cb16493
speed up pycocotools ops
Laughing-q Aug 26, 2022
50dc739
Merge branch 'master' into instance_seg
AyushExel Aug 26, 2022
6bec10e
faster process_mask(upsample=True) for predict
glenn-jocher Aug 26, 2022
8029d56
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 26, 2022
fee17a6
Merge pull request #21 from Laughing-q/instance_seg
AyushExel Aug 26, 2022
68f805b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 26, 2022
0d48eb5
eliminate permutations for process_mask(upsample=True)
glenn-jocher Aug 26, 2022
c2e0552
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 26, 2022
6010507
eliminate permute-contiguous in crop(), use native dimension order
glenn-jocher Aug 26, 2022
d43b101
cleanup comment
glenn-jocher Aug 26, 2022
61e282c
Add Proto() module
glenn-jocher Aug 26, 2022
e5724dc
Merge branch 'master' into instance_seg
glenn-jocher Aug 26, 2022
8823206
fix class count
glenn-jocher Aug 26, 2022
ff59beb
fix anchor order
glenn-jocher Aug 26, 2022
1b10d12
broadcast mask_gti in loss for speed
glenn-jocher Aug 26, 2022
af8663c
Cleanup seg loss
glenn-jocher Aug 26, 2022
5c8b968
Merge branch 'master' into instance_seg
glenn-jocher Aug 26, 2022
97e15a0
faster indexing
glenn-jocher Aug 26, 2022
0b83f5d
faster indexing fix
glenn-jocher Aug 27, 2022
46c38bb
faster indexing fix2
glenn-jocher Aug 27, 2022
f273ecb
revert faster indexing
glenn-jocher Aug 27, 2022
fc814b7
fix validation plotting
AyushExel Aug 27, 2022
422b8d2
Loss cleanup and mxyxy simplification
glenn-jocher Aug 27, 2022
36b0374
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Aug 27, 2022
b501668
Loss cleanup and mxyxy simplification 2
glenn-jocher Aug 27, 2022
8d8f797
revert validation plotting
AyushExel Aug 27, 2022
52a6ddd
Merge branch 'instance_seg' of https://github.com/AyushExel/yolov5 in…
AyushExel Aug 27, 2022
2361108
replace missing tanh
glenn-jocher Aug 27, 2022
5bd9541
Eliminate last permutation
glenn-jocher Aug 28, 2022
1aff5cc
delete unneeded .float()
glenn-jocher Aug 28, 2022
8fe3f91
Remove MaskIOULoss and crop(if HWC)
glenn-jocher Aug 28, 2022
f99934c
Final v6.3 SegmentationModel architecture updates
glenn-jocher Aug 28, 2022
00a23e0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2022
691866f
Merge branch 'master' into instance_seg
glenn-jocher Aug 28, 2022
6793bc3
Merge branch 'master' into instance_seg
AyushExel Aug 29, 2022
750b500
Merge branch 'master' into instance_seg
AyushExel Aug 29, 2022
2a26bdb
Add support for TF export
AyushExel Aug 30, 2022
0e0f9c0
remove debugger trace
AyushExel Aug 30, 2022
d3ba0f2
Merge branch 'master' into instance_seg
AyushExel Aug 30, 2022
b6bca18
add call
AyushExel Aug 30, 2022
c7a2ec9
update
AyushExel Aug 30, 2022
d2af8e1
update
AyushExel Aug 30, 2022
3b25f3c
Merge branch 'master' into instance_seg
glenn-jocher Aug 30, 2022
6e88e2c
Merge branch 'master' into instance_seg
glenn-jocher Aug 31, 2022
0861737
Merge branch 'master' into instance_seg
AyushExel Sep 1, 2022
73d4d7c
Merge branch 'master' into instance_seg
AyushExel Sep 1, 2022
445680c
Merge master
glenn-jocher Sep 1, 2022
3422294
Merge master
glenn-jocher Sep 1, 2022
5d7ed13
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2022
2738352
Update dataloaders.py
glenn-jocher Sep 1, 2022
70e35e5
Restore CI
glenn-jocher Sep 1, 2022
91f9258
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Sep 1, 2022
e74c49f
Update dataloaders.py
glenn-jocher Sep 1, 2022
3b9c5d1
Merge branch 'master' into instance_seg
glenn-jocher Sep 1, 2022
0328a10
Merge branch 'master' into instance_seg
glenn-jocher Sep 2, 2022
52f2123
Fix TF/TFLite export for segmentation model
zldrobit Sep 2, 2022
74c3b25
Merge master
glenn-jocher Sep 2, 2022
5fdd16a
Cleanup predict.py mask plotting
glenn-jocher Sep 2, 2022
ecbca70
Merge branch 'master' into instance_seg
glenn-jocher Sep 2, 2022
4a3a5bd
cleanup scale_masks()
glenn-jocher Sep 2, 2022
e4d2e7d
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Sep 2, 2022
b7cd6ea
rename scale_masks to scale_image
glenn-jocher Sep 2, 2022
92cd027
cleanup/optimize plot_masks
glenn-jocher Sep 2, 2022
c9156c4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 2, 2022
d0f40c3
Add Annotator.masks()
glenn-jocher Sep 2, 2022
e1edd2f
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Sep 2, 2022
b105654
Annotator.masks() fix
glenn-jocher Sep 2, 2022
1dc663f
Update plots.py
glenn-jocher Sep 2, 2022
558ee48
Annotator mask optimization
glenn-jocher Sep 2, 2022
e083785
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Sep 2, 2022
2378091
Rename crop() to crop_mask()
glenn-jocher Sep 2, 2022
27c5563
Do not crop in predict.py
glenn-jocher Sep 2, 2022
d1e49e4
crop always
glenn-jocher Sep 2, 2022
dde9a55
Merge pull request #25 from zldrobit/instance_seg_tf
AyushExel Sep 3, 2022
161d253
Merge branch 'master' into instance_seg
glenn-jocher Sep 3, 2022
0a039c3
Merge pull request #23 from AyushExel/instance_seg_tf
AyushExel Sep 4, 2022
b1357c7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 4, 2022
a67232b
Merge branch 'master' into instance_seg
glenn-jocher Sep 4, 2022
f34346f
Merge master
glenn-jocher Sep 4, 2022
dfeb646
Merge branch 'master' into instance_seg
glenn-jocher Sep 4, 2022
82deb52
Add vid-stride from master PR
glenn-jocher Sep 4, 2022
996a3e4
Update seg model outputs
glenn-jocher Sep 4, 2022
a014646
Update seg model outputs
glenn-jocher Sep 4, 2022
04eb590
Add segmentation benchmarks
glenn-jocher Sep 4, 2022
11d27a7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 4, 2022
4016d72
Add segmentation benchmarks
glenn-jocher Sep 4, 2022
9f69bf2
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Sep 4, 2022
e9ab851
Add segmentation benchmarks
glenn-jocher Sep 4, 2022
5a1abb2
Add segmentation benchmarks
glenn-jocher Sep 4, 2022
29c03da
Fix DetectMultiBackend for OpenVINO
glenn-jocher Sep 4, 2022
3b63e8b
update Annotator.masks
Laughing-q Sep 5, 2022
69e5993
fix val plot
Laughing-q Sep 5, 2022
6d0e952
revert val plot
Laughing-q Sep 5, 2022
71780b2
clean up
Laughing-q Sep 5, 2022
d53c825
revert pil
Laughing-q Sep 5, 2022
7cdda21
Merge pull request #26 from Laughing-q/instance_seg
AyushExel Sep 5, 2022
78a42d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 5, 2022
41f0277
Merge branch 'master' into instance_seg
glenn-jocher Sep 6, 2022
7abb61e
Merge branch 'master' into instance_seg
glenn-jocher Sep 7, 2022
373e5f4
Merge branch 'master' into instance_seg
glenn-jocher Sep 7, 2022
89299d9
Merge branch 'master' into instance_seg
glenn-jocher Sep 10, 2022
0c71b28
Merge branch 'master' into instance_seg
glenn-jocher Sep 10, 2022
1b3bacb
Fix CI error
glenn-jocher Sep 10, 2022
551eadd
Merge master
glenn-jocher Sep 10, 2022
3c84158
Merge branch 'master' into instance_seg
glenn-jocher Sep 10, 2022
6ddcf5a
Merge branch 'master' into instance_seg
glenn-jocher Sep 11, 2022
87c7c68
fix predict log
Laughing-q Sep 12, 2022
9d6fed1
remove upsample
Laughing-q Sep 12, 2022
5a9d410
update interpolate
Laughing-q Sep 12, 2022
5905c76
Merge pull request #27 from Laughing-q/instance_seg
AyushExel Sep 12, 2022
c2ea6c9
fix validation plot logging
AyushExel Sep 12, 2022
2fcdbc3
Merge branch 'master' into instance_seg
glenn-jocher Sep 13, 2022
14a8b48
Merge branch 'master' into instance_seg
glenn-jocher Sep 15, 2022
58b1e25
Merge branch 'master' into instance_seg
glenn-jocher Sep 15, 2022
52fbe31
Annotator.masks() cleanup
glenn-jocher Sep 15, 2022
6de176c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 15, 2022
4958de5
Remove segmentation_model definition
glenn-jocher Sep 15, 2022
f0816d9
Merge remote-tracking branch 'origin/instance_seg' into instance_seg
glenn-jocher Sep 15, 2022
753adac
Restore 0.99999 decimals
glenn-jocher Sep 15, 2022
09804e9
Merge branch 'master' into instance_seg
glenn-jocher Sep 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
Benchmarks:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
python-version: [ '3.9' ] # requires python<=3.9
Expand All @@ -37,9 +38,12 @@ jobs:
python --version
pip --version
pip list
- name: Run benchmarks
- name: Benchmark DetectionModel
run: |
python benchmarks.py --data coco128.yaml --weights ${{ matrix.model }}.pt --img 320 --hard-fail 0.29
- name: Benchmark SegmentationModel
run: |
python utils/benchmarks.py --weights ${{ matrix.model }}.pt --img 320 --hard-fail 0.29
python benchmarks.py --data coco128-seg.yaml --weights ${{ matrix.model }}-seg.pt --img 320

Tests:
timeout-minutes: 60
Expand Down Expand Up @@ -126,6 +130,20 @@ jobs:
model(im) # warmup, build grids for trace
torch.jit.trace(model, [im])
EOF
- name: Test segmentation
shell: bash # for Windows compatibility
run: |
m=${{ matrix.model }}-seg # official weights
b=runs/train-seg/exp/weights/best # best.pt checkpoint
python segment/train.py --imgsz 64 --batch 32 --weights $m.pt --cfg $m.yaml --epochs 1 --device cpu # train
python segment/train.py --imgsz 64 --batch 32 --weights '' --cfg $m.yaml --epochs 1 --device cpu # train
for d in cpu; do # devices
for w in $m $b; do # weights
python segment/val.py --imgsz 64 --batch 32 --weights $w.pt --device $d # val
python segment/predict.py --imgsz 64 --weights $w.pt --device $d # predict
python export.py --weights $w.pt --img 64 --include torchscript --device $d # export
done
done
- name: Test classification
shell: bash # for Windows compatibility
run: |
Expand Down
20 changes: 14 additions & 6 deletions utils/benchmarks.py β†’ benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@
import pandas as pd

FILE = Path(__file__).resolve()
ROOT = FILE.parents[1] # YOLOv5 root directory
ROOT = FILE.parents[0] # YOLOv5 root directory
if str(ROOT) not in sys.path:
sys.path.append(str(ROOT)) # add ROOT to PATH
# ROOT = ROOT.relative_to(Path.cwd()) # relative

import export
import val
from models.experimental import attempt_load
from models.yolo import SegmentationModel
from segment.val import run as val_seg
from utils import notebook_init
from utils.general import LOGGER, check_yaml, file_size, print_args
from utils.torch_utils import select_device
from val import run as val_det


def run(
Expand All @@ -59,6 +62,7 @@ def run(
):
y, t = [], time.time()
device = select_device(device)
model_type = type(attempt_load(weights, fuse=False)) # DetectionModel, SegmentationModel, etc.
for i, (name, f, suffix, cpu, gpu) in export.export_formats().iterrows(): # index, (name, file, suffix, CPU, GPU)
try:
assert i not in (9, 10, 11), 'inference not supported' # Edge TPU, TF.js and Paddle are unsupported
Expand All @@ -76,10 +80,14 @@ def run(
assert suffix in str(w), 'export failed'

# Validate
result = val.run(data, w, batch_size, imgsz, plots=False, device=device, task='benchmark', half=half)
metrics = result[0] # metrics (mp, mr, map50, map, *losses(box, obj, cls))
speeds = result[2] # times (preprocess, inference, postprocess)
y.append([name, round(file_size(w), 1), round(metrics[3], 4), round(speeds[1], 2)]) # MB, mAP, t_inference
if model_type == SegmentationModel:
result = val_seg(data, w, batch_size, imgsz, plots=False, device=device, task='benchmark', half=half)
metric = result[0][7] # (box(p, r, map50, map), mask(p, r, map50, map), *loss(box, obj, cls))
else: # DetectionModel:
result = val_det(data, w, batch_size, imgsz, plots=False, device=device, task='benchmark', half=half)
metric = result[0][3] # (p, r, map50, map, *loss(box, obj, cls))
speed = result[2][1] # times (preprocess, inference, postprocess)
y.append([name, round(file_size(w), 1), round(metric, 4), round(speed, 2)]) # MB, mAP, t_inference
except Exception as e:
if hard_fail:
assert type(e) is AssertionError, f'Benchmark --hard-fail for {name}: {e}'
Expand Down
101 changes: 101 additions & 0 deletions data/coco128-seg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# YOLOv5 πŸš€ by Ultralytics, GPL-3.0 license
# COCO128-seg dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics
# Example usage: python train.py --data coco128.yaml
# parent
# β”œβ”€β”€ yolov5
# └── datasets
# └── coco128-seg ← downloads here (7 MB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco128-seg # dataset root dir
train: images/train2017 # train images (relative to 'path') 128 images
val: images/train2017 # val images (relative to 'path') 128 images
test: # test images (optional)

# Classes
names:
0: person
1: bicycle
2: car
3: motorcycle
4: airplane
5: bus
6: train
7: truck
8: boat
9: traffic light
10: fire hydrant
11: stop sign
12: parking meter
13: bench
14: bird
15: cat
16: dog
17: horse
18: sheep
19: cow
20: elephant
21: bear
22: zebra
23: giraffe
24: backpack
25: umbrella
26: handbag
27: tie
28: suitcase
29: frisbee
30: skis
31: snowboard
32: sports ball
33: kite
34: baseball bat
35: baseball glove
36: skateboard
37: surfboard
38: tennis racket
39: bottle
40: wine glass
41: cup
42: fork
43: knife
44: spoon
45: bowl
46: banana
47: apple
48: sandwich
49: orange
50: broccoli
51: carrot
52: hot dog
53: pizza
54: donut
55: cake
56: chair
57: couch
58: potted plant
59: bed
60: dining table
61: toilet
62: tv
63: laptop
64: mouse
65: remote
66: keyboard
67: cell phone
68: microwave
69: oven
70: toaster
71: sink
72: refrigerator
73: book
74: clock
75: vase
76: scissors
77: teddy bear
78: hair drier
79: toothbrush


# Download script/URL (optional)
download: https://ultralytics.com/assets/coco128-seg.zip
4 changes: 2 additions & 2 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def run(
det[:, :4] = scale_coords(im.shape[2:], det[:, :4], im0.shape).round()

# Print results
for c in det[:, -1].unique():
n = (det[:, -1] == c).sum() # detections per class
for c in det[:, 5].unique():
n = (det[:, 5] == c).sum() # detections per class
s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string

# Write results
Expand Down
18 changes: 15 additions & 3 deletions models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ def __init__(self, weights='yolov5s.pt', device=torch.device('cpu'), dnn=False,
if batch_dim.is_static:
batch_size = batch_dim.get_length()
executable_network = ie.compile_model(network, device_name="CPU") # device_name="MYRIAD" for Intel NCS2
output_layer = next(iter(executable_network.outputs))
stride, names = self._load_metadata(Path(w).with_suffix('.yaml')) # load metadata
elif engine: # TensorRT
LOGGER.info(f'Loading {w} for TensorRT inference...')
Expand Down Expand Up @@ -491,7 +490,7 @@ def forward(self, im, augment=False, visualize=False):
y = self.session.run(self.output_names, {self.session.get_inputs()[0].name: im})
elif self.xml: # OpenVINO
im = im.cpu().numpy() # FP32
y = self.executable_network([im])[self.output_layer]
y = list(self.executable_network([im]).values())
elif self.engine: # TensorRT
if self.dynamic and im.shape != self.bindings['images'].shape:
i_in, i_out = (self.model.get_binding_index(x) for x in ('images', 'output'))
Expand Down Expand Up @@ -786,8 +785,21 @@ def __str__(self):
return ''


class Proto(nn.Module):
# YOLOv5 mask Proto module for segmentation models
def __init__(self, c1, c_=256, c2=32): # ch_in, number of protos, number of masks
super().__init__()
self.cv1 = Conv(c1, c_, k=3)
self.upsample = nn.Upsample(scale_factor=2, mode='nearest')
self.cv2 = Conv(c_, c_, k=3)
self.cv3 = Conv(c_, c2)

def forward(self, x):
return self.cv3(self.cv2(self.upsample(self.cv1(x))))


class Classify(nn.Module):
# Classification head, i.e. x(b,c1,20,20) to x(b,c2)
# YOLOv5 classification head, i.e. x(b,c1,20,20) to x(b,c2)
def __init__(self, c1, c2, k=1, s=1, p=None, g=1): # ch_in, ch_out, kernel, stride, padding, groups
super().__init__()
c_ = 1280 # efficientnet_b0 size
Expand Down
48 changes: 48 additions & 0 deletions models/segment/yolov5l-seg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# YOLOv5 πŸš€ by Ultralytics, GPL-3.0 license

# Parameters
nc: 80 # number of classes
depth_multiple: 1.0 # model depth multiple
width_multiple: 1.0 # layer channel multiple
anchors:
- [10,13, 16,30, 33,23] # P3/8
- [30,61, 62,45, 59,119] # P4/16
- [116,90, 156,198, 373,326] # P5/32

# YOLOv5 v6.0 backbone
backbone:
# [from, number, module, args]
[[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, C3, [128]],
[-1, 1, Conv, [256, 3, 2]], # 3-P3/8
[-1, 6, C3, [256]],
[-1, 1, Conv, [512, 3, 2]], # 5-P4/16
[-1, 9, C3, [512]],
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
[-1, 3, C3, [1024]],
[-1, 1, SPPF, [1024, 5]], # 9
]

# YOLOv5 v6.0 head
head:
[[-1, 1, Conv, [512, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 6], 1, Concat, [1]], # cat backbone P4
[-1, 3, C3, [512, False]], # 13

[-1, 1, Conv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 4], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [256, False]], # 17 (P3/8-small)

[-1, 1, Conv, [256, 3, 2]],
[[-1, 14], 1, Concat, [1]], # cat head P4
[-1, 3, C3, [512, False]], # 20 (P4/16-medium)

[-1, 1, Conv, [512, 3, 2]],
[[-1, 10], 1, Concat, [1]], # cat head P5
[-1, 3, C3, [1024, False]], # 23 (P5/32-large)

[[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5)
]
48 changes: 48 additions & 0 deletions models/segment/yolov5m-seg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# YOLOv5 πŸš€ by Ultralytics, GPL-3.0 license

# Parameters
nc: 80 # number of classes
depth_multiple: 0.67 # model depth multiple
width_multiple: 0.75 # layer channel multiple
anchors:
- [10,13, 16,30, 33,23] # P3/8
- [30,61, 62,45, 59,119] # P4/16
- [116,90, 156,198, 373,326] # P5/32

# YOLOv5 v6.0 backbone
backbone:
# [from, number, module, args]
[[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, C3, [128]],
[-1, 1, Conv, [256, 3, 2]], # 3-P3/8
[-1, 6, C3, [256]],
[-1, 1, Conv, [512, 3, 2]], # 5-P4/16
[-1, 9, C3, [512]],
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
[-1, 3, C3, [1024]],
[-1, 1, SPPF, [1024, 5]], # 9
]

# YOLOv5 v6.0 head
head:
[[-1, 1, Conv, [512, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 6], 1, Concat, [1]], # cat backbone P4
[-1, 3, C3, [512, False]], # 13

[-1, 1, Conv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 4], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [256, False]], # 17 (P3/8-small)

[-1, 1, Conv, [256, 3, 2]],
[[-1, 14], 1, Concat, [1]], # cat head P4
[-1, 3, C3, [512, False]], # 20 (P4/16-medium)

[-1, 1, Conv, [512, 3, 2]],
[[-1, 10], 1, Concat, [1]], # cat head P5
[-1, 3, C3, [1024, False]], # 23 (P5/32-large)

[[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5)
]
48 changes: 48 additions & 0 deletions models/segment/yolov5n-seg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# YOLOv5 πŸš€ by Ultralytics, GPL-3.0 license

# Parameters
nc: 80 # number of classes
depth_multiple: 0.33 # model depth multiple
width_multiple: 0.25 # layer channel multiple
anchors:
- [10,13, 16,30, 33,23] # P3/8
- [30,61, 62,45, 59,119] # P4/16
- [116,90, 156,198, 373,326] # P5/32

# YOLOv5 v6.0 backbone
backbone:
# [from, number, module, args]
[[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, C3, [128]],
[-1, 1, Conv, [256, 3, 2]], # 3-P3/8
[-1, 6, C3, [256]],
[-1, 1, Conv, [512, 3, 2]], # 5-P4/16
[-1, 9, C3, [512]],
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
[-1, 3, C3, [1024]],
[-1, 1, SPPF, [1024, 5]], # 9
]

# YOLOv5 v6.0 head
head:
[[-1, 1, Conv, [512, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 6], 1, Concat, [1]], # cat backbone P4
[-1, 3, C3, [512, False]], # 13

[-1, 1, Conv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 4], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [256, False]], # 17 (P3/8-small)

[-1, 1, Conv, [256, 3, 2]],
[[-1, 14], 1, Concat, [1]], # cat head P4
[-1, 3, C3, [512, False]], # 20 (P4/16-medium)

[-1, 1, Conv, [512, 3, 2]],
[[-1, 10], 1, Concat, [1]], # cat head P5
[-1, 3, C3, [1024, False]], # 23 (P5/32-large)

[[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5)
]
Loading