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

Resume hyp tune #13506

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d25a075
rk opt for yolov5 base@rk_85c6d7d2
Dec 19, 2023
d271491
Merge commit '5c91'
Dec 18, 2024
4aa4e51
Merge commit 'a82132c1'
Dec 18, 2024
bf60358
Merge commit '23c49232'
Dec 18, 2024
7b40631
Merge commit '1db95338'
Dec 18, 2024
6b5fd0a
rk opt for yolov5 base@rk_85c6d7d2
Dec 19, 2023
1a9e07c
add confusion matrix plot with abs vals
Dec 18, 2024
bfec875
Merge branch 'master' of github.com:edoyango/yolov5
Dec 18, 2024
541ae60
trim logger code
Dec 28, 2024
bc9e8f0
Fix PIL requirement
edoyango Dec 29, 2024
9dc4257
add back log_model
Dec 29, 2024
41b8bbc
fix double def
Dec 29, 2024
c1ca9c8
use older version of pytorch
Dec 29, 2024
cf28bbb
use older version of numpy
Dec 29, 2024
e29d794
remove irrelevant benchmark ci
Dec 29, 2024
bb3b761
Merge pull request #1 from edoyango/fix-CI
edoyango Dec 29, 2024
dd4f147
add tune hyperparameters
Jan 11, 2025
19c93d5
work with later versions of pytorch
edoyango Jan 24, 2025
d3865d5
merge export and convert rknn
edoyango Jan 30, 2025
a9b11f5
remove redundant import
edoyango Jan 30, 2025
4ab674b
Revert "merge export and convert rknn"
edoyango Jan 30, 2025
beb998f
remove unneeded functions
edoyango Jan 30, 2025
784a727
remove unneeded export options
edoyango Jan 30, 2025
5584eb9
remove auto package update
edoyango Jan 30, 2025
30bc65f
finish adding rknn export
edoyango Jan 30, 2025
a9f7979
add batch_size to rknn export
edoyango Feb 2, 2025
e32038a
Use torch<2
edoyango Feb 2, 2025
852acc4
fix numpy dependency in requirements
edoyango Feb 2, 2025
bd8f6b0
Fix torch version in requirements
edoyango Feb 2, 2025
57d1576
remove python 3.7 from ci-testing
edoyango Feb 2, 2025
25fb83f
Revert "work with later versions of pytorch"
edoyango Feb 2, 2025
b1c83cf
Remove hub testing and export rknn in ci
edoyango Feb 2, 2025
551471b
fix rknpu export
edoyango Feb 2, 2025
e79d86d
ignore rknn stuff
edoyango Feb 2, 2025
8f80b15
remove suffix check
edoyango Feb 2, 2025
bc8597b
remove tf format check
edoyango Feb 2, 2025
88104d4
remove unneeded formats
edoyango Feb 2, 2025
30cb9fb
remove val,detect from ci
edoyango Feb 2, 2025
3966484
add requirements for export
edoyango Feb 2, 2025
89167fe
tighten requirements for rknn-toolkit2
edoyango Feb 2, 2025
a856c60
remove python3.8 torch1.7 test
edoyango Feb 2, 2025
59d108b
remove gcp bucket
edoyango Feb 7, 2025
d06d636
swap arg project for save_dir
edoyango Feb 7, 2025
5f5a854
fix notebook utils init
edoyango Feb 7, 2025
718dd8c
Merge branch 'master' into no-project
edoyango Feb 7, 2025
915d4ec
remove check_requirements
edoyango Feb 8, 2025
2cb269d
remove check_git_status
edoyango Feb 8, 2025
87c22e0
remove hubconf.py
edoyango Feb 8, 2025
c0a733c
Merge pull request #2 from edoyango/no-project
edoyango Feb 8, 2025
52b6d53
move evolve into seperate script
edoyango Feb 8, 2025
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
99 changes: 9 additions & 90 deletions .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,22 @@ on:
- cron: '0 0 * * *' # runs at 00:00 UTC every day

