-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
9,006 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# YOLOv5 π by Ultralytics, GPL-3.0 license | ||
# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC | ||
# Example usage: python train.py --data VOC.yaml | ||
# parent | ||
# βββ yolov5 | ||
# βββ datasets | ||
# βββ VOC β downloads here | ||
|
||
|
||
# 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, ..] | ||
path: /remote-home/hanchengye/data/VOC | ||
train: # train images (relative to 'path') 16551 images | ||
- voc_train.txt | ||
val: # val images (relative to 'path') 4952 images | ||
- 2007_test.txt | ||
test: # test images (optional) | ||
- 2007_test.txt | ||
|
||
# Classes | ||
nc: 20 # number of classes | ||
names: ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', | ||
'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'] # class names | ||
|
||
|
||
# Download script/URL (optional) --------------------------------------------------------------------------------------- | ||
download: | | ||
import xml.etree.ElementTree as ET | ||
from tqdm import tqdm | ||
from utils.general import download, Path | ||
def convert_label(path, lb_path, year, image_id): | ||
def convert_box(size, box): | ||
dw, dh = 1. / size[0], 1. / size[1] | ||
x, y, w, h = (box[0] + box[1]) / 2.0 - 1, (box[2] + box[3]) / 2.0 - 1, box[1] - box[0], box[3] - box[2] | ||
return x * dw, y * dh, w * dw, h * dh | ||
in_file = open(path / f'VOC{year}/Annotations/{image_id}.xml') | ||
out_file = open(lb_path, 'w') | ||
tree = ET.parse(in_file) | ||
root = tree.getroot() | ||
size = root.find('size') | ||
w = int(size.find('width').text) | ||
h = int(size.find('height').text) | ||
for obj in root.iter('object'): | ||
cls = obj.find('name').text | ||
if cls in yaml['names'] and not int(obj.find('difficult').text) == 1: | ||
xmlbox = obj.find('bndbox') | ||
bb = convert_box((w, h), [float(xmlbox.find(x).text) for x in ('xmin', 'xmax', 'ymin', 'ymax')]) | ||
cls_id = yaml['names'].index(cls) # class id | ||
out_file.write(" ".join([str(a) for a in (cls_id, *bb)]) + '\n') | ||
# 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) | ||
# Convert | ||
path = dir / f'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() | ||
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 | ||
f.rename(imgs_path / f.name) # move image | ||
convert_label(path, lb_path, year, id) # convert labels to YOLO format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# YOLOv5 π by Ultralytics, GPL-3.0 license | ||
# COCO 2017 dataset http://cocodataset.org | ||
# Example usage: python train.py --data coco.yaml | ||
# parent | ||
# βββ yolov5 | ||
# βββ datasets | ||
# βββ coco β downloads here | ||
|
||
|
||
# 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, ..] | ||
path: /remote-home/hanchengye/data/coco # dataset root dir | ||
train: train2017.txt # train images (relative to 'path') 118287 images | ||
val: val2017.txt # train images (relative to 'path') 5000 images | ||
test: test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794 | ||
|
||
# Classes | ||
nc: 80 # number of classes | ||
names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', | ||
'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', | ||
'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', | ||
'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', | ||
'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', | ||
'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', | ||
'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', | ||
'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', | ||
'hair drier', 'toothbrush'] # class names | ||
|
||
|
||
# Download script/URL (optional) | ||
download: | | ||
from utils.general import download, Path | ||
# Download labels | ||
segments = False # segment or box labels | ||
dir = Path(yaml['path']) # dataset root dir | ||
url = 'https://github.com/ultralytics/yolov5/releases/download/v1.0/' | ||
urls = [url + ('coco2017labels-segments.zip' if segments else 'coco2017labels.zip')] # labels | ||
download(urls, dir=dir.parent) | ||
# Download data | ||
urls = ['http://images.cocodataset.org/zips/train2017.zip', # 19G, 118k images | ||
'http://images.cocodataset.org/zips/val2017.zip', # 1G, 5k images | ||
'http://images.cocodataset.org/zips/test2017.zip'] # 7G, 41k images (optional) | ||
download(urls, dir=dir / 'images', threads=3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# YOLOv5 π by Ultralytics, GPL-3.0 license | ||
# Hyperparameters for VOC finetuning | ||
# python train.py --batch 64 --weights yolov5m.pt --data VOC.yaml --img 512 --epochs 50 | ||
# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials | ||
|
||
# Hyperparameter Evolution Results | ||
# Generations: 306 | ||
# P R mAP.5 mAP.5:.95 box obj cls | ||
# Metrics: 0.6 0.936 0.896 0.684 0.0115 0.00805 0.00146 | ||
|
||
lr0: 0.0032 | ||
lrf: 0.12 | ||
momentum: 0.843 | ||
weight_decay: 0.00036 | ||
warmup_epochs: 2.0 | ||
warmup_momentum: 0.5 | ||
warmup_bias_lr: 0.05 | ||
box: 0.0296 | ||
cls: 0.243 | ||
cls_pw: 0.631 | ||
obj: 0.301 | ||
obj_pw: 0.911 | ||
iou_t: 0.2 | ||
anchor_t: 2.91 | ||
# anchors: 3.63 | ||
fl_gamma: 0.0 | ||
hsv_h: 0.0138 | ||
hsv_s: 0.664 | ||
hsv_v: 0.464 | ||
degrees: 0.373 | ||
translate: 0.245 | ||
scale: 0.898 | ||
shear: 0.602 | ||
perspective: 0.0 | ||
flipud: 0.00856 | ||
fliplr: 0.5 | ||
mosaic: 1.0 | ||
mixup: 0.243 | ||
copy_paste: 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# YOLOv5 π by Ultralytics, GPL-3.0 license | ||
# Hyperparameters for COCO training from scratch | ||
# python train.py --batch 32 --cfg yolov5m6.yaml --weights '' --data coco.yaml --img 1280 --epochs 300 | ||
# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials | ||
|
||
lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) | ||
lrf: 0.2 # 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) | ||
fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) | ||
hsv_h: 0.015 # image HSV-Hue augmentation (fraction) | ||
hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) | ||
hsv_v: 0.4 # image HSV-Value augmentation (fraction) | ||
degrees: 0.0 # image rotation (+/- deg) | ||
translate: 0.1 # image translation (+/- fraction) | ||
scale: 0.9 # image scale (+/- gain) | ||
shear: 0.0 # image shear (+/- deg) | ||
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 | ||
flipud: 0.0 # image flip up-down (probability) | ||
fliplr: 0.5 # image flip left-right (probability) | ||
mosaic: 1.0 # image mosaic (probability) | ||
mixup: 0.0 # image mixup (probability) | ||
copy_paste: 0.0 # segment copy-paste (probability) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# YOLOv5 π by Ultralytics, GPL-3.0 license | ||
# Hyperparameters for COCO training from scratch | ||
# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 | ||
# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials | ||
|
||
lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) | ||
lrf: 0.2 # 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.5 # cls loss gain | ||
cls_pw: 1.0 # cls BCELoss positive_weight | ||
obj: 1.0 # 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) | ||
fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) | ||
hsv_h: 0.015 # image HSV-Hue augmentation (fraction) | ||
hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) | ||
hsv_v: 0.4 # image HSV-Value augmentation (fraction) | ||
degrees: 0.0 # image rotation (+/- deg) | ||
translate: 0.1 # image translation (+/- fraction) | ||
scale: 0.5 # image scale (+/- gain) | ||
shear: 0.0 # image shear (+/- deg) | ||
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 | ||
flipud: 0.0 # image flip up-down (probability) | ||
fliplr: 0.5 # image flip left-right (probability) | ||
mosaic: 1.0 # image mosaic (probability) | ||
mixup: 0.0 # image mixup (probability) | ||
copy_paste: 0.0 # segment copy-paste (probability) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
# YOLOv5 π by Ultralytics, GPL-3.0 license | ||
# Download latest models from https://github.com/ultralytics/yolov5/releases | ||
# Example usage: bash path/to/download_weights.sh | ||
# parent | ||
# βββ yolov5 | ||
# βββ yolov5s.pt β downloads here | ||
# βββ yolov5m.pt | ||
# βββ ... | ||
|
||
python - <<EOF | ||
from utils.downloads import attempt_download | ||
for x in ['s', 'm', 'l', 'x']: | ||
attempt_download(f'yolov5{x}.pt') | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
# YOLOv5 π by Ultralytics, GPL-3.0 license | ||
# Download COCO 2017 dataset http://cocodataset.org | ||
# Example usage: bash data/scripts/get_coco.sh | ||
# parent | ||
# βββ yolov5 | ||
# βββ datasets | ||
# βββ coco β downloads here | ||
|
||
# Download/unzip labels | ||
d='../datasets' # unzip directory | ||
url=https://github.com/ultralytics/yolov5/releases/download/v1.0/ | ||
f='coco2017labels.zip' # or 'coco2017labels-segments.zip', 68 MB | ||
echo 'Downloading' $url$f ' ...' | ||
curl -L $url$f -o $f && unzip -q $f -d $d && rm $f & | ||
|
||
# Download/unzip images | ||
d='../datasets/coco/images' # unzip directory | ||
url=http://images.cocodataset.org/zips/ | ||
f1='train2017.zip' # 19G, 118k images | ||
f2='val2017.zip' # 1G, 5k images | ||
f3='test2017.zip' # 7G, 41k images (optional) | ||
for f in $f1 $f2; do | ||
echo 'Downloading' $url$f '...' | ||
curl -L $url$f -o $f && unzip -q $f -d $d && rm $f & | ||
done | ||
wait # finish background tasks |
Empty file.
Oops, something went wrong.