Skip to content

Commit

Permalink
update to 01.02.23 ultralytics/yolov5 (#214)
Browse files Browse the repository at this point in the history
* update to latest ultralytics

* updates

* fix typo

* fix a typo

* fix classify predict

* fix typo

* fix typo

* update roboflow cls data

* remove roboflow cls ci

* refactor ci workflow, fix typo in roboflow util (#215)

* update workflow config and yolov5 version

* fix a typo in roboflow utils

* Co-authored-by: SkalskiP <piotr.skalski92@gmail.com>

* Update ci.yml

* fix a typo

* Update package_testing.yml
  • Loading branch information
fcakyon committed Jan 31, 2023
1 parent e4012d1 commit a05ce22
Show file tree
Hide file tree
Showing 25 changed files with 216 additions and 138 deletions.
47 changes: 34 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ jobs:
run: |
python -m unittest
- name: Test scripts
env:
ROBOFLOW_TOKEN: ${{ secrets.ROBOFLOW_API_KEY }}
- name: Test yolov5 train
shell: bash # for Windows compatibility
run: |
pip install -e .
Expand All @@ -66,34 +64,57 @@ jobs:
python yolov5/train.py --img 128 --batch 16 --weights yolov5/weights/yolov5n.pt --epochs 1 --device cpu
yolov5 train --img 128 --batch 16 --weights yolov5/weights/yolov5n.pt --epochs 1 --device cpu --freeze 10
yolov5 train --img 128 --batch 16 --weights yolov5/weights/yolov5n.pt --epochs 1 --device cpu --evolve 2
# detect
- name: Test yolov5 detect
shell: bash # for Windows compatibility
run: |
python yolov5/detect.py --weights yolov5/weights/yolov5n.pt --device cpu
yolov5 detect --weights yolov5/weights/yolov5n.pt --device cpu
python yolov5/detect.py --weights runs/train/exp/weights/last.pt --device cpu
yolov5 detect --weights runs/train/exp/weights/last.pt --device cpu
# val
- name: Test yolov5 val
shell: bash # for Windows compatibility
run: |
python yolov5/val.py --img 128 --batch 16 --weights yolov5/weights/yolov5n.pt --device cpu
yolov5 val --data yolov5/data/coco128.yaml --img 128 --batch 16 --weights yolov5/weights/yolov5n.pt --device cpu
python yolov5/val.py --img 128 --batch 16 --weights runs/train/exp/weights/last.pt --device cpu
yolov5 val --data yolov5/data/coco128.yaml --img 128 --batch 16 --weights runs/train/exp/weights/last.pt --device cpu
# export
- name: Test yolov5 export
shell: bash # for Windows compatibility
run: |
pip install onnx onnx-simplifier tensorflowjs
python yolov5/export.py --weights yolov5/weights/yolov5n.pt --device cpu --include torchscript,onnx,tflite
yolov5 export --weights yolov5/weights/yolov5n.pt --device cpu --simplify --include torchscript,onnx,saved_model,pb,tfjs
# benckmarks
- name: Test yolov5 benchmarks
shell: bash # for Windows compatibility
run: |
yolov5 benchmarks --weights yolov5n.pt --img 128 --pt-only --device cpu
# classify
- name: Test yolov5 classify
shell: bash # for Windows compatibility
run: |
yolov5 classify train --img 128 --data mnist2560 --model yolov5n-cls.pt --epochs 1 --device cpu
yolov5 classify train --img 128 --data mnist2560 --model fcakyon/yolov5n-cls-v7.0 --epochs 1 --device cpu
yolov5 classify val --img 128 --data datasets/mnist2560 --weights yolov5n-cls.pt --device cpu
yolov5 classify predict --img 128 --weights yolov5n-cls.pt --device cpu
# segment
- name: Test yolov5 segment
shell: bash # for Windows compatibility
run: |
yolov5 segment train --img 128 --weights yolov5n-seg.pt --epochs 1 --device cpu
yolov5 segment train --img 128 --weights fcakyon/yolov5n-seg-v7.0 --epochs 1 --device cpu
# yolov5 segment val --img 128 --weights yolov5n-seg.pt --device cpu
yolov5 segment predict --img 128 --weights yolov5n-seg.pt --device cpu
# roboflow
yolov5 train --data https://universe.roboflow.com/jacob-solawetz/aerial-maritime/dataset/10 --weights yolov5/weights/yolov5n.pt --device cpu --roboflow_token ${{ env.ROBOFLOW_TOKEN }}
yolov5 classify train --data https://universe.roboflow.com/bagas-etcfr/flowerdata1/dataset/1 --img 128 --model yolov5n-cls.pt --epochs 1 --device cpu --roboflow_token ${{ env.ROBOFLOW_TOKEN }}
yolov5 segment train --data https://universe.roboflow.com/scaffolding/scaffolding-distance/dataset/2 --img 128 --weights yolov5n-seg.pt --epochs 1 --device cpu --roboflow_token ${{ env.ROBOFLOW_TOKEN }}
- name: Test roboflow train
shell: bash # for Windows compatibility
env:
ROBOFLOW_TOKEN: ${{ secrets.ROBOFLOW_API_KEY }}
run: |
yolov5 train --data https://universe.roboflow.com/gdit/aerial-airport/dataset/1 --weights yolov5/weights/yolov5n.pt --img 128 --epochs 1 --device cpu --roboflow_token ${{ env.ROBOFLOW_TOKEN }}
# yolov5 classify train --data https://universe.roboflow.com/carlos-gabriel-da-silva-machado-siwvs/turtles-i1tlr/dataset/1 --img 128 --model yolov5n-cls.pt --epochs 1 --device cpu --roboflow_token ${{ env.ROBOFLOW_TOKEN }}
yolov5 segment train --data https://universe.roboflow.com/aymane-outani-auooc/cable-fzjik/dataset/2 --img 128 --weights yolov5n-seg.pt --epochs 1 --device cpu --roboflow_token ${{ env.ROBOFLOW_TOKEN }}
36 changes: 28 additions & 8 deletions .github/workflows/package_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ jobs:
run: |
python -m unittest
- name: Test scripts
- name: Test yolov5 train
shell: bash # for Windows compatibility
run: |
pip install -e .
# donwload coco formatted testing data
python tests/download_test_coco_dataset.py
# train (dl base model from hf hub)
Expand All @@ -61,29 +61,49 @@ jobs:
python yolov5/train.py --img 128 --batch 16 --weights yolov5/weights/yolov5n.pt --epochs 1 --device cpu
yolov5 train --img 128 --batch 16 --weights yolov5/weights/yolov5n.pt --epochs 1 --device cpu --freeze 10
yolov5 train --img 128 --batch 16 --weights yolov5/weights/yolov5n.pt --epochs 1 --device cpu --evolve 2
# detect
- name: Test yolov5 detect
shell: bash # for Windows compatibility
run: |
python yolov5/detect.py --weights yolov5/weights/yolov5n.pt --device cpu
yolov5 detect --weights yolov5/weights/yolov5n.pt --device cpu
python yolov5/detect.py --weights runs/train/exp/weights/last.pt --device cpu
yolov5 detect --weights runs/train/exp/weights/last.pt --device cpu
# val
- name: Test yolov5 val
shell: bash # for Windows compatibility
run: |
python yolov5/val.py --img 128 --batch 16 --weights yolov5/weights/yolov5n.pt --device cpu
yolov5 val --data yolov5/data/coco128.yaml --img 128 --batch 16 --weights yolov5/weights/yolov5n.pt --device cpu
python yolov5/val.py --img 128 --batch 16 --weights runs/train/exp/weights/last.pt --device cpu
yolov5 val --data yolov5/data/coco128.yaml --img 128 --batch 16 --weights runs/train/exp/weights/last.pt --device cpu
# export
- name: Test yolov5 export
shell: bash # for Windows compatibility
run: |
pip install onnx onnx-simplifier tensorflowjs
python yolov5/export.py --weights yolov5/weights/yolov5n.pt --device cpu --include torchscript,onnx,tflite
yolov5 export --weights yolov5/weights/yolov5n.pt --device cpu --simplify --include torchscript,onnx,saved_model,pb,tfjs
# benckmarks
- name: Test yolov5 benchmarks
shell: bash # for Windows compatibility
run: |
yolov5 benchmarks --weights yolov5n.pt --img 128 --pt-only --device cpu
# classify
- name: Test yolov5 classify
shell: bash # for Windows compatibility
run: |
yolov5 classify train --img 128 --data mnist2560 --model yolov5n-cls.pt --epochs 1 --device cpu
yolov5 classify train --img 128 --data mnist2560 --model fcakyon/yolov5n-cls-v7.0 --epochs 1 --device cpu
yolov5 classify val --img 128 --data datasets/mnist2560 --weights yolov5n-cls.pt --device cpu
yolov5 classify predict --img 128 --weights yolov5n-cls.pt --device cpu
# segment
- name: Test yolov5 segment
shell: bash # for Windows compatibility
run: |
yolov5 segment train --img 128 --weights yolov5n-seg.pt --epochs 1 --device cpu
yolov5 segment train --img 128 --weights fcakyon/yolov5n-seg-v7.0 --epochs 1 --device cpu
# yolov5 segment val --img 128 --weights yolov5n-seg.pt --device cpu
yolov5 segment predict --img 128 --weights yolov5n-seg.pt --device cpu
- name: Test roboflow train
shell: bash # for Windows compatibility
env:
ROBOFLOW_TOKEN: ${{ secrets.ROBOFLOW_API_KEY }}
run: |
yolov5 train --data https://universe.roboflow.com/gdit/aerial-airport/dataset/1 --weights yolov5/weights/yolov5n.pt --img 128 --epochs 1 --device cpu --roboflow_token ${{ env.ROBOFLOW_TOKEN }}
# yolov5 classify train --data https://universe.roboflow.com/carlos-gabriel-da-silva-machado-siwvs/turtles-i1tlr/dataset/1 --img 128 --model yolov5n-cls.pt --epochs 1 --device cpu --roboflow_token ${{ env.ROBOFLOW_TOKEN }}
yolov5 segment train --data https://universe.roboflow.com/aymane-outani-auooc/cable-fzjik/dataset/2 --img 128 --weights yolov5n-seg.pt --epochs 1 --device cpu --roboflow_token ${{ env.ROBOFLOW_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ You can finally install <a href="https://github.com/ultralytics/yolov5">YOLOv5 o
</div>

<br>
This yolov5 package contains everything from ultralytics/yolov5 <a href="https://github.com/ultralytics/yolov5/tree/357cde9ee7da13ba3095995488c5a23631467f1a">at this commit</a> plus:
This yolov5 package contains everything from ultralytics/yolov5 <a href="https://github.com/ultralytics/yolov5/tree/064365d8683fd002e9ad789c1e91fa3d021b44f0">at this commit</a> plus:
<br>
1. Easy installation via pip: <b>pip install yolov5</b>
<br>
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# YOLOv5 🚀 requirements
# YOLOv5 requirements
# Usage: pip install -r requirements.txt

# Base ------------------------------------------------------------------------
Expand Down Expand Up @@ -29,7 +29,7 @@ seaborn>=0.11.0

# Export ----------------------------------------------------------------------
# coremltools>=6.0 # CoreML export
# onnx>=1.9.0 # ONNX export
# onnx>=1.12.0 # ONNX export
# onnx-simplifier>=0.4.1 # ONNX simplifier
# nvidia-pyindex # TensorRT export
# nvidia-tensorrt # TensorRT export
Expand All @@ -44,7 +44,7 @@ seaborn>=0.11.0
# Extras ----------------------------------------------------------------------
# mss # screenshots
# albumentations>=1.0.3
# pycocotools>=2.0 # COCO mAP
# pycocotools>=2.0.6 # COCO mAP
# roboflow>=0.2.27
# ultralytics # HUB https://hub.ultralytics.com

Expand All @@ -55,4 +55,4 @@ boto3>=1.19.1
# coco to yolov5 conversion
sahi>=0.11.10
# huggingface
huggingface-hub>=0.11.1
huggingface-hub>=0.12.0
2 changes: 1 addition & 1 deletion yolov5/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from yolov5.helpers import YOLOv5
from yolov5.helpers import load_model as load

__version__ = "7.0.7"
__version__ = "7.0.8"
4 changes: 2 additions & 2 deletions yolov5/classify/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def parse_opt():
parser.add_argument('--augment', action='store_true', help='augmented inference')
parser.add_argument('--visualize', action='store_true', help='visualize features')
parser.add_argument('--update', action='store_true', help='update all models')
parser.add_argument('--project', default=ROOT / 'runs/predict-cls', help='save results to project/name')
parser.add_argument('--project', default='runs/predict-cls', help='save results to project/name')
parser.add_argument('--name', default='exp', help='save results to project/name')
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
parser.add_argument('--half', action='store_true', help='use FP16 half-precision inference')
Expand All @@ -227,7 +227,7 @@ def parse_opt():

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


Expand Down
22 changes: 8 additions & 14 deletions yolov5/classify/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$ python classify/train.py --model yolov5s-cls.pt --data imagenette160 --epochs 5 --img 224
Usage - Multi-GPU DDP training:
$ python -m torch.distributed.run --nproc_per_node 4 --master_port 1 classify/train.py --model yolov5s-cls.pt --data imagenet --epochs 5 --img 224 --device 0,1,2,3
$ python -m torch.distributed.run --nproc_per_node 4 --master_port 2022 classify/train.py --model yolov5s-cls.pt --data imagenet --epochs 5 --img 224 --device 0,1,2,3
Datasets: --data mnist, fashion-mnist, cifar10, cifar100, imagenette, imagewoof, imagenet, or 'path/to/data'
YOLOv5-cls models: --model yolov5n-cls.pt, yolov5s-cls.pt, yolov5m-cls.pt, yolov5l-cls.pt, yolov5x-cls.pt
Expand All @@ -30,7 +30,7 @@
from torch.cuda import amp
from tqdm import tqdm

from yolov5.utils.downloads import attempt_donwload_from_hub
from yolov5.utils.downloads import attempt_download_from_hub
from yolov5.utils.roboflow import check_dataset_roboflow

FILE = Path(__file__).resolve()
Expand All @@ -43,18 +43,12 @@
from yolov5.models.experimental import attempt_load
from yolov5.models.yolo import ClassificationModel, DetectionModel
from yolov5.utils.dataloaders import create_classification_dataloader
from yolov5.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 yolov5.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 yolov5.utils.loggers import GenericLogger
from yolov5.utils.plots import imshow_cls
from yolov5.utils.torch_utils import (ModelEMA, model_info,
reshape_classifier_output, select_device,
smart_DDP, smart_optimizer,
smartCrossEntropyLoss,
torch_distributed_zero_first)
from yolov5.utils.torch_utils import (ModelEMA, model_info, reshape_classifier_output, select_device, smart_DDP,
smart_optimizer, smartCrossEntropyLoss, torch_distributed_zero_first)

LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
RANK = int(os.getenv('RANK', -1))
Expand Down Expand Up @@ -116,7 +110,7 @@ def train(opt, device):

# Model
# try to download from hf hub
result = attempt_donwload_from_hub(opt.model, hf_token=None)
result = attempt_download_from_hub(opt.model, hf_token=None)
if result is not None:
opt.model = result
with torch_distributed_zero_first(LOCAL_RANK), WorkingDirectory(ROOT):
Expand Down Expand Up @@ -266,7 +260,7 @@ def train(opt, device):
f"\nPredict: yolov5 classify predict --weights {best} --source im.jpg"
f"\nValidate: yolov5 classify val --weights {best} --data {data_dir}"
f"\nExport: yolov5 export --weights {best} --include onnx"
f"\nPyPi: model = yolov5.load('custom.pt')"
f"\nPython: model = yolov5.load('{best}')"
f"\nVisualize: https://netron.app\n")

# Plot examples
Expand Down
8 changes: 4 additions & 4 deletions yolov5/classify/val.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

@smart_inference_mode()
def run(
data=ROOT / '../datasets/mnist', # dataset dir
data='../datasets/mnist', # dataset dir
weights='yolov5s-cls.pt', # model.pt path(s)
batch_size=None, # batch size
batch=None, # batch size
Expand Down Expand Up @@ -155,14 +155,14 @@ def run(

def parse_opt():
parser = argparse.ArgumentParser()
parser.add_argument('--data', type=str, default=ROOT / '../datasets/mnist', help='dataset path')
parser.add_argument('--weights', nargs='+', type=str, default=ROOT / 'yolov5s-cls.pt', help='model.pt path(s)')
parser.add_argument('--data', type=str, default='../datasets/mnist', help='dataset path')
parser.add_argument('--weights', nargs='+', type=str, default='yolov5s-cls.pt', help='model.pt path(s)')
parser.add_argument('--batch-size', type=int, default=128, help='batch size')
parser.add_argument('--imgsz', '--img', '--img-size', type=int, default=224, help='inference size (pixels)')
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
parser.add_argument('--workers', type=int, default=8, help='max dataloader workers (per RANK in DDP mode)')
parser.add_argument('--verbose', nargs='?', const=True, default=True, help='verbose output')
parser.add_argument('--project', default=ROOT / 'runs/val-cls', help='save to project/name')
parser.add_argument('--project', default='runs/val-cls', help='save to project/name')
parser.add_argument('--name', default='exp', help='save to project/name')
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
parser.add_argument('--half', action='store_true', help='use FP16 half-precision inference')
Expand Down
35 changes: 35 additions & 0 deletions yolov5/data/hyps/hyp.no-augmentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Hyperparameters when using Albumentations frameworks
# python train.py --hyp hyp.no-augmentation.yaml
# See https://github.com/ultralytics/yolov5/pull/3882 for YOLOv5 + Albumentations Usage examples

lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3)
lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf)
momentum: 0.937 # SGD momentum/Adam beta1
weight_decay: 0.0005 # optimizer weight decay 5e-4
warmup_epochs: 3.0 # warmup epochs (fractions ok)
warmup_momentum: 0.8 # warmup initial momentum
warmup_bias_lr: 0.1 # warmup initial bias lr
box: 0.05 # box loss gain
cls: 0.3 # cls loss gain
cls_pw: 1.0 # cls BCELoss positive_weight
obj: 0.7 # obj loss gain (scale with pixels)
obj_pw: 1.0 # obj BCELoss positive_weight
iou_t: 0.20 # IoU training threshold
anchor_t: 4.0 # anchor-multiple threshold
# anchors: 3 # anchors per output layer (0 to ignore)
# this parameters are all zero since we want to use albumentation framework
fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5)
hsv_h: 0 # image HSV-Hue augmentation (fraction)
hsv_s: 00 # image HSV-Saturation augmentation (fraction)
hsv_v: 0 # image HSV-Value augmentation (fraction)
degrees: 0.0 # image rotation (+/- deg)
translate: 0 # image translation (+/- fraction)
scale: 0 # image scale (+/- gain)
shear: 0 # image shear (+/- deg)
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
flipud: 0.0 # image flip up-down (probability)
fliplr: 0.0 # image flip left-right (probability)
mosaic: 0.0 # image mosaic (probability)
mixup: 0.0 # image mixup (probability)
copy_paste: 0.0 # segment copy-paste (probability)
2 changes: 1 addition & 1 deletion yolov5/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def parse_opt():

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


Expand Down
Loading

0 comments on commit a05ce22

Please sign in to comment.