jobs:
Benchmarks:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
python-version: [ '3.10' ] # requires python<=3.10
model: [ yolov5n ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # caching pip dependencies
- name: Install requirements
run: |
python -m pip install --upgrade pip wheel
pip install -r requirements.txt coremltools openvino-dev tensorflow-cpu --extra-index-url https://download.pytorch.org/whl/cpu
python --version
pip --version
pip list
- 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 benchmarks.py --data coco128-seg.yaml --weights ${{ matrix.model }}-seg.pt --img 320 --hard-fail 0.22
- name: Test predictions
run: |
python export.py --weights ${{ matrix.model }}-cls.pt --include onnx --img 224
python detect.py --weights ${{ matrix.model }}.onnx --img 320
python segment/predict.py --weights ${{ matrix.model }}-seg.onnx --img 320
python classify/predict.py --weights ${{ matrix.model }}-cls.onnx --img 224

Tests:
timeout-minutes: 60
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest ] # macos-latest bug https://github.com/ultralytics/yolov5/pull/9049
os: [ ubuntu-latest ] # macos-latest bug https://github.com/ultralytics/yolov5/pull/9049
python-version: [ '3.10' ]
model: [ yolov5n ]
include:
- os: ubuntu-latest
python-version: '3.7' # '3.6.8' min
model: yolov5n
- os: ubuntu-latest
python-version: '3.8'
model: yolov5n
- os: ubuntu-latest
python-version: '3.9'
model: yolov5n
- os: ubuntu-latest
python-version: '3.8' # torch 1.7.0 requires python >=3.6, <=3.8
model: yolov5n
torch: '1.7.0' # min torch version CI https://pypi.org/project/torchvision/
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down Expand Up @@ -97,57 +56,17 @@ jobs:
pip --version
pip list
- name: Test detection
shell: bash # for Windows compatibility
shell: bash
run: |
# export PYTHONPATH="$PWD" # to run '$ python *.py' files in subdirectories
m=${{ matrix.model }} # official weights
b=runs/train/exp/weights/best # best.pt checkpoint
python train.py --imgsz 64 --batch 32 --weights $m.pt --cfg $m.yaml --epochs 1 --device cpu # train
for d in cpu; do # devices
for w in $m $b; do # weights
python val.py --imgsz 64 --batch 32 --weights $w.pt --device $d # val
python detect.py --imgsz 64 --weights $w.pt --device $d # detect
done
done
python hubconf.py --model $m # hub
# python models/tf.py --weights $m.pt # build TF model
#for d in cpu; do # devices
# for w in $m $b; do # weights
# python val.py --imgsz 64 --batch 32 --weights $w.pt --device $d # val
# python detect.py --imgsz 64 --weights $w.pt --device $d # detect
# done
#done
python models/yolo.py --cfg $m.yaml # build PyTorch model
python export.py --weights $m.pt --img 64 --include torchscript # export
python - <<EOF
import torch
im = torch.zeros([1, 3, 64, 64])
for path in '$m', '$b':
model = torch.hub.load('.', 'custom', path=path, source='local')
print(model('data/images/bus.jpg'))
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: |
m=${{ matrix.model }}-cls.pt # official weights
b=runs/train-cls/exp/weights/best.pt # best.pt checkpoint
python classify/train.py --imgsz 32 --model $m --data mnist160 --epochs 1 # train
python classify/val.py --imgsz 32 --weights $b --data ../datasets/mnist160 # val
python classify/predict.py --imgsz 32 --weights $b --source ../datasets/mnist160/test/7/60.png # predict
python classify/predict.py --imgsz 32 --weights $m --source data/images/bus.jpg # predict
python export.py --weights $b --img 64 --include torchscript # export
python - <<EOF
import torch
for path in '$m', '$b':
model = torch.hub.load('.', 'custom', path=path, source='local')
EOF
python export.py --weights $m.pt --img 64 --rknpu --int8 --data data/rknpu-qnt.txt # export
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,7 @@ com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# RKNN files
*.rknn
RK_anchors.txt
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#### Get model optimized for RKNN
Exporting detect/segment model with optimization for RKNN, please refer here [README_rkopt.md](./README_rkopt.md)

导出适配 RKNPU 的检测/分割模型, 请参考 [README_rkopt.md](./README_rkopt.md) 的说明

---
<br>

<div align="center">
<p>
<a align="center" href="https://ultralytics.com/yolov5" target="_blank">
Expand Down
43 changes: 43 additions & 0 deletions README_rkopt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# YOLOv5 - RKNN optimize

## Source

