From c83b3ff2b854eaf5018b9aa63618d2ab26611cc0 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 09:10:53 +0200 Subject: [PATCH 01/15] make package --- {models => yolov5}/__init__.py | 0 detect.py => yolov5/detect.py | 8 ++++---- hubconf.py => yolov5/hubconf.py | 4 ++-- {utils => yolov5/models}/__init__.py | 0 {models => yolov5/models}/common.py | 0 {models => yolov5/models}/experimental.py | 4 ++-- {models => yolov5/models}/export.py | 2 +- {models => yolov5/models}/hub/yolov3-spp.yaml | 0 {models => yolov5/models}/hub/yolov5-fpn.yaml | 0 {models => yolov5/models}/hub/yolov5-panet.yaml | 0 {models => yolov5/models}/yolo.py | 8 ++++---- {models => yolov5/models}/yolov5l.yaml | 0 {models => yolov5/models}/yolov5m.yaml | 0 {models => yolov5/models}/yolov5s.yaml | 0 {models => yolov5/models}/yolov5x.yaml | 0 test.py => yolov5/test.py | 8 ++++---- train.py => yolov5/train.py | 10 +++++----- yolov5/utils/__init__.py | 0 {utils => yolov5/utils}/activations.py | 0 {utils => yolov5/utils}/datasets.py | 2 +- {utils => yolov5/utils}/general.py | 2 +- {utils => yolov5/utils}/google_utils.py | 0 {utils => yolov5/utils}/torch_utils.py | 0 23 files changed, 24 insertions(+), 24 deletions(-) rename {models => yolov5}/__init__.py (100%) rename detect.py => yolov5/detect.py (95%) rename hubconf.py => yolov5/hubconf.py (97%) rename {utils => yolov5/models}/__init__.py (100%) rename {models => yolov5/models}/common.py (100%) rename {models => yolov5/models}/experimental.py (98%) rename {models => yolov5/models}/export.py (98%) rename {models => yolov5/models}/hub/yolov3-spp.yaml (100%) rename {models => yolov5/models}/hub/yolov5-fpn.yaml (100%) rename {models => yolov5/models}/hub/yolov5-panet.yaml (100%) rename {models => yolov5/models}/yolo.py (97%) rename {models => yolov5/models}/yolov5l.yaml (100%) rename {models => yolov5/models}/yolov5m.yaml (100%) rename {models => yolov5/models}/yolov5s.yaml (100%) rename {models => yolov5/models}/yolov5x.yaml (100%) rename test.py => yolov5/test.py (98%) rename train.py => yolov5/train.py (99%) create mode 100644 yolov5/utils/__init__.py rename {utils => yolov5/utils}/activations.py (100%) rename {utils => yolov5/utils}/datasets.py (99%) rename {utils => yolov5/utils}/general.py (99%) rename {utils => yolov5/utils}/google_utils.py (100%) rename {utils => yolov5/utils}/torch_utils.py (100%) diff --git a/models/__init__.py b/yolov5/__init__.py similarity index 100% rename from models/__init__.py rename to yolov5/__init__.py diff --git a/detect.py b/yolov5/detect.py similarity index 95% rename from detect.py rename to yolov5/detect.py index ca7b96773173..c614d7ef218c 100644 --- a/detect.py +++ b/yolov5/detect.py @@ -10,10 +10,10 @@ import torch.backends.cudnn as cudnn from numpy import random -from models.experimental import attempt_load -from utils.datasets import LoadStreams, LoadImages -from utils.general import check_img_size, non_max_suppression, apply_classifier, scale_coords, xyxy2xywh, plot_one_box -from utils.torch_utils import select_device, load_classifier, time_synchronized +from yolov5.models.experimental import attempt_load +from yolov5.utils.datasets import LoadStreams, LoadImages +from yolov5.utils.general import check_img_size, non_max_suppression, apply_classifier, scale_coords, xyxy2xywh, plot_one_box +from yolov5.utils.torch_utils import select_device, load_classifier, time_synchronized def detect(save_img=False): diff --git a/hubconf.py b/yolov5/hubconf.py similarity index 97% rename from hubconf.py rename to yolov5/hubconf.py index 98416a5b8563..26107f92f321 100644 --- a/hubconf.py +++ b/yolov5/hubconf.py @@ -10,8 +10,8 @@ import torch -from models.yolo import Model -from utils.google_utils import attempt_download +from yolov5.models.yolo import Model +from yolov5.utils.google_utils import attempt_download def create(name, pretrained, channels, classes): diff --git a/utils/__init__.py b/yolov5/models/__init__.py similarity index 100% rename from utils/__init__.py rename to yolov5/models/__init__.py diff --git a/models/common.py b/yolov5/models/common.py similarity index 100% rename from models/common.py rename to yolov5/models/common.py diff --git a/models/experimental.py b/yolov5/models/experimental.py similarity index 98% rename from models/experimental.py rename to yolov5/models/experimental.py index 1b99ce47db53..20c1706cd9e4 100644 --- a/models/experimental.py +++ b/yolov5/models/experimental.py @@ -4,8 +4,8 @@ import torch import torch.nn as nn -from models.common import Conv, DWConv -from utils.google_utils import attempt_download +from yolov5.models.common import Conv, DWConv +from yolov5.utils.google_utils import attempt_download class CrossConv(nn.Module): diff --git a/models/export.py b/yolov5/models/export.py similarity index 98% rename from models/export.py rename to yolov5/models/export.py index 7ccd392bcde3..aa76f0592061 100644 --- a/models/export.py +++ b/yolov5/models/export.py @@ -8,7 +8,7 @@ import torch -from utils.google_utils import attempt_download +from yolov5.utils.google_utils import attempt_download if __name__ == '__main__': parser = argparse.ArgumentParser() diff --git a/models/hub/yolov3-spp.yaml b/yolov5/models/hub/yolov3-spp.yaml similarity index 100% rename from models/hub/yolov3-spp.yaml rename to yolov5/models/hub/yolov3-spp.yaml diff --git a/models/hub/yolov5-fpn.yaml b/yolov5/models/hub/yolov5-fpn.yaml similarity index 100% rename from models/hub/yolov5-fpn.yaml rename to yolov5/models/hub/yolov5-fpn.yaml diff --git a/models/hub/yolov5-panet.yaml b/yolov5/models/hub/yolov5-panet.yaml similarity index 100% rename from models/hub/yolov5-panet.yaml rename to yolov5/models/hub/yolov5-panet.yaml diff --git a/models/yolo.py b/yolov5/models/yolo.py similarity index 97% rename from models/yolo.py rename to yolov5/models/yolo.py index baa4e1afb758..c776b110da03 100644 --- a/models/yolo.py +++ b/yolov5/models/yolo.py @@ -6,10 +6,10 @@ import torch import torch.nn as nn -from models.common import Conv, Bottleneck, SPP, DWConv, Focus, BottleneckCSP, Concat -from models.experimental import MixConv2d, CrossConv, C3 -from utils.general import check_anchor_order, make_divisible, check_file -from utils.torch_utils import ( +from yolov5.models.common import Conv, Bottleneck, SPP, DWConv, Focus, BottleneckCSP, Concat +from yolov5.models.experimental import MixConv2d, CrossConv, C3 +from yolov5.utils.general import check_anchor_order, make_divisible, check_file +from yolov5.utils.torch_utils import ( time_synchronized, fuse_conv_and_bn, model_info, scale_img, initialize_weights, select_device) diff --git a/models/yolov5l.yaml b/yolov5/models/yolov5l.yaml similarity index 100% rename from models/yolov5l.yaml rename to yolov5/models/yolov5l.yaml diff --git a/models/yolov5m.yaml b/yolov5/models/yolov5m.yaml similarity index 100% rename from models/yolov5m.yaml rename to yolov5/models/yolov5m.yaml diff --git a/models/yolov5s.yaml b/yolov5/models/yolov5s.yaml similarity index 100% rename from models/yolov5s.yaml rename to yolov5/models/yolov5s.yaml diff --git a/models/yolov5x.yaml b/yolov5/models/yolov5x.yaml similarity index 100% rename from models/yolov5x.yaml rename to yolov5/models/yolov5x.yaml diff --git a/test.py b/yolov5/test.py similarity index 98% rename from test.py rename to yolov5/test.py index 7d4df0822b28..8068dc5017f3 100644 --- a/test.py +++ b/yolov5/test.py @@ -10,12 +10,12 @@ import yaml from tqdm import tqdm -from models.experimental import attempt_load -from utils.datasets import create_dataloader -from utils.general import ( +from yolov5.models.experimental import attempt_load +from yolov5.utils.datasets import create_dataloader +from yolov5.utils.general import ( coco80_to_coco91_class, check_file, check_img_size, compute_loss, non_max_suppression, scale_coords, xyxy2xywh, clip_coords, plot_images, xywh2xyxy, box_iou, output_to_target, ap_per_class) -from utils.torch_utils import select_device, time_synchronized +from yolov5.utils.torch_utils import select_device, time_synchronized def test(data, diff --git a/train.py b/yolov5/train.py similarity index 99% rename from train.py rename to yolov5/train.py index 4b8f1f7c9cbb..1c9b75e3dfeb 100644 --- a/train.py +++ b/yolov5/train.py @@ -19,14 +19,14 @@ from tqdm import tqdm import test # import test.py to get mAP after each epoch -from models.yolo import Model -from utils.datasets import create_dataloader -from utils.general import ( +from yolov5.models.yolo import Model +from yolov5.utils.datasets import create_dataloader +from yolov5.utils.general import ( check_img_size, torch_distributed_zero_first, labels_to_class_weights, plot_labels, check_anchors, labels_to_image_weights, compute_loss, plot_images, fitness, strip_optimizer, plot_results, get_latest_run, check_git_status, check_file, increment_dir, print_mutation) -from utils.google_utils import attempt_download -from utils.torch_utils import init_seeds, ModelEMA, select_device +from yolov5.utils.google_utils import attempt_download +from yolov5.utils.torch_utils import init_seeds, ModelEMA, select_device # Hyperparameters hyp = {'lr0': 0.01, # initial learning rate (SGD=1E-2, Adam=1E-3) diff --git a/yolov5/utils/__init__.py b/yolov5/utils/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/utils/activations.py b/yolov5/utils/activations.py similarity index 100% rename from utils/activations.py rename to yolov5/utils/activations.py diff --git a/utils/datasets.py b/yolov5/utils/datasets.py similarity index 99% rename from utils/datasets.py rename to yolov5/utils/datasets.py index 169a518e0697..491c2512504f 100755 --- a/utils/datasets.py +++ b/yolov5/utils/datasets.py @@ -14,7 +14,7 @@ from torch.utils.data import Dataset from tqdm import tqdm -from utils.general import xyxy2xywh, xywh2xyxy, torch_distributed_zero_first +from yolov5.utils.general import xyxy2xywh, xywh2xyxy, torch_distributed_zero_first help_url = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data' img_formats = ['.bmp', '.jpg', '.jpeg', '.png', '.tif', '.tiff', '.dng'] diff --git a/utils/general.py b/yolov5/utils/general.py similarity index 99% rename from utils/general.py rename to yolov5/utils/general.py index ca1225a09e48..a6020e144c20 100755 --- a/utils/general.py +++ b/yolov5/utils/general.py @@ -22,7 +22,7 @@ from scipy.signal import butter, filtfilt from tqdm import tqdm -from utils.torch_utils import init_seeds, is_parallel +from yolov5.utils.torch_utils import init_seeds, is_parallel # Set printoptions torch.set_printoptions(linewidth=320, precision=5, profile='long') diff --git a/utils/google_utils.py b/yolov5/utils/google_utils.py similarity index 100% rename from utils/google_utils.py rename to yolov5/utils/google_utils.py diff --git a/utils/torch_utils.py b/yolov5/utils/torch_utils.py similarity index 100% rename from utils/torch_utils.py rename to yolov5/utils/torch_utils.py From cd06ebc24a3832e6bb7b24d37a99f5b58a7364e8 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 09:15:53 +0200 Subject: [PATCH 02/15] update CI --- .github/workflows/ci-testing.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index b00335cc43b9..3a1a6fb61f2d 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: [3.8] + python-version: [3.7, 3.8] model: ['yolov5s'] # models to test # Timeout: https://stackoverflow.com/a/59076067/4521646 @@ -53,7 +53,7 @@ jobs: - name: Download data run: | - python -c "from utils.google_utils import * ; gdrive_download('1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', 'coco128.zip')" + python -c "from yolov5.utils.google_utils import * ; gdrive_download('1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', 'coco128.zip')" mv ./coco128 ../ - name: Tests workflow @@ -62,14 +62,14 @@ jobs: di=cpu # inference devices # define device # train - python train.py --img 256 --batch 8 --weights weights/${{ matrix.model }}.pt --cfg models/${{ matrix.model }}.yaml --epochs 1 --device $di + python yolov5/train.py --img 256 --batch 8 --weights weights/${{ matrix.model }}.pt --cfg models/${{ matrix.model }}.yaml --epochs 1 --device $di # detect - python detect.py --weights weights/${{ matrix.model }}.pt --device $di - python detect.py --weights runs/exp0/weights/last.pt --device $di + python yolov5/detect.py --weights weights/${{ matrix.model }}.pt --device $di + python yolov5/detect.py --weights runs/exp0/weights/last.pt --device $di # test - python test.py --img 256 --batch 8 --weights weights/${{ matrix.model }}.pt --device $di - python test.py --img 256 --batch 8 --weights runs/exp0/weights/last.pt --device $di + python yolov5/test.py --img 256 --batch 8 --weights weights/${{ matrix.model }}.pt --device $di + python yolov5/test.py --img 256 --batch 8 --weights runs/exp0/weights/last.pt --device $di - python models/yolo.py --cfg models/${{ matrix.model }}.yaml # inspect - python models/export.py --img 256 --batch 1 --weights weights/${{ matrix.model }}.pt # export + python yolov5/models/yolo.py --cfg models/${{ matrix.model }}.yaml # inspect + python yolov5/models/export.py --img 256 --batch 1 --weights weights/${{ matrix.model }}.pt # export shell: bash From 10c3ed4a401d8b444feb04c6122a1472ba139c56 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 09:45:52 +0200 Subject: [PATCH 03/15] clean imports --- yolov5/train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yolov5/train.py b/yolov5/train.py index 1c9b75e3dfeb..ff11bb93484a 100644 --- a/yolov5/train.py +++ b/yolov5/train.py @@ -18,7 +18,7 @@ from torch.utils.tensorboard import SummaryWriter from tqdm import tqdm -import test # import test.py to get mAP after each epoch +from yolov5 import test # import test.py to get mAP after each epoch from yolov5.models.yolo import Model from yolov5.utils.datasets import create_dataloader from yolov5.utils.general import ( From 9710c08cba6e22f510ae212ddcf846d301cd22d7 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 10:07:24 +0200 Subject: [PATCH 04/15] clean imports --- .github/workflows/ci-testing.yml | 16 ++++++++-------- {yolov5 => yolo5}/__init__.py | 0 {yolov5 => yolo5}/detect.py | 8 ++++---- {yolov5 => yolo5}/hubconf.py | 6 +++--- {yolov5 => yolo5}/models/__init__.py | 0 {yolov5 => yolo5}/models/common.py | 0 {yolov5 => yolo5}/models/experimental.py | 4 ++-- {yolov5 => yolo5}/models/export.py | 2 +- {yolov5 => yolo5}/models/hub/yolov3-spp.yaml | 0 {yolov5 => yolo5}/models/hub/yolov5-fpn.yaml | 0 {yolov5 => yolo5}/models/hub/yolov5-panet.yaml | 0 {yolov5 => yolo5}/models/yolo.py | 8 ++++---- {yolov5 => yolo5}/models/yolov5l.yaml | 0 {yolov5 => yolo5}/models/yolov5m.yaml | 0 {yolov5 => yolo5}/models/yolov5s.yaml | 0 {yolov5 => yolo5}/models/yolov5x.yaml | 0 {yolov5 => yolo5}/test.py | 8 ++++---- {yolov5 => yolo5}/train.py | 12 ++++++------ {yolov5 => yolo5}/utils/__init__.py | 0 {yolov5 => yolo5}/utils/activations.py | 0 {yolov5 => yolo5}/utils/datasets.py | 2 +- {yolov5 => yolo5}/utils/general.py | 4 ++-- {yolov5 => yolo5}/utils/google_utils.py | 2 +- {yolov5 => yolo5}/utils/torch_utils.py | 0 24 files changed, 36 insertions(+), 36 deletions(-) rename {yolov5 => yolo5}/__init__.py (100%) rename {yolov5 => yolo5}/detect.py (95%) rename {yolov5 => yolo5}/hubconf.py (94%) rename {yolov5 => yolo5}/models/__init__.py (100%) rename {yolov5 => yolo5}/models/common.py (100%) rename {yolov5 => yolo5}/models/experimental.py (98%) rename {yolov5 => yolo5}/models/export.py (98%) rename {yolov5 => yolo5}/models/hub/yolov3-spp.yaml (100%) rename {yolov5 => yolo5}/models/hub/yolov5-fpn.yaml (100%) rename {yolov5 => yolo5}/models/hub/yolov5-panet.yaml (100%) rename {yolov5 => yolo5}/models/yolo.py (97%) rename {yolov5 => yolo5}/models/yolov5l.yaml (100%) rename {yolov5 => yolo5}/models/yolov5m.yaml (100%) rename {yolov5 => yolo5}/models/yolov5s.yaml (100%) rename {yolov5 => yolo5}/models/yolov5x.yaml (100%) rename {yolov5 => yolo5}/test.py (98%) rename {yolov5 => yolo5}/train.py (98%) rename {yolov5 => yolo5}/utils/__init__.py (100%) rename {yolov5 => yolo5}/utils/activations.py (100%) rename {yolov5 => yolo5}/utils/datasets.py (99%) rename {yolov5 => yolo5}/utils/general.py (99%) rename {yolov5 => yolo5}/utils/google_utils.py (99%) rename {yolov5 => yolo5}/utils/torch_utils.py (100%) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 3a1a6fb61f2d..f1c135e40303 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -53,7 +53,7 @@ jobs: - name: Download data run: | - python -c "from yolov5.utils.google_utils import * ; gdrive_download('1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', 'coco128.zip')" + python -c "from yolo5.utils.google_utils import * ; gdrive_download('1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', 'coco128.zip')" mv ./coco128 ../ - name: Tests workflow @@ -62,14 +62,14 @@ jobs: di=cpu # inference devices # define device # train - python yolov5/train.py --img 256 --batch 8 --weights weights/${{ matrix.model }}.pt --cfg models/${{ matrix.model }}.yaml --epochs 1 --device $di + python yolo5/train.py --img 256 --batch 8 --weights weights/${{ matrix.model }}.pt --cfg models/${{ matrix.model }}.yaml --epochs 1 --device $di # detect - python yolov5/detect.py --weights weights/${{ matrix.model }}.pt --device $di - python yolov5/detect.py --weights runs/exp0/weights/last.pt --device $di + python yolo5/detect.py --weights weights/${{ matrix.model }}.pt --device $di + python yolo5/detect.py --weights runs/exp0/weights/last.pt --device $di # test - python yolov5/test.py --img 256 --batch 8 --weights weights/${{ matrix.model }}.pt --device $di - python yolov5/test.py --img 256 --batch 8 --weights runs/exp0/weights/last.pt --device $di + python yolo5/test.py --img 256 --batch 8 --weights weights/${{ matrix.model }}.pt --device $di + python yolo5/test.py --img 256 --batch 8 --weights runs/exp0/weights/last.pt --device $di - python yolov5/models/yolo.py --cfg models/${{ matrix.model }}.yaml # inspect - python yolov5/models/export.py --img 256 --batch 1 --weights weights/${{ matrix.model }}.pt # export + python yolo5/models/yolo.py --cfg models/${{ matrix.model }}.yaml # inspect + python yolo5/models/export.py --img 256 --batch 1 --weights weights/${{ matrix.model }}.pt # export shell: bash diff --git a/yolov5/__init__.py b/yolo5/__init__.py similarity index 100% rename from yolov5/__init__.py rename to yolo5/__init__.py diff --git a/yolov5/detect.py b/yolo5/detect.py similarity index 95% rename from yolov5/detect.py rename to yolo5/detect.py index c614d7ef218c..b3f0ef087dab 100644 --- a/yolov5/detect.py +++ b/yolo5/detect.py @@ -10,10 +10,10 @@ import torch.backends.cudnn as cudnn from numpy import random -from yolov5.models.experimental import attempt_load -from yolov5.utils.datasets import LoadStreams, LoadImages -from yolov5.utils.general import check_img_size, non_max_suppression, apply_classifier, scale_coords, xyxy2xywh, plot_one_box -from yolov5.utils.torch_utils import select_device, load_classifier, time_synchronized +from yolo5.models.experimental import attempt_load +from yolo5.utils.datasets import LoadStreams, LoadImages +from yolo5.utils.general import check_img_size, non_max_suppression, apply_classifier, scale_coords, xyxy2xywh, plot_one_box +from yolo5.utils.torch_utils import select_device, load_classifier, time_synchronized def detect(save_img=False): diff --git a/yolov5/hubconf.py b/yolo5/hubconf.py similarity index 94% rename from yolov5/hubconf.py rename to yolo5/hubconf.py index 26107f92f321..69c412b3af86 100644 --- a/yolov5/hubconf.py +++ b/yolo5/hubconf.py @@ -2,7 +2,7 @@ Usage: import torch - model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True, channels=3, classes=80) + model = torch.hub.load('ultralytics/yolo5', 'yolov5s', pretrained=True, channels=3, classes=80) """ dependencies = ['torch', 'yaml'] @@ -10,8 +10,8 @@ import torch -from yolov5.models.yolo import Model -from yolov5.utils.google_utils import attempt_download +from yolo5.models.yolo import Model +from yolo5.utils.google_utils import attempt_download def create(name, pretrained, channels, classes): diff --git a/yolov5/models/__init__.py b/yolo5/models/__init__.py similarity index 100% rename from yolov5/models/__init__.py rename to yolo5/models/__init__.py diff --git a/yolov5/models/common.py b/yolo5/models/common.py similarity index 100% rename from yolov5/models/common.py rename to yolo5/models/common.py diff --git a/yolov5/models/experimental.py b/yolo5/models/experimental.py similarity index 98% rename from yolov5/models/experimental.py rename to yolo5/models/experimental.py index 20c1706cd9e4..0438e0c30803 100644 --- a/yolov5/models/experimental.py +++ b/yolo5/models/experimental.py @@ -4,8 +4,8 @@ import torch import torch.nn as nn -from yolov5.models.common import Conv, DWConv -from yolov5.utils.google_utils import attempt_download +from yolo5.models.common import Conv, DWConv +from yolo5.utils.google_utils import attempt_download class CrossConv(nn.Module): diff --git a/yolov5/models/export.py b/yolo5/models/export.py similarity index 98% rename from yolov5/models/export.py rename to yolo5/models/export.py index aa76f0592061..cce33d4f5a43 100644 --- a/yolov5/models/export.py +++ b/yolo5/models/export.py @@ -8,7 +8,7 @@ import torch -from yolov5.utils.google_utils import attempt_download +from yolo5.utils.google_utils import attempt_download if __name__ == '__main__': parser = argparse.ArgumentParser() diff --git a/yolov5/models/hub/yolov3-spp.yaml b/yolo5/models/hub/yolov3-spp.yaml similarity index 100% rename from yolov5/models/hub/yolov3-spp.yaml rename to yolo5/models/hub/yolov3-spp.yaml diff --git a/yolov5/models/hub/yolov5-fpn.yaml b/yolo5/models/hub/yolov5-fpn.yaml similarity index 100% rename from yolov5/models/hub/yolov5-fpn.yaml rename to yolo5/models/hub/yolov5-fpn.yaml diff --git a/yolov5/models/hub/yolov5-panet.yaml b/yolo5/models/hub/yolov5-panet.yaml similarity index 100% rename from yolov5/models/hub/yolov5-panet.yaml rename to yolo5/models/hub/yolov5-panet.yaml diff --git a/yolov5/models/yolo.py b/yolo5/models/yolo.py similarity index 97% rename from yolov5/models/yolo.py rename to yolo5/models/yolo.py index c776b110da03..e092153dd87d 100644 --- a/yolov5/models/yolo.py +++ b/yolo5/models/yolo.py @@ -6,10 +6,10 @@ import torch import torch.nn as nn -from yolov5.models.common import Conv, Bottleneck, SPP, DWConv, Focus, BottleneckCSP, Concat -from yolov5.models.experimental import MixConv2d, CrossConv, C3 -from yolov5.utils.general import check_anchor_order, make_divisible, check_file -from yolov5.utils.torch_utils import ( +from yolo5.models.common import Conv, Bottleneck, SPP, DWConv, Focus, BottleneckCSP, Concat +from yolo5.models.experimental import MixConv2d, CrossConv, C3 +from yolo5.utils.general import check_anchor_order, make_divisible, check_file +from yolo5.utils.torch_utils import ( time_synchronized, fuse_conv_and_bn, model_info, scale_img, initialize_weights, select_device) diff --git a/yolov5/models/yolov5l.yaml b/yolo5/models/yolov5l.yaml similarity index 100% rename from yolov5/models/yolov5l.yaml rename to yolo5/models/yolov5l.yaml diff --git a/yolov5/models/yolov5m.yaml b/yolo5/models/yolov5m.yaml similarity index 100% rename from yolov5/models/yolov5m.yaml rename to yolo5/models/yolov5m.yaml diff --git a/yolov5/models/yolov5s.yaml b/yolo5/models/yolov5s.yaml similarity index 100% rename from yolov5/models/yolov5s.yaml rename to yolo5/models/yolov5s.yaml diff --git a/yolov5/models/yolov5x.yaml b/yolo5/models/yolov5x.yaml similarity index 100% rename from yolov5/models/yolov5x.yaml rename to yolo5/models/yolov5x.yaml diff --git a/yolov5/test.py b/yolo5/test.py similarity index 98% rename from yolov5/test.py rename to yolo5/test.py index 8068dc5017f3..c00cd8bbba82 100644 --- a/yolov5/test.py +++ b/yolo5/test.py @@ -10,12 +10,12 @@ import yaml from tqdm import tqdm -from yolov5.models.experimental import attempt_load -from yolov5.utils.datasets import create_dataloader -from yolov5.utils.general import ( +from yolo5.models.experimental import attempt_load +from yolo5.utils.datasets import create_dataloader +from yolo5.utils.general import ( coco80_to_coco91_class, check_file, check_img_size, compute_loss, non_max_suppression, scale_coords, xyxy2xywh, clip_coords, plot_images, xywh2xyxy, box_iou, output_to_target, ap_per_class) -from yolov5.utils.torch_utils import select_device, time_synchronized +from yolo5.utils.torch_utils import select_device, time_synchronized def test(data, diff --git a/yolov5/train.py b/yolo5/train.py similarity index 98% rename from yolov5/train.py rename to yolo5/train.py index ff11bb93484a..8d763455afac 100644 --- a/yolov5/train.py +++ b/yolo5/train.py @@ -18,15 +18,15 @@ from torch.utils.tensorboard import SummaryWriter from tqdm import tqdm -from yolov5 import test # import test.py to get mAP after each epoch -from yolov5.models.yolo import Model -from yolov5.utils.datasets import create_dataloader -from yolov5.utils.general import ( +from yolo5 import test # import test.py to get mAP after each epoch +from yolo5.models.yolo import Model +from yolo5.utils.datasets import create_dataloader +from yolo5.utils.general import ( check_img_size, torch_distributed_zero_first, labels_to_class_weights, plot_labels, check_anchors, labels_to_image_weights, compute_loss, plot_images, fitness, strip_optimizer, plot_results, get_latest_run, check_git_status, check_file, increment_dir, print_mutation) -from yolov5.utils.google_utils import attempt_download -from yolov5.utils.torch_utils import init_seeds, ModelEMA, select_device +from yolo5.utils.google_utils import attempt_download +from yolo5.utils.torch_utils import init_seeds, ModelEMA, select_device # Hyperparameters hyp = {'lr0': 0.01, # initial learning rate (SGD=1E-2, Adam=1E-3) diff --git a/yolov5/utils/__init__.py b/yolo5/utils/__init__.py similarity index 100% rename from yolov5/utils/__init__.py rename to yolo5/utils/__init__.py diff --git a/yolov5/utils/activations.py b/yolo5/utils/activations.py similarity index 100% rename from yolov5/utils/activations.py rename to yolo5/utils/activations.py diff --git a/yolov5/utils/datasets.py b/yolo5/utils/datasets.py similarity index 99% rename from yolov5/utils/datasets.py rename to yolo5/utils/datasets.py index 491c2512504f..773db8d22885 100755 --- a/yolov5/utils/datasets.py +++ b/yolo5/utils/datasets.py @@ -14,7 +14,7 @@ from torch.utils.data import Dataset from tqdm import tqdm -from yolov5.utils.general import xyxy2xywh, xywh2xyxy, torch_distributed_zero_first +from yolo5.utils.general import xyxy2xywh, xywh2xyxy, torch_distributed_zero_first help_url = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data' img_formats = ['.bmp', '.jpg', '.jpeg', '.png', '.tif', '.tiff', '.dng'] diff --git a/yolov5/utils/general.py b/yolo5/utils/general.py similarity index 99% rename from yolov5/utils/general.py rename to yolo5/utils/general.py index a6020e144c20..cdd7586dade7 100755 --- a/yolov5/utils/general.py +++ b/yolo5/utils/general.py @@ -22,7 +22,7 @@ from scipy.signal import butter, filtfilt from tqdm import tqdm -from yolov5.utils.torch_utils import init_seeds, is_parallel +from yolo5.utils.torch_utils import init_seeds, is_parallel # Set printoptions torch.set_printoptions(linewidth=320, precision=5, profile='long') @@ -763,7 +763,7 @@ def print_results(k): if isinstance(path, str): # *.yaml file with open(path) as f: data_dict = yaml.load(f, Loader=yaml.FullLoader) # model dict - from utils.datasets import LoadImagesAndLabels + from yolo5.utils.datasets import LoadImagesAndLabels dataset = LoadImagesAndLabels(data_dict['train'], augment=True, rect=True) else: dataset = path # dataset diff --git a/yolov5/utils/google_utils.py b/yolo5/utils/google_utils.py similarity index 99% rename from yolov5/utils/google_utils.py rename to yolo5/utils/google_utils.py index ca9600b35a13..96201724116f 100644 --- a/yolov5/utils/google_utils.py +++ b/yolo5/utils/google_utils.py @@ -27,7 +27,7 @@ def attempt_download(weights): if not (r == 0 and os.path.exists(weights) and os.path.getsize(weights) > 1E6): # weights exist and > 1MB os.remove(weights) if os.path.exists(weights) else None # remove partial downloads - s = "curl -L -o %s 'storage.googleapis.com/ultralytics/yolov5/ckpt/%s'" % (weights, file) + s = "curl -L -o %s 'storage.googleapis.com/ultralytics/yolo5/ckpt/%s'" % (weights, file) r = os.system(s) # execute, capture return values # Error check diff --git a/yolov5/utils/torch_utils.py b/yolo5/utils/torch_utils.py similarity index 100% rename from yolov5/utils/torch_utils.py rename to yolo5/utils/torch_utils.py From 6311d124152d5ea0dc5361c40b13157e13ddf0c0 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 10:28:02 +0200 Subject: [PATCH 05/15] ci: paths --- .github/workflows/ci-testing.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index f1c135e40303..fbcbf5de04de 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -62,14 +62,14 @@ jobs: di=cpu # inference devices # define device # train - python yolo5/train.py --img 256 --batch 8 --weights weights/${{ matrix.model }}.pt --cfg models/${{ matrix.model }}.yaml --epochs 1 --device $di + python yolo5/train.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --cfg ./models/${{ matrix.model }}.yaml --epochs 1 --device $di # detect - python yolo5/detect.py --weights weights/${{ matrix.model }}.pt --device $di - python yolo5/detect.py --weights runs/exp0/weights/last.pt --device $di + python yolo5/detect.py --weights ./weights/${{ matrix.model }}.pt --device $di + python yolo5/detect.py --weights ./runs/exp0/weights/last.pt --device $di # test - python yolo5/test.py --img 256 --batch 8 --weights weights/${{ matrix.model }}.pt --device $di - python yolo5/test.py --img 256 --batch 8 --weights runs/exp0/weights/last.pt --device $di + python yolo5/test.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --device $di + python yolo5/test.py --img 256 --batch 8 --weights ./runs/exp0/weights/last.pt --device $di - python yolo5/models/yolo.py --cfg models/${{ matrix.model }}.yaml # inspect - python yolo5/models/export.py --img 256 --batch 1 --weights weights/${{ matrix.model }}.pt # export + python yolo5/models/yolo.py --cfg ./models/${{ matrix.model }}.yaml # inspect + python yolo5/models/export.py --img 256 --batch 1 --weights ./weights/${{ matrix.model }}.pt # export shell: bash From 5b539b203639432150b16599d2731fdcdf18bd24 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 11:10:01 +0200 Subject: [PATCH 06/15] export --- .github/workflows/ci-testing.yml | 6 ++++-- yolo5/{models => }/export.py | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) rename yolo5/{models => }/export.py (98%) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index fbcbf5de04de..10a14ff21f1b 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -70,6 +70,8 @@ jobs: python yolo5/test.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --device $di python yolo5/test.py --img 256 --batch 8 --weights ./runs/exp0/weights/last.pt --device $di - python yolo5/models/yolo.py --cfg ./models/${{ matrix.model }}.yaml # inspect - python yolo5/models/export.py --img 256 --batch 1 --weights ./weights/${{ matrix.model }}.pt # export + # inspect + python yolo5/models/yolo.py --cfg ./models/${{ matrix.model }}.yaml + # export + python yolo5/export.py --img 256 --batch 1 --weights ./weights/${{ matrix.model }}.pt shell: bash diff --git a/yolo5/models/export.py b/yolo5/export.py similarity index 98% rename from yolo5/models/export.py rename to yolo5/export.py index cce33d4f5a43..9e95bf6b4d40 100644 --- a/yolo5/models/export.py +++ b/yolo5/export.py @@ -10,15 +10,8 @@ from yolo5.utils.google_utils import attempt_download -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--weights', type=str, default='./yolov5s.pt', help='weights path') - parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='image size') - parser.add_argument('--batch-size', type=int, default=1, help='batch size') - opt = parser.parse_args() - opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand - print(opt) +def main(opt): # Input img = torch.zeros((opt.batch_size, 3, *opt.img_size)) # image size(1,3,320,192) iDetection @@ -72,3 +65,14 @@ # Finish print('\nExport complete. Visualize with https://github.com/lutzroeder/netron.') + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--weights', type=str, default='./yolov5s.pt', help='weights path') + parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='image size') + parser.add_argument('--batch-size', type=int, default=1, help='batch size') + opt = parser.parse_args() + opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand + print(opt) + + main(opt) From fd7ea3761c92dceb8a357d7e6a2f775637de0405 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 11:21:58 +0200 Subject: [PATCH 07/15] pytest --- .github/workflows/ci-testing.yml | 38 ++++++++++++++++++-------------- setup.cfg | 30 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 setup.cfg diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 10a14ff21f1b..efe46684a9ef 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -56,22 +56,26 @@ jobs: python -c "from yolo5.utils.google_utils import * ; gdrive_download('1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', 'coco128.zip')" mv ./coco128 ../ - - name: Tests workflow - run: | - export PYTHONPATH="$PWD" # to run *.py. files in subdirectories - di=cpu # inference devices # define device + - name: PyTest + run: | + pip install -q pytest + python -m pytest yolo5 - # train - python yolo5/train.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --cfg ./models/${{ matrix.model }}.yaml --epochs 1 --device $di - # detect - python yolo5/detect.py --weights ./weights/${{ matrix.model }}.pt --device $di - python yolo5/detect.py --weights ./runs/exp0/weights/last.pt --device $di - # test - python yolo5/test.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --device $di - python yolo5/test.py --img 256 --batch 8 --weights ./runs/exp0/weights/last.pt --device $di - # inspect - python yolo5/models/yolo.py --cfg ./models/${{ matrix.model }}.yaml - # export - python yolo5/export.py --img 256 --batch 1 --weights ./weights/${{ matrix.model }}.pt - shell: bash + - name: Tests workflow + run: | + export PYTHONPATH="$PWD" # to run *.py. files in subdirectories + di=cpu # inference devices # define device + # train + python yolo5/train.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --cfg ./models/${{ matrix.model }}.yaml --epochs 1 --device $di + # detect + python yolo5/detect.py --weights ./weights/${{ matrix.model }}.pt --device $di + python yolo5/detect.py --weights ./runs/exp0/weights/last.pt --device $di + # test + python yolo5/test.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --device $di + python yolo5/test.py --img 256 --batch 8 --weights ./runs/exp0/weights/last.pt --device $di + # inspect + python yolo5/models/yolo.py --cfg ./models/${{ matrix.model }}.yaml + # export + python yolo5/export.py --img 256 --batch 1 --weights ./weights/${{ matrix.model }}.pt + shell: bash diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 000000000000..5874854a05c8 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,30 @@ +[metadata] +# This includes the license file(s) in the wheel. +# https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file +license_files = LICENSE + +[bdist_wheel] +# This flag says to generate wheels that support both Python 2 and Python +# 3. If your code will not run unchanged on both Python 2 and 3, you will +# need to generate separate wheels for each Python version that you +# support. Removing this line (or setting universal to 0) will prevent +# bdist_wheel from trying to make a universal wheel. For more see: +# https://packaging.python.org/guides/distributing-packages-using-setuptools/#wheels +universal=1 + +[flake8] +# http://flake8.pycqa.org/en/latest/user/configuration.html +ignore = E501 +max-line-length = 100 +exclude = *.egg,build,temp +select = E,W,F +doctests = True +verbose = 2 +# max-complexity = 10 + +[tool:pytest] +log_cli = 1 +log_cli_level = CRITICAL +log_file = pytest.log +log_file_level = DEBUG +filterwarnings = ignore::FutureWarning From df939c645be353362e16a0408b2d7713fe0df0a7 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 11:42:50 +0200 Subject: [PATCH 08/15] add setup --- setup.py | 141 ++++++++++++++++++++++++++++++++++++++++++++++ yolo5/__init__.py | 12 ++++ 2 files changed, 153 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 000000000000..8347baa0f021 --- /dev/null +++ b/setup.py @@ -0,0 +1,141 @@ +"""A setuptools based setup module. + +See: +https://packaging.python.org/guides/distributing-packages-using-setuptools/ +https://github.com/pypa/sampleproject +""" + +# Always prefer setuptools over distutils +from os import path +from setuptools import setup, find_packages + +import yolo5 + +PATH_HERE = path.abspath(path.dirname(__file__)) + +with open(path.join(PATH_HERE, 'requirements.txt')) as fp: + install_reqs = [r.rstrip() for r in fp.readlines() if not r.startswith('#')] + +# Get the long description from the README file +with open(path.join(PATH_HERE, 'README.md'), encoding='utf-8') as fp: + long_description = fp.read() + +# Arguments marked as "Required" below must be included for upload to PyPI. +# Fields marked as "Optional" may be commented out. + +setup( + # This is the name of your project. The first time you publish this + # package, this name will be registered for you. It will determine how + # users can install this project, e.g.: + # + # $ pip install YOLOv5 + # + # And where it will live on PyPI: https://pypi.org/project/YOLOv5/ + name='YOLOv5', # Required + version=yolo5.__version__, # Required + description=yolo5.__doc__, # Optional + + # This is an optional longer description of your project that represents + # the body of text which users will see when they visit PyPI. + long_description=yolo5.__doc_long__, # Optional + + # Denotes that our long_description is in Markdown; valid values are + # text/plain, text/x-rst, and text/markdown + long_description_content_type='text/markdown', # Optional (see note above) + + # This should be a valid link to your project's main homepage. + url='https://github.com/ultralytics/yolov5', # Optional + + # This should be your name or the name of the organization which owns the project. + author='Ultralytics', # Optional + # This should be a valid email address corresponding to the author listed above. + author_email='glenn.jocher@ultralytics.com', # Optional + + # Classifiers help users find your project by categorizing it. + # For a list of valid classifiers, see https://pypi.org/classifiers/ + classifiers=[ # Optional + # How mature is this project? Common values are + # 3 - Alpha + # 4 - Beta + # 5 - Production/Stable + 'Development Status :: 5 - Production/Stable', + + # Indicate who your project is intended for + 'Intended Audience :: Developers', + + # Operation system + 'Operating System :: OS Independent', + + # Topics + 'Topic :: Education', + 'Topic :: Scientific/Engineering', + 'Topic :: Scientific/Engineering :: Artificial Intelligence', + 'Topic :: Scientific/Engineering :: Image Recognition', + + # Pick your license as you wish + 'License :: OSI Approved :: Apache Software License', + + # Specify the Python versions you support here. In particular, ensure + # that you indicate whether you support Python 2, Python 3 or both. + # These classifiers are *not* checked by 'pip install'. See instead + # 'python_requires' below. + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + ], + + # This field adds keywords for your project which will appear on the + # project page. What does your project relate to? + # + # Note that this is a string of words separated by whitespace, not a list. + keywords='YOLO object-detection', # Optional + + # You can just specify package directories manually here if your project is + # simple. Or you can use find_packages(). + # + # Alternatively, if you just want to distribute a single Python file, use + # the `py_modules` argument instead as follows, which will expect a file + # called `my_module.py` to exist: + # + # py_modules=["my_module"], + # + packages=find_packages(exclude=['contrib', 'docs', 'tests']), # Required + + # Specify which Python versions you support. In contrast to the + # 'Programming Language' classifiers above, 'pip install' will check this + # and refuse to install the project if the version does not match. If you + # do not support Python 2, you can simplify this to '>=3.5' or similar, see + # https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires + python_requires='>=3.6, <4', + install_requires=install_reqs, + + # This field lists other packages that your project depends on to run. + # Any package you put here will be installed by pip when your project is + # installed, so they must be valid existing projects. + # install_requires=[], # Optional + + # Although 'package_data' is the preferred approach, in some case you may + # need to place data files outside of your packages. See: + # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files + # + # In this case, 'data_file' will be installed into '/my_data' + data_files=[('models', ['yolo5/models/*.yaml', 'yolo5/models/hub/*.yaml'])], # Optional + + # To provide executable scripts, use entry points in preference to the + # "scripts" keyword. Entry points provide cross-platform support and allow + # `pip` to create the appropriate form of executable for the target + # platform. + # entry_points={ # Optional + # 'console_scripts': [ + # 'sandbox=sandbox:main', + # ], + # }, + + # List additional URLs that are relevant to your project as a dict. + project_urls={ # Optional + 'Bug Reports': 'https://github.com/ultralytics/yolov5/issues', + 'Funding': 'https://www.ultralytics.com', + 'Source': 'https://github.com/ultralytics/yolov5/', + }, +) diff --git a/yolo5/__init__.py b/yolo5/__init__.py index e69de29bb2d1..24dbf3d6c15e 100644 --- a/yolo5/__init__.py +++ b/yolo5/__init__.py @@ -0,0 +1,12 @@ +__version__ = '2.0' +__doc__ = "YOLO v5 - object detection network" +__doc_long__ = """ +# YOLO v5 + +This repository represents Ultralytics open-source research into future object detection methods, + and incorporates our lessons learned and best practices evolved over training thousands of models + on custom client datasets with our previous YOLO repository https://github.com/ultralytics/yolov3. + +**All code and models are under active development, and are subject to modification or deletion without notice.** + Use at your own risk. +""" \ No newline at end of file From 08715848df35a7a99b32aa138ad138ea6782e271 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 12:04:14 +0200 Subject: [PATCH 09/15] add manifest --- MANIFEST.in | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000000..6cef8dcf6d70 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,39 @@ +# Manifest syntax https://docs.python.org/2/distutils/sourcedist.html +graft wheelhouse + +recursive-exclude __pycache__ *.pyc *.pyo *.orig + +# Include the README +include *.md + +# Include the license file +include LICENSE + +# Include the Requirements +include requirements.txt + +# Include package +recursive-include yolo5 *.py *.yaml + +# Include setup +include setup.* + +# Exclude testing +exclude pytest.* +recursive-exclude tests * +exclude tests + +# Exclude experiments +exclude */*.sh +exclude *.ipynb +exclude Dockerfile .dockerignore + +prune .git +prune .github +prune run +prune venv +prune build +prune docs +prune tests +prune data +prune inference From 14a669c25656fd4b0ba760c877af98491bb0897e Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 12:04:29 +0200 Subject: [PATCH 10/15] test install --- .github/workflows/ci-testing.yml | 23 +++++++++++++++++++---- setup.py | 6 +++++- yolo5/__init__.py | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index efe46684a9ef..8029b01a9ec6 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -56,10 +56,11 @@ jobs: python -c "from yolo5.utils.google_utils import * ; gdrive_download('1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', 'coco128.zip')" mv ./coco128 ../ - - name: PyTest - run: | - pip install -q pytest - python -m pytest yolo5 + - name: PyTest + run: | + pip install -q pytest pytest-flake8 + # todo: make code pep8 complient and uncoment this Flake8 check + python -m pytest yolo5 # --flake8 - name: Tests workflow @@ -79,3 +80,17 @@ jobs: # export python yolo5/export.py --img 256 --batch 1 --weights ./weights/${{ matrix.model }}.pt shell: bash + + - name: Test Install + run: | + pip install -q check-manifest twine + + check-manifest + python setup.py check --metadata --strict + + # Build the package + python setup.py sdist bdist_wheel + twine check ./dist/* + + # Dry run install + python setup.py install --dry-run diff --git a/setup.py b/setup.py index 8347baa0f021..6f6287da8694 100644 --- a/setup.py +++ b/setup.py @@ -120,7 +120,11 @@ # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # # In this case, 'data_file' will be installed into '/my_data' - data_files=[('models', ['yolo5/models/*.yaml', 'yolo5/models/hub/*.yaml'])], # Optional + data_files=[('models', + [f'yolo5/models/yolov5{n}.yaml' for n in 'smlx'] + + ['yolo5/models/hub/yolov3-spp.yaml'] + + [f'yolo5/models/hub/yolov5-{n}.yaml' for n in ('fpn', 'panet')] + )], # Optional # To provide executable scripts, use entry points in preference to the # "scripts" keyword. Entry points provide cross-platform support and allow diff --git a/yolo5/__init__.py b/yolo5/__init__.py index 24dbf3d6c15e..a934385017fe 100644 --- a/yolo5/__init__.py +++ b/yolo5/__init__.py @@ -1,4 +1,4 @@ -__version__ = '2.0' +__version__ = '2.0rc1' __doc__ = "YOLO v5 - object detection network" __doc_long__ = """ # YOLO v5 From 1be57e9872941b2975dcaca27829f5cbc4f1d5f5 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 12:19:28 +0200 Subject: [PATCH 11/15] add sample doctest --- .github/workflows/ci-testing.yml | 8 ++++---- yolo5/utils/torch_utils.py | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 8029b01a9ec6..cc5e71fa623d 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -58,10 +58,10 @@ jobs: - name: PyTest run: | - pip install -q pytest pytest-flake8 - # todo: make code pep8 complient and uncoment this Flake8 check - python -m pytest yolo5 # --flake8 - + pip install -q coverage pytest pytest-flake8 + # todo: make code PEP8 complient and uncoment this Flake8 check + coverage run --source yolo5 -m pytest yolo5 --doctest-modules # --flake8 + coverage report - name: Tests workflow run: | diff --git a/yolo5/utils/torch_utils.py b/yolo5/utils/torch_utils.py index f61d29ec191f..e87b6db40115 100644 --- a/yolo5/utils/torch_utils.py +++ b/yolo5/utils/torch_utils.py @@ -11,6 +11,11 @@ def init_seeds(seed=0): + """ + Example: + + >>> init_seeds(42) + """ torch.manual_seed(seed) # Speed-reproducibility tradeoff https://pytorch.org/docs/stable/notes/randomness.html From ab8698142b015c668fe008b4d97b8aa15ddf6674 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 14:46:21 +0200 Subject: [PATCH 12/15] update --- setup.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/setup.py b/setup.py index 6f6287da8694..af135f947a48 100644 --- a/setup.py +++ b/setup.py @@ -87,19 +87,10 @@ # This field adds keywords for your project which will appear on the # project page. What does your project relate to? - # - # Note that this is a string of words separated by whitespace, not a list. keywords='YOLO object-detection', # Optional # You can just specify package directories manually here if your project is # simple. Or you can use find_packages(). - # - # Alternatively, if you just want to distribute a single Python file, use - # the `py_modules` argument instead as follows, which will expect a file - # called `my_module.py` to exist: - # - # py_modules=["my_module"], - # packages=find_packages(exclude=['contrib', 'docs', 'tests']), # Required # Specify which Python versions you support. In contrast to the From 25ef3ac508861790ccd52cb0436e050d48747a55 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 21 Jul 2020 15:37:47 +0200 Subject: [PATCH 13/15] readme --- README.md | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 65ce5f301add..d6e61d0d6dec 100755 --- a/README.md +++ b/README.md @@ -41,6 +41,13 @@ Python 3.7 or later with all `requirements.txt` dependencies installed, includin $ pip install -U -r requirements.txt ``` +## Installation + +You can install this package straight with pip +```bash +pip install git+https://github.com/ultralytics/yolov5.git +``` + ## Tutorials @@ -68,19 +75,19 @@ YOLOv5 may be run in any of the following up-to-date verified environments (with Inference can be run on most common media formats. Model [checkpoints](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J) are downloaded automatically if available. Results are saved to `./inference/output`. ```bash -$ python detect.py --source 0 # webcam - file.jpg # image - file.mp4 # video - path/ # directory - path/*.jpg # glob - rtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa # rtsp stream - http://112.50.243.8/PLTV/88888888/224/3221225900/1.m3u8 # http stream +$ python yolo5/detect.py --source 0 # webcam + file.jpg # image + file.mp4 # video + path/ # directory + path/*.jpg # glob + rtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa # rtsp stream + http://112.50.243.8/PLTV/88888888/224/3221225900/1.m3u8 # http stream ``` To run inference on examples in the `./inference/images` folder: ```bash -$ python detect.py --source ./inference/images/ --weights yolov5s.pt --conf 0.4 +$ python yolo5/detect.py --source ./inference/images/ --weights yolov5s.pt --conf 0.4 Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='', fourcc='mp4v', half=False, img_size=640, iou_thres=0.5, output='inference/output', save_txt=False, source='./inference/images/', view_img=False, weights='yolov5s.pt') Using CUDA device0 _CudaDeviceProperties(name='Tesla P100-PCIE-16GB', total_memory=16280MB) @@ -99,10 +106,10 @@ Results saved to /content/yolov5/inference/output Download [COCO](https://github.com/ultralytics/yolov5/blob/master/data/get_coco2017.sh), install [Apex](https://github.com/NVIDIA/apex) and run command below. Training times for YOLOv5s/m/l/x are 2/4/6/8 days on a single V100 (multi-GPU times faster). Use the largest `--batch-size` your GPU allows (batch sizes shown for 16 GB devices). ```bash -$ python train.py --data coco.yaml --cfg yolov5s.yaml --weights '' --batch-size 64 - yolov5m 48 - yolov5l 32 - yolov5x 16 +$ python yolo5/train.py --data coco.yaml --cfg yolov5s.yaml --weights '' --batch-size 64 + yolov5m 48 + yolov5l 32 + yolov5x 16 ``` From 0c1a5cc6d15d14de3ecafb9b9563356e18b696b4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 21 Jul 2020 14:37:43 -0700 Subject: [PATCH 14/15] Update google_utils.py --- yolo5/utils/google_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yolo5/utils/google_utils.py b/yolo5/utils/google_utils.py index 96201724116f..ca9600b35a13 100644 --- a/yolo5/utils/google_utils.py +++ b/yolo5/utils/google_utils.py @@ -27,7 +27,7 @@ def attempt_download(weights): if not (r == 0 and os.path.exists(weights) and os.path.getsize(weights) > 1E6): # weights exist and > 1MB os.remove(weights) if os.path.exists(weights) else None # remove partial downloads - s = "curl -L -o %s 'storage.googleapis.com/ultralytics/yolo5/ckpt/%s'" % (weights, file) + s = "curl -L -o %s 'storage.googleapis.com/ultralytics/yolov5/ckpt/%s'" % (weights, file) r = os.system(s) # execute, capture return values # Error check From f316cccc2240e6fb41859a13ffd2e0b0d2d5496c Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Mon, 3 Aug 2020 01:28:03 +0200 Subject: [PATCH 15/15] fix --- .github/workflows/ci-testing.yml | 48 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index cc5e71fa623d..d33336213c0c 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -63,34 +63,34 @@ jobs: coverage run --source yolo5 -m pytest yolo5 --doctest-modules # --flake8 coverage report - - name: Tests workflow - run: | - export PYTHONPATH="$PWD" # to run *.py. files in subdirectories - di=cpu # inference devices # define device - # train - python yolo5/train.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --cfg ./models/${{ matrix.model }}.yaml --epochs 1 --device $di - # detect - python yolo5/detect.py --weights ./weights/${{ matrix.model }}.pt --device $di - python yolo5/detect.py --weights ./runs/exp0/weights/last.pt --device $di - # test - python yolo5/test.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --device $di - python yolo5/test.py --img 256 --batch 8 --weights ./runs/exp0/weights/last.pt --device $di - # inspect - python yolo5/models/yolo.py --cfg ./models/${{ matrix.model }}.yaml - # export - python yolo5/export.py --img 256 --batch 1 --weights ./weights/${{ matrix.model }}.pt - shell: bash + - name: Tests workflow + run: | + export PYTHONPATH="$PWD" # to run *.py. files in subdirectories + di=cpu # inference devices # define device + # train + python yolo5/train.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --cfg ./models/${{ matrix.model }}.yaml --epochs 1 --device $di + # detect + python yolo5/detect.py --weights ./weights/${{ matrix.model }}.pt --device $di + python yolo5/detect.py --weights ./runs/exp0/weights/last.pt --device $di + # test + python yolo5/test.py --img 256 --batch 8 --weights ./weights/${{ matrix.model }}.pt --device $di + python yolo5/test.py --img 256 --batch 8 --weights ./runs/exp0/weights/last.pt --device $di + # inspect + python yolo5/models/yolo.py --cfg ./models/${{ matrix.model }}.yaml + # export + python yolo5/export.py --img 256 --batch 1 --weights ./weights/${{ matrix.model }}.pt + shell: bash - name: Test Install run: | pip install -q check-manifest twine - check-manifest - python setup.py check --metadata --strict + check-manifest + python setup.py check --metadata --strict - # Build the package - python setup.py sdist bdist_wheel - twine check ./dist/* + # Build the package + python setup.py sdist bdist_wheel + twine check ./dist/* - # Dry run install - python setup.py install --dry-run + # Dry run install + python setup.py install --dry-run