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

added config files for much lighter yolov5 models #11812

Closed
wants to merge 26 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
988dfbe
first commit
AyushExel May 29, 2023
8ee268e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2023
3e8191f
update
AyushExel May 29, 2023
1aae676
Merge branch 'ultralytics_cleanup' of https://github.com/ultralytics/…
AyushExel May 29, 2023
9171b2d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2023
e979c12
update
AyushExel May 29, 2023
f54a59d
Merge branch 'ultralytics_cleanup' of https://github.com/ultralytics/…
AyushExel May 29, 2023
28c8092
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2023
f21523f
update
AyushExel May 29, 2023
9018227
update
AyushExel May 29, 2023
8509d81
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2023
c2c3a39
Merge branch 'master' into ultralytics_cleanup
AyushExel Jun 1, 2023
49faf87
use autobatch
AyushExel Jun 1, 2023
3873325
Merge branch 'ultralytics_cleanup' of https://github.com/ultralytics/…
AyushExel Jun 1, 2023
0355343
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 1, 2023
9946c68
update
AyushExel Jun 1, 2023
b8ac927
Merge branch 'ultralytics_cleanup' of https://github.com/ultralytics/…
AyushExel Jun 1, 2023
9f32732
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 1, 2023
16d32a7
udpate
AyushExel Jun 1, 2023
97fbbac
Merge branch 'ultralytics_cleanup' of https://github.com/ultralytics/…
AyushExel Jun 1, 2023
9c358a5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 1, 2023
7dc495f
Merge branch 'master' into ultralytics_cleanup
AyushExel Jun 2, 2023
934e881
Merge branch 'master' into ultralytics_cleanup
AyushExel Jun 6, 2023
f91d6b1
Merge branch 'master' into ultralytics_cleanup
glenn-jocher Jun 17, 2023
a614091
Merge branch 'ultralytics_cleanup' into master
glenn-jocher Jul 4, 2023
d05a086
added lighter yolov5 models
jere357 Jul 4, 2023
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
Prev Previous commit
Next Next commit
udpate
AyushExel committed Jun 1, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 16d32a777c2e9c8c7b80f596dd4f873705eafb39
4 changes: 2 additions & 2 deletions classify/predict.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@

import torch
import torch.nn.functional as F
from ultralytics.yolo.utils.checks import check_requirements, print_args, check_img_size, check_imshow
from ultralytics.yolo.utils.checks import check_requirements, print_args, check_imgsz, check_imshow
from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode, strip_optimizer

FILE = Path(__file__).resolve()
@@ -89,7 +89,7 @@ def run(
device = select_device(device)
model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half)
stride, names, pt = model.stride, model.names, model.pt
imgsz = check_img_size(imgsz, s=stride) # check image size
imgsz = check_imgsz(imgsz, s=stride) # check image size

# Dataloader
bs = 1 # batch_size
4 changes: 2 additions & 2 deletions classify/val.py
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
import torch
from tqdm import tqdm
from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode
from ultralytics.yolo.utils.checks import check_img_size, check_requirements, print_args
from ultralytics.yolo.utils.checks import check_imgsz, check_requirements, print_args
from ultralytics.yolo.utils import colorstr