Base on https://github.com/ultralytics/yolov5 (v7.0) with commit id as 915bbf294bb74c859f0b41f1c23bc395014ea679



## What different

With inference result values unchanged, the following optimizations were applied:

- Optimize focus/SPPF block, getting better performance with same result
- Change output node, remove post_process from the model. (post process block in model is unfriendly for quantization)



With inference result got changed, the following optimization was applied:

- Using ReLU as activation layer instead of SiLU(Only valid when training new model)



## How to use

```
# for detection model
python export.py --rknpu --weight yolov5s.pt

# for segmentation model
python export.py --rknpu --weight yolov5s-seg.pt
```

- 'yolov5s.pt'/ 'yolov5s-seg.pt' could be replaced with your model path
- A file name "RK_anchors.txt" would be generated and it would be used for the post_process stage.
- **NOTICE: Please call with --rknpu, do not changing the default rknpu value in export.py.**



## Deploy demo

Please refer https://github.com/airockchip/rknn_model_zoo

3 changes: 1 addition & 2 deletions classify/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from models.common import DetectMultiBackend
from utils.augmentations import classify_transforms
from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams
from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, check_requirements, colorstr, cv2,
from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, colorstr, cv2,
increment_path, print_args, strip_optimizer)
from utils.plots import Annotator
from utils.torch_utils import select_device, smart_inference_mode
Expand Down Expand Up @@ -217,7 +217,6 @@ def parse_opt():


def main(opt):
check_requirements(exclude=('tensorboard', 'thop'))
run(**vars(opt))


Expand Down
6 changes: 2 additions & 4 deletions classify/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
from models.experimental import attempt_load
from models.yolo import ClassificationModel, DetectionModel
from utils.dataloaders import create_classification_dataloader
from utils.general import (DATASETS_DIR, LOGGER, TQDM_BAR_FORMAT, WorkingDirectory, check_git_info, check_git_status,
check_requirements, colorstr, download, increment_path, init_seeds, print_args, yaml_save)
from utils.general import (DATASETS_DIR, LOGGER, TQDM_BAR_FORMAT, WorkingDirectory, check_git_info,
colorstr, download, increment_path, init_seeds, print_args, yaml_save)
from utils.loggers import GenericLogger
from utils.plots import imshow_cls
from utils.torch_utils import (ModelEMA, de_parallel, model_info, reshape_classifier_output, select_device, smart_DDP,
Expand Down Expand Up @@ -299,8 +299,6 @@ def main(opt):
# Checks
if RANK in {-1, 0}:
print_args(vars(opt))
check_git_status()
check_requirements()

# DDP mode
device = select_device(opt.device, batch_size=opt.batch_size)
Expand Down
3 changes: 1 addition & 2 deletions classify/val.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from models.common import DetectMultiBackend
from utils.dataloaders import create_classification_dataloader
from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_img_size, check_requirements, colorstr,
from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_img_size, colorstr,
increment_path, print_args)
from utils.torch_utils import select_device, smart_inference_mode

Expand Down Expand Up @@ -161,7 +161,6 @@ def parse_opt():


def main(opt):
check_requirements(exclude=('tensorboard', 'thop'))
run(**vars(opt))


Expand Down
3 changes: 1 addition & 2 deletions data/Objects365.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,8 @@ names:
download: |
from tqdm import tqdm

from utils.general import Path, check_requirements, download, np, xyxy2xywhn
from utils.general import Path, download, np, xyxy2xywhn

check_requirements(('pycocotools>=2.0',))
from pycocotools.coco import COCO

# Make Directories
Expand Down
2 changes: 2 additions & 0 deletions data/rknpu-qnt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
images/bus.jpg
images/zidane.jpg
3 changes: 1 addition & 2 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

from models.common import DetectMultiBackend
from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams
from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, check_requirements, colorstr, cv2,
from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, colorstr, cv2,
increment_path, non_max_suppression, print_args, scale_boxes, strip_optimizer, xyxy2xywh)
from utils.plots import Annotator, colors, save_one_box
from utils.torch_utils import select_device, smart_inference_mode
Expand Down Expand Up @@ -252,7 +252,6 @@ def parse_opt():


def main(opt):
check_requirements(exclude=('tensorboard', 'thop'))
run(**vars(opt))


Expand Down
Loading
Loading