Skip to content

Commit

Permalink
update to ultralytics/yolov5 04.08.22 (#131)
Browse files Browse the repository at this point in the history
* update files

* update readme

* fix val

* update version to 6.1.7
  • Loading branch information
fcakyon authored Aug 4, 2022
1 parent defc4f7 commit c27bf14
Show file tree
Hide file tree
Showing 35 changed files with 2,025 additions and 618 deletions.
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/177da7f348181abdf4820ad26707eb8b3dd4fdc9">at this commit</a> plus:
This yolov5 package contains everything from ultralytics/yolov5 <a href="https://github.com/ultralytics/yolov5/tree/84e7748564f83ba04601770f17a38cc55e6be661">at this commit</a> plus:
<br>
1. Easy installation via pip: `pip install yolov5`
<br>
Expand Down
24 changes: 15 additions & 9 deletions requirements.txt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
# pip install -r requirements.txt
# YOLOv5 requirements
# Usage: pip install -r requirements.txt

# Base ----------------------------------------
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.2
opencv-python>=4.1.1
Pillow>=7.1.2
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1
torch>=1.7.0
torchvision>=0.8.1
tqdm>=4.41.0
tqdm>=4.64.0
protobuf<=3.20.1 # https://github.com/ultralytics/yolov5/issues/8012

# Logging -------------------------------------
tensorboard>=2.4.1
protobuf<=3.20.1
# wandb

# Plotting ------------------------------------
pandas>=1.1.4
seaborn>=0.11.0

# Export --------------------------------------
# coremltools>=4.1 # CoreML export
# coremltools>=5.2 # CoreML export
# onnx>=1.9.0 # ONNX export
# onnx-simplifier>=0.3.6 # ONNX simplifier
# onnx-simplifier>=0.4.1 # ONNX simplifier
# nvidia-pyindex # TensorRT export
# nvidia-tensorrt # TensorRT export
# scikit-learn==0.19.2 # CoreML quantization
# tensorflow>=2.4.1 # TFLite export
# tensorflow>=2.4.1 # TFLite export (or tensorflow-cpu, tensorflow-aarch64)
# tensorflowjs>=3.9.0 # TF.js export
# openvino-dev # OpenVINO export

# Extras --------------------------------------
ipython # interactive notebook
psutil # system utilization
thop>=0.1.1 # FLOPs computation
# albumentations>=1.0.3
# Cython # for pycocotools https://github.com/cocodataset/cocoapi/issues/172
# pycocotools>=2.0 # COCO mAP
# roboflow
thop # FLOPs computation

# CLI
fire
# AWS
Expand Down
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__ = "6.1.6"
__version__ = "6.1.7"
4 changes: 2 additions & 2 deletions yolov5/data/Argoverse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# parent
# ├── yolov5
# └── datasets
# └── Argoverse ← downloads here
# └── Argoverse ← downloads here (31.3 GB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
Expand Down Expand Up @@ -32,7 +32,7 @@ download: |
for annot in tqdm(a['annotations'], desc=f"Converting {set} to YOLOv5 format..."):
img_id = annot['image_id']
img_name = a['images'][img_id]['name']
img_label_name = img_name[:-3] + "txt"
img_label_name = f'{img_name[:-3]}txt'
cls = annot['category_id'] # instance class id
x_center, y_center, width, height = annot['bbox']
Expand Down
2 changes: 1 addition & 1 deletion yolov5/data/GlobalWheat2020.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# parent
# ├── yolov5
# └── datasets
# └── GlobalWheat2020 ← downloads here
# └── GlobalWheat2020 ← downloads here (7.0 GB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
Expand Down
7 changes: 4 additions & 3 deletions yolov5/data/Objects365.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# parent
# ├── yolov5
# └── datasets
# └── Objects365 ← downloads here
# └── Objects365 ← downloads here (712 GB = 367G data + 345G zips)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
Expand Down Expand Up @@ -60,11 +60,12 @@ names: ['Person', 'Sneakers', 'Chair', 'Other Shoes', 'Hat', 'Car', 'Lamp', 'Gla

# Download script/URL (optional) ---------------------------------------------------------------------------------------
download: |
from pycocotools.coco import COCO
from tqdm import tqdm
from utils.general import Path, download, np, xyxy2xywhn
from utils.general import Path, check_requirements, download, np, xyxy2xywhn
check_requirements(('pycocotools>=2.0',))
from pycocotools.coco import COCO
# Make Directories
dir = Path(yaml['path']) # dataset root dir
Expand Down
2 changes: 1 addition & 1 deletion yolov5/data/SKU-110K.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# parent
# ├── yolov5
# └── datasets
# └── SKU-110K ← downloads here
# └── SKU-110K ← downloads here (13.6 GB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
Expand Down
15 changes: 8 additions & 7 deletions yolov5/data/VOC.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# parent
# ├── yolov5
# └── datasets
# └── VOC ← downloads here
# └── VOC ← downloads here (2.8 GB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
Expand Down Expand Up @@ -59,20 +59,21 @@ download: |
# Download
dir = Path(yaml['path']) # dataset root dir
url = 'https://github.com/ultralytics/yolov5/releases/download/v1.0/'
urls = [url + 'VOCtrainval_06-Nov-2007.zip', # 446MB, 5012 images
url + 'VOCtest_06-Nov-2007.zip', # 438MB, 4953 images
url + 'VOCtrainval_11-May-2012.zip'] # 1.95GB, 17126 images
download(urls, dir=dir / 'images', delete=False, threads=3)
urls = [f'{url}VOCtrainval_06-Nov-2007.zip', # 446MB, 5012 images
f'{url}VOCtest_06-Nov-2007.zip', # 438MB, 4953 images
f'{url}VOCtrainval_11-May-2012.zip'] # 1.95GB, 17126 images
download(urls, dir=dir / 'images', delete=False, curl=True, threads=3)
# Convert
path = dir / f'images/VOCdevkit'
path = dir / 'images/VOCdevkit'
for year, image_set in ('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test'):
imgs_path = dir / 'images' / f'{image_set}{year}'
lbs_path = dir / 'labels' / f'{image_set}{year}'
imgs_path.mkdir(exist_ok=True, parents=True)
lbs_path.mkdir(exist_ok=True, parents=True)
image_ids = open(path / f'VOC{year}/ImageSets/Main/{image_set}.txt').read().strip().split()
with open(path / f'VOC{year}/ImageSets/Main/{image_set}.txt') as f:
image_ids = f.read().strip().split()
for id in tqdm(image_ids, desc=f'{image_set}{year}'):
f = path / f'VOC{year}/JPEGImages/{id}.jpg' # old img path
lb_path = (lbs_path / f.name).with_suffix('.txt') # new label path
Expand Down
4 changes: 2 additions & 2 deletions yolov5/data/VisDrone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# parent
# ├── yolov5
# └── datasets
# └── VisDrone ← downloads here
# └── VisDrone ← downloads here (2.3 GB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
Expand Down Expand Up @@ -54,7 +54,7 @@ download: |
'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-val.zip',
'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-test-dev.zip',
'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-test-challenge.zip']
download(urls, dir=dir, threads=4)
download(urls, dir=dir, curl=True, threads=4)
# Convert
for d in 'VisDrone2019-DET-train', 'VisDrone2019-DET-val', 'VisDrone2019-DET-test-dev':
Expand Down
2 changes: 1 addition & 1 deletion yolov5/data/coco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# parent
# ├── yolov5
# └── datasets
# └── coco ← downloads here
# └── coco ← downloads here (20.1 GB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
Expand Down
2 changes: 1 addition & 1 deletion yolov5/data/coco128.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# parent
# ├── yolov5
# └── datasets
# └── coco128 ← downloads here
# └── coco128 ← downloads here (7 MB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
Expand Down
2 changes: 1 addition & 1 deletion yolov5/data/xView.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# parent
# ├── yolov5
# └── datasets
# └── xView ← downloads here
# └── xView ← downloads here (20.7 GB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
Expand Down
26 changes: 15 additions & 11 deletions yolov5/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Run inference on images, videos, directories, streams, etc.
Usage - sources:
$ yolov5 detect --weights yolov5s.pt --source 0 # webcam
$ yolov5 detect --weights yolov5s.pt --source 0 # webcam
img.jpg # image
vid.mp4 # video
path/ # directory
Expand All @@ -12,7 +12,7 @@
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
Usage - formats:
$ yolov5 detect --weights yolov5s.pt # PyTorch
$ yolov5 detect --weights yolov5s.pt # PyTorch
yolov5s.torchscript # TorchScript
yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn
yolov5s.xml # OpenVINO
Expand All @@ -26,7 +26,7 @@

import argparse
import os
import sys
import platform
from pathlib import Path

import torch
Expand All @@ -37,10 +37,10 @@
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative

from yolov5.models.common import DetectMultiBackend
from yolov5.utils.datasets import (IMG_FORMATS, VID_FORMATS, LoadImages,
LoadStreams)
from yolov5.utils.dataloaders import (IMG_FORMATS, VID_FORMATS, LoadImages,
LoadStreams)
from yolov5.utils.general import (LOGGER, check_file, check_img_size,
check_imshow, check_requirements, colorstr,
check_imshow, colorstr,
cv2, increment_path, non_max_suppression,
print_args, scale_coords, strip_optimizer,
xyxy2xywh)
Expand Down Expand Up @@ -117,7 +117,7 @@ def run(

# Run inference
model.warmup(imgsz=(1 if pt else bs, 3, *imgsz)) # warmup
dt, seen = [0.0, 0.0, 0.0], 0
seen, windows, dt = 0, [], [0.0, 0.0, 0.0]
for path, im, im0s, vid_cap, s in dataset:
t1 = time_sync()
im = torch.from_numpy(im).to(device)
Expand Down Expand Up @@ -171,19 +171,23 @@ def run(
if save_txt: # Write to file
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
line = (cls, *xywh, conf) if save_conf else (cls, *xywh) # label format
with open(txt_path + '.txt', 'a') as f:
with open(f'{txt_path}.txt', 'a') as f:
f.write(('%g ' * len(line)).rstrip() % line + '\n')

if save_img or save_crop or view_img: # Add bbox to image
c = int(cls) # integer class
label = None if hide_labels else (names[c] if hide_conf else f'{names[c]} {conf:.2f}')
annotator.box_label(xyxy, label, color=colors(c, True))
if save_crop:
save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)
if save_crop:
save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)

# Stream results
im0 = annotator.result()
if view_img:
if platform.system() == 'Linux' and p not in windows:
windows.append(p)
cv2.namedWindow(str(p), cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO) # allow window resize (Linux)
cv2.resizeWindow(str(p), im0.shape[1], im0.shape[0])
cv2.imshow(str(p), im0)
cv2.waitKey(1) # 1 millisecond

Expand Down Expand Up @@ -216,7 +220,7 @@ def run(
s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
LOGGER.info(f"Results saved to {colorstr('bold', save_dir)}{s}")
if update:
strip_optimizer(weights) # update model (to fix SourceChangeWarning)
strip_optimizer(weights[0]) # update model (to fix SourceChangeWarning)


def parse_opt():
Expand Down
Loading

0 comments on commit c27bf14

Please sign in to comment.