FILE = Path(__file__).resolve()
@@ -77,7 +77,7 @@ def run(
# Load model
model = DetectMultiBackend(weights, device=device, dnn=dnn, fp16=half)
stride, pt, jit, engine = model.stride, model.pt, model.jit, model.engine
imgsz = check_img_size(imgsz, s=stride) # check image size
imgsz = check_imgsz(imgsz, s=stride) # check image size
half = model.fp16 # FP16 supported on limited backends with CUDA
if engine:
batch_size = model.batch_size
4 changes: 2 additions & 2 deletions detect.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@

import torch
from ultralyitcs.yolo.utils import colorstr
from ultralytics.yolo.utils.checks import print_args, check_img_size, check_imshow, check_requirements
from ultralytics.yolo.utils.checks import print_args, check_imgsz, check_imshow, check_requirements
from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode

FILE = Path(__file__).resolve()
@@ -98,7 +98,7 @@ def run(
device = select_device(device)
model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half)
stride, names, pt = model.stride, model.names, model.pt
imgsz = check_img_size(imgsz, s=stride) # check image size
imgsz = check_imgsz(imgsz, s=stride) # check image size

# Dataloader
bs = 1 # batch_size
4 changes: 2 additions & 2 deletions export.py
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@
from ultralytics.nn.tasks import attempt_load_weights
from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode
from ultraltics.yolo.utils import file_size, check_requirements, colorstr
from ultralytics.yolo.utils.checks import print_args, check_img_size, check_version
from ultralytics.yolo.utils.checks import print_args, check_imgsz, check_version

FILE = Path(__file__).resolve()
ROOT = FILE.parents[0] # YOLOv5 root directory
@@ -698,7 +698,7 @@ def run(

# Input
gs = int(max(model.stride)) # grid size (max stride)
imgsz = [check_img_size(x, gs) for x in imgsz] # verify img_size are gs-multiples
imgsz = [check_imgsz(x, gs) for x in imgsz] # verify img_size are gs-multiples
im = torch.zeros(batch_size, 3, *imgsz).to(device) # image size(1,3,320,192) BCHW iDetection

# Update model
4 changes: 3 additions & 1 deletion models/common.py
Original file line number Diff line number Diff line change
@@ -24,10 +24,12 @@
from PIL import Image
from torch.cuda import amp
from ultralytics.nn.tasks import attempt_load_weights
from ultralytics.yolo.utils.checks import check_requirements, check_suffix, check_version
from ultralytics.yolo.utils import colorstr

from utils import TryExcept
from utils.dataloaders import exif_transpose, letterbox
from utils.general import (LOGGER, ROOT, Profile, check_requirements, check_suffix, check_version, colorstr,
from utils.general import (LOGGER, ROOT, Profile,
increment_path, is_jupyter, make_divisible, non_max_suppression, scale_boxes, xywh2xyxy,
xyxy2xywh, yaml_load)
from utils.plots import Annotator, colors, save_one_box
3 changes: 2 additions & 1 deletion models/yolo.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@

from ultralytics.yolo.utils.checks import print_args
from ultralytics.yolo.utils.torch_utils import select_device
from ultralytics.yolo.utils.checks import check_version

FILE = Path(__file__).resolve()
ROOT = FILE.parents[1] # YOLOv5 root directory
@@ -27,7 +28,7 @@
from models.common import *
from models.experimental import *
from utils.autoanchor import check_anchor_order
from utils.general import LOGGER, check_version, check_yaml, make_divisible
from utils.general import LOGGER, check_yaml, make_divisible
from utils.plots import feature_visualization
from utils.torch_utils import fuse_conv_and_bn, initialize_weights, model_info, profile, scale_img, time_sync

4 changes: 2 additions & 2 deletions segment/predict.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@

import torch
from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode, strip_optimizer
from ultrlalytics.yolo.utils.checks import print_args, check_img_size, check_imshow
from ultrlalytics.yolo.utils.checks import print_args, check_imgsz, check_imshow

FILE = Path(__file__).resolve()
ROOT = FILE.parents[1] # YOLOv5 root directory
@@ -100,7 +100,7 @@ def run(
device = select_device(device)
model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half)
stride, names, pt = model.stride, model.names, model.pt
imgsz = check_img_size(imgsz, s=stride) # check image size
imgsz = check_imgsz(imgsz, s=stride) # check image size

# Dataloader
bs = 1 # batch_size
4 changes: 2 additions & 2 deletions segment/train.py
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@
from torch.optim import lr_scheduler
from tqdm import tqdm
from ultralytics.nn.tasks import attempt_load_weights
from ultralytics.yolo.utils.checks import check_requirements, check_img_size
from ultralytics.yolo.utils.checks import check_requirements, check_imgsz
from ultralytics.yolo.utils.autobatch import check_train_batch_size
from ultralytics.yolo.utils import colorstr, increment_path
from ultralytics.yolo.utils.torch_utils import strip_optimizer, de_parallel, torch_distributed_zero_first
@@ -133,7 +133,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio

# Image size
gs = max(int(model.stride.max()), 32) # grid size (max stride)
imgsz = check_img_size(opt.imgsz, gs, floor=gs * 2) # verify imgsz is gs-multiple
imgsz = check_imgsz(opt.imgsz, gs, floor=gs * 2) # verify imgsz is gs-multiple

# Batch size
if RANK == -1 and batch_size == -1: # single-GPU only, estimate best batch size
4 changes: 2 additions & 2 deletions segment/val.py
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative

import torch.nn.functional as F
from ultralytis.yolo.utils.checks import check_requirements, print_args, check_img_size
from ultralytis.yolo.utils.checks import check_requirements, print_args, check_imgsz
from ultralytics.yolo.utils.torch_utils import de_parallel, select_device, smart_inference_mode

from models.common import DetectMultiBackend
@@ -183,7 +183,7 @@ def run(
# Load model
model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half)
stride, pt, jit, engine = model.stride, model.pt, model.jit, model.engine
imgsz = check_img_size(imgsz, s=stride) # check image size
imgsz = check_imgsz(imgsz, s=stride) # check image size
half = model.fp16 # FP16 supported on limited backends with CUDA
nm = de_parallel(model).model.model[-1].nm if isinstance(model, SegmentationModel) else 32 # number of masks
if engine:
5 changes: 3 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
@@ -34,10 +34,11 @@
from torch.optim import lr_scheduler
from tqdm import tqdm
from ultralytics.nn.tasks import attempt_load_weights
from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args, check_img_size
from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args, check_imgsz
from ultralytics.yolo.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, strip_optimizer,
torch_distributed_zero_first)
from ultralytics.yolo.utils.autobatch import check_train_batch_size
from ultralytics.yolo.utils import colorstr

FILE = Path(__file__).resolve()
ROOT = FILE.parents[0] # YOLOv5 root directory
@@ -144,7 +145,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio

# Image size
gs = max(int(model.stride.max()), 32) # grid size (max stride)
imgsz = check_img_size(opt.imgsz, gs, floor=gs * 2) # verify imgsz is gs-multiple
imgsz = check_imgsz(opt.imgsz, gs, floor=gs * 2) # verify imgsz is gs-multiple

# Batch size
if RANK == -1 and batch_size == -1: # single-GPU only, estimate best batch size
4 changes: 3 additions & 1 deletion utils/augmentations.py
Original file line number Diff line number Diff line change
@@ -11,8 +11,10 @@
import torch
import torchvision.transforms as T
import torchvision.transforms.functional as TF
from ultralytics.yolo.utils import colorstr
from ultralytics.yolo.utils.checks import check_version

from utils.general import LOGGER, check_version, colorstr, resample_segments, segment2box, xywhn2xyxy
from utils.general import LOGGER, resample_segments, segment2box, xywhn2xyxy
from utils.metrics import bbox_ioa

IMAGENET_MEAN = 0.485, 0.456, 0.406 # RGB mean
3 changes: 2 additions & 1 deletion utils/general.py
Original file line number Diff line number Diff line change
@@ -35,7 +35,8 @@
import torch
import torchvision
import yaml
from ultralytics.yolo.utils.checks import check_requirements
from ultralytics.yolo.utils.checks import check_requirements, check_version
from ultralytics.yolo.utils import colorstr

from utils import TryExcept, emojis
from utils.downloads import curl_download, gsutil_getsize
4 changes: 2 additions & 2 deletions val.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
import numpy as np
import torch
from tqdm import tqdm
from ultralytics.yolo.utils.checks import check_requirements, print_args, check_img_size
from ultralytics.yolo.utils.checks import check_requirements, print_args, check_imgsz
from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode

FILE = Path(__file__).resolve()
@@ -143,7 +143,7 @@ def run(
# Load model
model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half)
stride, pt, jit, engine = model.stride, model.pt, model.jit, model.engine
imgsz = check_img_size(imgsz, s=stride) # check image size
imgsz = check_imgsz(imgsz, s=stride) # check image size
half = model.fp16 # FP16 supported on limited backends with CUDA
if engine:
batch_size = model.batch_size