├── .gitattributes ├── .gitignore ├── README-YOLOv5.md ├── README.md ├── __init__.py ├── data ├── Argoverse.yaml ├── GlobalWheat2020.yaml ├── Objects365.yaml ├── SKU-110K.yaml ├── VOC.yaml ├── VisDrone.yaml ├── coco.yaml ├── coco128.yaml ├── hyps │ ├── hyp.finetune.yaml │ ├── hyp.finetune_objects365.yaml │ ├── hyp.scratch-high.yaml │ ├── hyp.scratch-low.yaml │ └── hyp.scratch.yaml ├── images │ ├── bus.jpg │ └── zidane.jpg ├── scripts │ ├── download_weights.sh │ ├── get_coco.sh │ └── get_coco128.sh └── xView.yaml ├── datasets ├── Annotations │ ├── 000000.xml │ ├── 000001.xml │ ├── 000002.xml │ ├── 000003.xml │ ├── 000004.xml │ ├── 000005.xml │ ├── 000006.xml │ ├── 000007.xml │ ├── 000008.xml │ ├── 000009.xml │ ├── 000010.xml │ ├── 000011.xml │ ├── 000012.xml │ ├── 000013.xml │ ├── 000014.xml │ ├── 000015.xml │ ├── 000016.xml │ ├── 000017.xml │ ├── 000018.xml │ ├── 000019.xml │ ├── 000020.xml │ ├── 000021.xml │ ├── 000022.xml │ ├── 000023.xml │ ├── 000024.xml │ ├── 000025.xml │ ├── 000026.xml │ ├── 000027.xml │ ├── 000028.xml │ ├── 000029.xml │ └── 000030.xml ├── MergedLabels │ ├── Merged.yaml │ ├── images │ ├── labels │ │ ├── 000000.txt │ │ ├── 000001.txt │ │ ├── 000002.txt │ │ ├── 000003.txt │ │ ├── 000004.txt │ │ ├── 000005.txt │ │ ├── 000006.txt │ │ ├── 000007.txt │ │ ├── 000008.txt │ │ ├── 000009.txt │ │ ├── 000010.txt │ │ ├── 000011.txt │ │ ├── 000012.txt │ │ ├── 000013.txt │ │ ├── 000014.txt │ │ ├── 000015.txt │ │ ├── 000016.txt │ │ ├── 000017.txt │ │ ├── 000018.txt │ │ ├── 000019.txt │ │ ├── 000020.txt │ │ ├── 000021.txt │ │ ├── 000022.txt │ │ ├── 000023.txt │ │ ├── 000024.txt │ │ ├── 000025.txt │ │ ├── 000026.txt │ │ ├── 000027.txt │ │ ├── 000028.txt │ │ ├── 000029.txt │ │ └── 000030.txt │ ├── test.txt │ ├── train.txt │ └── trainval.txt ├── MultiLabels │ ├── Multiple.yaml │ ├── images │ ├── labels │ │ ├── 000000.txt │ │ ├── 000001.txt │ │ ├── 000002.txt │ │ ├── 000003.txt │ │ ├── 000004.txt │ │ ├── 000005.txt │ │ ├── 000006.txt │ │ ├── 000007.txt │ │ ├── 000008.txt │ │ ├── 000009.txt │ │ ├── 000010.txt │ │ ├── 000011.txt │ │ ├── 000012.txt │ │ ├── 000013.txt │ │ ├── 000014.txt │ │ ├── 000015.txt │ │ ├── 000016.txt │ │ ├── 000017.txt │ │ ├── 000018.txt │ │ ├── 000019.txt │ │ ├── 000020.txt │ │ ├── 000021.txt │ │ ├── 000022.txt │ │ ├── 000023.txt │ │ ├── 000024.txt │ │ ├── 000025.txt │ │ ├── 000026.txt │ │ ├── 000027.txt │ │ ├── 000028.txt │ │ ├── 000029.txt │ │ └── 000030.txt │ ├── test.txt │ ├── train.txt │ └── trainval.txt ├── images │ ├── 000000.jpeg │ ├── 000001.jpeg │ ├── 000002.jpeg │ ├── 000003.jpeg │ ├── 000004.jpeg │ ├── 000005.jpeg │ ├── 000006.jpeg │ ├── 000007.jpeg │ ├── 000008.jpeg │ ├── 000009.jpeg │ ├── 000010.jpeg │ ├── 000011.jpeg │ ├── 000012.jpeg │ ├── 000013.jpeg │ ├── 000014.jpeg │ ├── 000015.jpeg │ ├── 000016.jpeg │ ├── 000017.jpeg │ ├── 000018.jpeg │ ├── 000019.jpeg │ ├── 000020.jpeg │ ├── 000021.jpeg │ ├── 000022.jpeg │ ├── 000023.jpeg │ ├── 000024.jpeg │ ├── 000025.jpeg │ ├── 000026.jpeg │ ├── 000027.jpeg │ ├── 000028.jpeg │ ├── 000029.jpeg │ └── 000030.jpeg ├── split-datasets.py ├── voc2myYOLO.py └── voc2yolo.py ├── detect.py ├── export.py ├── models ├── __init__.py ├── common.py ├── experimental.py ├── hub │ ├── anchors.yaml │ ├── yolov3-spp.yaml │ ├── yolov3-tiny.yaml │ ├── yolov3.yaml │ ├── yolov5-bifpn.yaml │ ├── yolov5-fpn.yaml │ ├── yolov5-p2.yaml │ ├── yolov5-p6.yaml │ ├── yolov5-p7.yaml │ ├── yolov5-panet.yaml │ ├── yolov5l6.yaml │ ├── yolov5m6.yaml │ ├── yolov5n6.yaml │ ├── yolov5s-ghost.yaml │ ├── yolov5s-transformer.yaml │ ├── yolov5s6.yaml │ └── yolov5x6.yaml ├── tf.py ├── yolo.py ├── yolov5l.yaml ├── yolov5m.yaml ├── yolov5n.yaml ├── yolov5s.yaml └── yolov5x.yaml ├── outputs ├── run.sh ├── yolov5s.yaml └── yolov5s │ ├── Double_Head+FocalLoss │ ├── hyp.yaml │ ├── opt.yaml │ └── result.txt │ └── hyp.scratch.yaml ├── requirements.txt ├── train.py ├── utils ├── __init__.py ├── activations.py ├── augmentations.py ├── autoanchor.py ├── aws │ ├── __init__.py │ ├── mime.sh │ ├── resume.py │ └── userdata.sh ├── callbacks.py ├── datasetOrg.py ├── datasets.py ├── downloads.py ├── flask_rest_api │ ├── README.md │ ├── example_request.py │ └── restapi.py ├── general.py ├── google_app_engine │ ├── Dockerfile │ ├── additional_requirements.txt │ └── app.yaml ├── loggers │ ├── __init__.py │ └── wandb │ │ ├── README.md │ │ ├── __init__.py │ │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ └── wandb_utils.cpython-37.pyc │ │ ├── log_dataset.py │ │ ├── sweep.py │ │ ├── sweep.yaml │ │ └── wandb_utils.py ├── loss.py ├── metrics.py ├── plots.py └── torch_utils.py ├── val.py └── val_merged.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.DS_Store 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ##
YOLOv5-v6.0-RetinaNet-MultiLabel
3 | ##
Author:Code-keys
4 | 5 |
6 | Introduction 7 |

8 | This project : yolov5-6.0-RetinaNet-MultiLabel 🚀 is a project based on Ultralytics yolov5-v6.0 for detection-framework for multiLabel-detection:
9 | multiLabel-detection: a bbox contain two or more classes-Info ,such as contain a classname and a degree
10 |

11 |
12 | 13 | 14 |
15 | Write before 16 | 17 | Merge the Labels to one can also complete your task ( class of M ✖️ N ) 18 | 19 |
20 | 21 | 22 | ##
Quick Start Examples
23 | 24 |
25 | Install 26 | 27 | [**Python>=3.6.0**](https://www.python.org/) is required with all 28 | [requirements.txt](https://github.com/ultralytics/yolov5/blob/master/requirements.txt) installed including 29 | [**PyTorch>=1.7**](https://pytorch.org/get-started/locally/): 30 | 31 | 32 | ```bash 33 | $ git clone https://github.com/Code-keys/yolov5-6.0-RetinaNet-MultiClass 34 | $ cd yolov5-6.0-RetinaNet-MultiClass 35 | $ pip install -r requirements.txt 36 | ``` 37 | 38 |
39 | 40 |
41 | VOC datasets-prepare 42 | Put at the datasets folder{ images/ 、Annotations/ } 43 | 44 | The Annotations should be initialized as follows: 45 | 46 | 47 | WarShip 48 | 0 49 | 50 | 590 51 | 119 52 | 1896 53 | 1017 54 | 55 | 56 | 57 | 58 | ConmmonShip 59 | 7 60 | 61 | 590 62 | 119 63 | 1896 64 | 1017 65 | 66 | 67 | 68 | 69 | WarShip 70 | 4 71 | 72 | 590 73 | 119 74 | 1896 75 | 1017 76 | 77 | 78 | 79 | 80 | Then split the datasets: 81 | ``` bash 82 | cd datasets/ 83 | mkdir MergedLabels && ln -s images MergedLabels/images 84 | mkdir MultiLabels && ln -s images MultiLabels/images 85 | 86 | python ../split-datasets.py 87 | ``` 88 | 89 |
90 | datasets-convert-for-train 91 | 92 | \ \ \ \ \ \: 93 | 94 | The labels can be converted as follows ( append a tail behind the yolo-format-line ): 95 | 96 | ``` bash 97 | cd datasets/MergedLabels && mkdir labels 98 | vim ../voc2myYOLO.py ( Define something ) && python ../voc2myYOLO.py 99 | ``` 100 | MultiLabels/labels/000000.txt : 101 | ``` bash 102 | 0 0.255859375 0.6736111111111112 0.13046875 0.47500000000000003 0 103 | 1 0.361328125 0.6777777777777778 0.11484375000000001 0.430555555 3 104 | 1 0.361328125 0.6777777777777778 0.11484375000000001 0.430555555 2 105 | 0 0.432421875 0.6895833333333333 0.08203125 0.37083333333333335 5 106 | 1 0.6957031250000001 0.7152777777777778 0.12578125 0.35833333333333334 7 107 | ``` 108 |
109 | 110 |
111 | datasets-for-val&test 112 | 113 | // merged-class-id : tree children-node 114 | 115 | \ \ \ \ \ : 116 | 117 | The images && the datasets-split must be same to corresponding the train-datasets 118 | 119 | The Datasets-labels can be convert as following 120 | ``` bash 121 | cd datasets/MergedLabels && mkdir labels 122 | vim ../voc2YOLO.py ( Define something ) && python ../voc2YOLO.py 123 | ``` 124 | MergedLabels/labels/000000.txt : 125 | 126 | 0 0.255859375 0.6736111111111112 0.13046875 0.47500000000000003 127 | 4 0.361328125 0.6777777777777778 0.11484375000000001 0.4305555555555556 128 | 11 0.432421875 0.6895833333333333 0.08203125 0.37083333333333335 129 | 15 0.6957031250000001 0.7152777777777778 0.12578125 0.35833333333333334 130 | 6 0.6957031250000001 0.7152777777777778 0.12578125 0.35833333333333334 131 | 132 |
133 | 134 | 135 |
136 | train 137 | Train with ours YOLOv5 138 | 139 | ```python 140 | # datasets.yaml 141 | train: /home/xxx/xxx/dateset/train.txt # train-format : yolo-format append a other-id 142 | val: /home/xxx/xxx/dateset/eval.txt # val-format : new_cls_id 交叉组合结果 143 | test: /home/xxx/xxx/dateset/test.txt # val-format 144 | ``` 145 | train: 146 | ```sh 147 | xxx@xxx:~/xxx/yolov5-6.0$ export Use_Double_Head=1 148 | xxx@xxx:~/xxx/yolov5-6.0$ python train.py --cfg outputs/yolov5s.yaml --data datasets.yaml 149 | ``` 150 |
151 | 152 | 153 | 154 |
155 | val 156 | key codes modified as follows: 157 | 158 | out, train_out = model(img, augment=augment) # inference and training outputs 159 | 160 | # re-assign by class 161 | out_val = torch.cat( [ out[..., 0:5] ,out[..., 7:], out[..., 7:] ] , dim=-1 ) 162 | out_val[:, :, 5:13 ] *= (out[:, :, 5:6].repeat(1, 1, 8) ) 163 | out_val[:, :, 13: ] *= (out[:, :, 6:7].repeat(1, 1, 8) ) 164 | val: 165 | ```python 166 | xxx@xxx:~/xxx/yolov5-6.0$ export Use_Double_Head=1 167 | xxx@xxx:~/xxx/yolov5-6.0$ python val_merged.py --weights outputs/yolov5s/weights/best.pt --data your-datasets.yaml 168 | ``` 169 |
170 | 171 | 172 |
173 | FootStep of Project-Modify 174 | 175 | ### Abstract 176 | 177 | 1. 数据集 划分 split train.txt et al -> mergedLabel/images -> MultiLabels/images 178 | 2. 标签转换 MultiLabels 型(仅用于 train) + mergedLabel型 (仅用于 eval-test) 179 | 3. datasets.py: 180 | 181 | verify_image_label(args): -> assert ... 182 | 183 | class LoadImagesAndLabels -> __getitem__ ↓ 184 | 185 | torch.zeros((nl, 7)) # datasets:Label-format ( bs class x y w h other ) 186 | 187 | 5. yolo.py 188 | 189 | Detect : 双头:nc nc1 ;适配 190 | 191 | 6. val-merged.py 192 | 输出转换后 与 merged 类进行对比: 193 | 194 | # re-assign by class ( using multiply direct ) 195 | out_val = torch.cat( [ out[..., 0:5] ,out[..., 7:], out[..., 7:] ] , dim=-1 ) 196 | out_val[:, :, 5:13 ] *= (out[:, :, 5:6].repeat(1, 1, 8) ) 197 | out_val[:, :, 13: ] *= (out[:, :, 6:7].repeat(1, 1, 8) ) 198 | 199 | 7. Loss.py -> ComputeLoss 200 | 201 | \# added BCEcls 202 | \# Define criteria 203 | \# added a BCEWithLogitsLoss 204 | \# added a FocalLoss ( better ) Focal loss : FocalLoss(BCEdeg, g) 205 | 206 | \# \_\_call__ modify as the lcls 207 | Classification && other 同 208 | t = torch.full_like(ps[:, self.nc+5: ], self.cn, device=device) 209 | t[range(n), tdeg[i]] = self.cp 210 | ldeg += self.BCEdeg(ps[:, self.nc+5: ], t) # BCE 211 | 212 | 213 | \# Loss: build_targets 214 | 215 |
216 | 217 | 218 |
219 | Thanks 220 | 221 | @ yolov5 for base 222 | @ deast@hdu.edu.cn for the data&labels 223 | 224 |
225 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | from utils.autoanchor import kmean_anchors 2 | from utils.datasets import create_dataloader, LoadImagesAndLabels 3 | import tqdm 4 | 5 | 6 | # kmean_anchors(dataset='/home/gy/NSD/yolov5-6.0/Rship.yaml', n=9, img_size=640, thr=4.0, gen=6000, verbose=True ) 7 | 8 | dataset = LoadImagesAndLabels( "/home/gy/NSD/yolov5-6.0/datasets/images_train.txt" , 640, 8 ) 9 | 10 | for i, (imgs, targets, paths, _) in tqdm.tqdm(enumerate(dataset)): 11 | print(i, " ", targets.size() ) -------------------------------------------------------------------------------- /data/Argoverse.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # Argoverse-HD dataset (ring-front-center camera) http://www.cs.cmu.edu/~mengtial/proj/streaming/ 3 | # Example usage: python train.py --data Argoverse.yaml 4 | # parent 5 | # ├── yolov5 6 | # └── datasets 7 | # └── Argoverse ← downloads here 8 | 9 | 10 | # 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, ..] 11 | path: ../datasets/Argoverse # dataset root dir 12 | train: Argoverse-1.1/images/train/ # train images (relative to 'path') 39384 images 13 | val: Argoverse-1.1/images/val/ # val images (relative to 'path') 15062 images 14 | test: Argoverse-1.1/images/test/ # test images (optional) https://eval.ai/web/challenges/challenge-page/800/overview 15 | 16 | # Classes 17 | nc: 8 # number of classes 18 | names: ['person', 'bicycle', 'car', 'motorcycle', 'bus', 'truck', 'traffic_light', 'stop_sign'] # class names 19 | 20 | 21 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 22 | download: | 23 | import json 24 | 25 | from tqdm import tqdm 26 | from utils.general import download, Path 27 | 28 | 29 | def argoverse2yolo(set): 30 | labels = {} 31 | a = json.load(open(set, "rb")) 32 | for annot in tqdm(a['annotations'], desc=f"Converting {set} to YOLOv5 format..."): 33 | img_id = annot['image_id'] 34 | img_name = a['images'][img_id]['name'] 35 | img_label_name = img_name[:-3] + "txt" 36 | 37 | cls = annot['category_id'] # instance class id 38 | x_center, y_center, width, height = annot['bbox'] 39 | x_center = (x_center + width / 2) / 1920.0 # offset and scale 40 | y_center = (y_center + height / 2) / 1200.0 # offset and scale 41 | width /= 1920.0 # scale 42 | height /= 1200.0 # scale 43 | 44 | img_dir = set.parents[2] / 'Argoverse-1.1' / 'labels' / a['seq_dirs'][a['images'][annot['image_id']]['sid']] 45 | if not img_dir.exists(): 46 | img_dir.mkdir(parents=True, exist_ok=True) 47 | 48 | k = str(img_dir / img_label_name) 49 | if k not in labels: 50 | labels[k] = [] 51 | labels[k].append(f"{cls} {x_center} {y_center} {width} {height}\n") 52 | 53 | for k in labels: 54 | with open(k, "w") as f: 55 | f.writelines(labels[k]) 56 | 57 | 58 | # Download 59 | dir = Path('../datasets/Argoverse') # dataset root dir 60 | urls = ['https://argoverse-hd.s3.us-east-2.amazonaws.com/Argoverse-HD-Full.zip'] 61 | download(urls, dir=dir, delete=False) 62 | 63 | # Convert 64 | annotations_dir = 'Argoverse-HD/annotations/' 65 | (dir / 'Argoverse-1.1' / 'tracking').rename(dir / 'Argoverse-1.1' / 'images') # rename 'tracking' to 'images' 66 | for d in "train.json", "val.json": 67 | argoverse2yolo(dir / annotations_dir / d) # convert VisDrone annotations to YOLO labels 68 | -------------------------------------------------------------------------------- /data/GlobalWheat2020.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # Global Wheat 2020 dataset http://www.global-wheat.com/ 3 | # Example usage: python train.py --data GlobalWheat2020.yaml 4 | # parent 5 | # ├── yolov5 6 | # └── datasets 7 | # └── GlobalWheat2020 ← downloads here 8 | 9 | 10 | # 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, ..] 11 | path: ../datasets/GlobalWheat2020 # dataset root dir 12 | train: # train images (relative to 'path') 3422 images 13 | - images/arvalis_1 14 | - images/arvalis_2 15 | - images/arvalis_3 16 | - images/ethz_1 17 | - images/rres_1 18 | - images/inrae_1 19 | - images/usask_1 20 | val: # val images (relative to 'path') 748 images (WARNING: train set contains ethz_1) 21 | - images/ethz_1 22 | test: # test images (optional) 1276 images 23 | - images/utokyo_1 24 | - images/utokyo_2 25 | - images/nau_1 26 | - images/uq_1 27 | 28 | # Classes 29 | nc: 1 # number of classes 30 | names: ['wheat_head'] # class names 31 | 32 | 33 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 34 | download: | 35 | from utils.general import download, Path 36 | 37 | # Download 38 | dir = Path(yaml['path']) # dataset root dir 39 | urls = ['https://zenodo.org/record/4298502/files/global-wheat-codalab-official.zip', 40 | 'https://github.com/ultralytics/yolov5/releases/download/v1.0/GlobalWheat2020_labels.zip'] 41 | download(urls, dir=dir) 42 | 43 | # Make Directories 44 | for p in 'annotations', 'images', 'labels': 45 | (dir / p).mkdir(parents=True, exist_ok=True) 46 | 47 | # Move 48 | for p in 'arvalis_1', 'arvalis_2', 'arvalis_3', 'ethz_1', 'rres_1', 'inrae_1', 'usask_1', \ 49 | 'utokyo_1', 'utokyo_2', 'nau_1', 'uq_1': 50 | (dir / p).rename(dir / 'images' / p) # move to /images 51 | f = (dir / p).with_suffix('.json') # json file 52 | if f.exists(): 53 | f.rename((dir / 'annotations' / p).with_suffix('.json')) # move to /annotations 54 | -------------------------------------------------------------------------------- /data/Objects365.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # Objects365 dataset https://www.objects365.org/ 3 | # Example usage: python train.py --data Objects365.yaml 4 | # parent 5 | # ├── yolov5 6 | # └── datasets 7 | # └── Objects365 ← downloads here 8 | 9 | 10 | # 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, ..] 11 | path: ../datasets/Objects365 # dataset root dir 12 | train: images/train # train images (relative to 'path') 1742289 images 13 | val: images/val # val images (relative to 'path') 5570 images 14 | test: # test images (optional) 15 | 16 | # Classes 17 | nc: 365 # number of classes 18 | names: ['Person', 'Sneakers', 'Chair', 'Other Shoes', 'Hat', 'Car', 'Lamp', 'Glasses', 'Bottle', 'Desk', 'Cup', 19 | 'Street Lights', 'Cabinet/shelf', 'Handbag/Satchel', 'Bracelet', 'Plate', 'Picture/Frame', 'Helmet', 'Book', 20 | 'Gloves', 'Storage box', 'Boat', 'Leather Shoes', 'Flower', 'Bench', 'Potted Plant', 'Bowl/Basin', 'Flag', 21 | 'Pillow', 'Boots', 'Vase', 'Microphone', 'Necklace', 'Ring', 'SUV', 'Wine Glass', 'Belt', 'Monitor/TV', 22 | 'Backpack', 'Umbrella', 'Traffic Light', 'Speaker', 'Watch', 'Tie', 'Trash bin Can', 'Slippers', 'Bicycle', 23 | 'Stool', 'Barrel/bucket', 'Van', 'Couch', 'Sandals', 'Basket', 'Drum', 'Pen/Pencil', 'Bus', 'Wild Bird', 24 | 'High Heels', 'Motorcycle', 'Guitar', 'Carpet', 'Cell Phone', 'Bread', 'Camera', 'Canned', 'Truck', 25 | 'Traffic cone', 'Cymbal', 'Lifesaver', 'Towel', 'Stuffed Toy', 'Candle', 'Sailboat', 'Laptop', 'Awning', 26 | 'Bed', 'Faucet', 'Tent', 'Horse', 'Mirror', 'Power outlet', 'Sink', 'Apple', 'Air Conditioner', 'Knife', 27 | 'Hockey Stick', 'Paddle', 'Pickup Truck', 'Fork', 'Traffic Sign', 'Balloon', 'Tripod', 'Dog', 'Spoon', 'Clock', 28 | 'Pot', 'Cow', 'Cake', 'Dinning Table', 'Sheep', 'Hanger', 'Blackboard/Whiteboard', 'Napkin', 'Other Fish', 29 | 'Orange/Tangerine', 'Toiletry', 'Keyboard', 'Tomato', 'Lantern', 'Machinery Vehicle', 'Fan', 30 | 'Green Vegetables', 'Banana', 'Baseball Glove', 'Airplane', 'Mouse', 'Train', 'Pumpkin', 'Soccer', 'Skiboard', 31 | 'Luggage', 'Nightstand', 'Tea pot', 'Telephone', 'Trolley', 'Head Phone', 'Sports Car', 'Stop Sign', 32 | 'Dessert', 'Scooter', 'Stroller', 'Crane', 'Remote', 'Refrigerator', 'Oven', 'Lemon', 'Duck', 'Baseball Bat', 33 | 'Surveillance Camera', 'Cat', 'Jug', 'Broccoli', 'Piano', 'Pizza', 'Elephant', 'Skateboard', 'Surfboard', 34 | 'Gun', 'Skating and Skiing shoes', 'Gas stove', 'Donut', 'Bow Tie', 'Carrot', 'Toilet', 'Kite', 'Strawberry', 35 | 'Other Balls', 'Shovel', 'Pepper', 'Computer Box', 'Toilet Paper', 'Cleaning Products', 'Chopsticks', 36 | 'Microwave', 'Pigeon', 'Baseball', 'Cutting/chopping Board', 'Coffee Table', 'Side Table', 'Scissors', 37 | 'Marker', 'Pie', 'Ladder', 'Snowboard', 'Cookies', 'Radiator', 'Fire Hydrant', 'Basketball', 'Zebra', 'Grape', 38 | 'Giraffe', 'Potato', 'Sausage', 'Tricycle', 'Violin', 'Egg', 'Fire Extinguisher', 'Candy', 'Fire Truck', 39 | 'Billiards', 'Converter', 'Bathtub', 'Wheelchair', 'Golf Club', 'Briefcase', 'Cucumber', 'Cigar/Cigarette', 40 | 'Paint Brush', 'Pear', 'Heavy Truck', 'Hamburger', 'Extractor', 'Extension Cord', 'Tong', 'Tennis Racket', 41 | 'Folder', 'American Football', 'earphone', 'Mask', 'Kettle', 'Tennis', 'Ship', 'Swing', 'Coffee Machine', 42 | 'Slide', 'Carriage', 'Onion', 'Green beans', 'Projector', 'Frisbee', 'Washing Machine/Drying Machine', 43 | 'Chicken', 'Printer', 'Watermelon', 'Saxophone', 'Tissue', 'Toothbrush', 'Ice cream', 'Hot-air balloon', 44 | 'Cello', 'French Fries', 'Scale', 'Trophy', 'Cabbage', 'Hot dog', 'Blender', 'Peach', 'Rice', 'Wallet/Purse', 45 | 'Volleyball', 'Deer', 'Goose', 'Tape', 'Tablet', 'Cosmetics', 'Trumpet', 'Pineapple', 'Golf Ball', 46 | 'Ambulance', 'Parking meter', 'Mango', 'Key', 'Hurdle', 'Fishing Rod', 'Medal', 'Flute', 'Brush', 'Penguin', 47 | 'Megaphone', 'Corn', 'Lettuce', 'Garlic', 'Swan', 'Helicopter', 'Green Onion', 'Sandwich', 'Nuts', 48 | 'Speed Limit Sign', 'Induction Cooker', 'Broom', 'Trombone', 'Plum', 'Rickshaw', 'Goldfish', 'Kiwi fruit', 49 | 'Router/modem', 'Poker Card', 'Toaster', 'Shrimp', 'Sushi', 'Cheese', 'Notepaper', 'Cherry', 'Pliers', 'CD', 50 | 'Pasta', 'Hammer', 'Cue', 'Avocado', 'Hamimelon', 'Flask', 'Mushroom', 'Screwdriver', 'Soap', 'Recorder', 51 | 'Bear', 'Eggplant', 'Board Eraser', 'Coconut', 'Tape Measure/Ruler', 'Pig', 'Showerhead', 'Globe', 'Chips', 52 | 'Steak', 'Crosswalk Sign', 'Stapler', 'Camel', 'Formula 1', 'Pomegranate', 'Dishwasher', 'Crab', 53 | 'Hoverboard', 'Meat ball', 'Rice Cooker', 'Tuba', 'Calculator', 'Papaya', 'Antelope', 'Parrot', 'Seal', 54 | 'Butterfly', 'Dumbbell', 'Donkey', 'Lion', 'Urinal', 'Dolphin', 'Electric Drill', 'Hair Dryer', 'Egg tart', 55 | 'Jellyfish', 'Treadmill', 'Lighter', 'Grapefruit', 'Game board', 'Mop', 'Radish', 'Baozi', 'Target', 'French', 56 | 'Spring Rolls', 'Monkey', 'Rabbit', 'Pencil Case', 'Yak', 'Red Cabbage', 'Binoculars', 'Asparagus', 'Barbell', 57 | 'Scallop', 'Noddles', 'Comb', 'Dumpling', 'Oyster', 'Table Tennis paddle', 'Cosmetics Brush/Eyeliner Pencil', 58 | 'Chainsaw', 'Eraser', 'Lobster', 'Durian', 'Okra', 'Lipstick', 'Cosmetics Mirror', 'Curling', 'Table Tennis'] 59 | 60 | 61 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 62 | download: | 63 | from pycocotools.coco import COCO 64 | from tqdm import tqdm 65 | 66 | from utils.general import download, Path 67 | 68 | # Make Directories 69 | dir = Path(yaml['path']) # dataset root dir 70 | for p in 'images', 'labels': 71 | (dir / p).mkdir(parents=True, exist_ok=True) 72 | for q in 'train', 'val': 73 | (dir / p / q).mkdir(parents=True, exist_ok=True) 74 | 75 | # Download 76 | url = "https://dorc.ks3-cn-beijing.ksyun.com/data-set/2020Objects365%E6%95%B0%E6%8D%AE%E9%9B%86/train/" 77 | download([url + 'zhiyuan_objv2_train.tar.gz'], dir=dir, delete=False) # annotations json 78 | download([url + f for f in [f'patch{i}.tar.gz' for i in range(51)]], dir=dir / 'images' / 'train', 79 | curl=True, delete=False, threads=8) 80 | 81 | # Move 82 | train = dir / 'images' / 'train' 83 | for f in tqdm(train.rglob('*.jpg'), desc=f'Moving images'): 84 | f.rename(train / f.name) # move to /images/train 85 | 86 | # Labels 87 | coco = COCO(dir / 'zhiyuan_objv2_train.json') 88 | names = [x["name"] for x in coco.loadCats(coco.getCatIds())] 89 | for cid, cat in enumerate(names): 90 | catIds = coco.getCatIds(catNms=[cat]) 91 | imgIds = coco.getImgIds(catIds=catIds) 92 | for im in tqdm(coco.loadImgs(imgIds), desc=f'Class {cid + 1}/{len(names)} {cat}'): 93 | width, height = im["width"], im["height"] 94 | path = Path(im["file_name"]) # image filename 95 | try: 96 | with open(dir / 'labels' / 'train' / path.with_suffix('.txt').name, 'a') as file: 97 | annIds = coco.getAnnIds(imgIds=im["id"], catIds=catIds, iscrowd=None) 98 | for a in coco.loadAnns(annIds): 99 | x, y, w, h = a['bbox'] # bounding box in xywh (xy top-left corner) 100 | x, y = x + w / 2, y + h / 2 # xy to center 101 | file.write(f"{cid} {x / width:.5f} {y / height:.5f} {w / width:.5f} {h / height:.5f}\n") 102 | 103 | except Exception as e: 104 | print(e) 105 | -------------------------------------------------------------------------------- /data/SKU-110K.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # SKU-110K retail items dataset https://github.com/eg4000/SKU110K_CVPR19 3 | # Example usage: python train.py --data SKU-110K.yaml 4 | # parent 5 | # ├── yolov5 6 | # └── datasets 7 | # └── SKU-110K ← downloads here 8 | 9 | 10 | # 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, ..] 11 | path: ../datasets/SKU-110K # dataset root dir 12 | train: train.txt # train images (relative to 'path') 8219 images 13 | val: val.txt # val images (relative to 'path') 588 images 14 | test: test.txt # test images (optional) 2936 images 15 | 16 | # Classes 17 | nc: 1 # number of classes 18 | names: ['object'] # class names 19 | 20 | 21 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 22 | download: | 23 | import shutil 24 | from tqdm import tqdm 25 | from utils.general import np, pd, Path, download, xyxy2xywh 26 | 27 | # Download 28 | dir = Path(yaml['path']) # dataset root dir 29 | parent = Path(dir.parent) # download dir 30 | urls = ['http://trax-geometry.s3.amazonaws.com/cvpr_challenge/SKU110K_fixed.tar.gz'] 31 | download(urls, dir=parent, delete=False) 32 | 33 | # Rename directories 34 | if dir.exists(): 35 | shutil.rmtree(dir) 36 | (parent / 'SKU110K_fixed').rename(dir) # rename dir 37 | (dir / 'labels').mkdir(parents=True, exist_ok=True) # create labels dir 38 | 39 | # Convert labels 40 | names = 'image', 'x1', 'y1', 'x2', 'y2', 'class', 'image_width', 'image_height' # column names 41 | for d in 'annotations_train.csv', 'annotations_val.csv', 'annotations_test.csv': 42 | x = pd.read_csv(dir / 'annotations' / d, names=names).values # annotations 43 | images, unique_images = x[:, 0], np.unique(x[:, 0]) 44 | with open((dir / d).with_suffix('.txt').__str__().replace('annotations_', ''), 'w') as f: 45 | f.writelines(f'./images/{s}\n' for s in unique_images) 46 | for im in tqdm(unique_images, desc=f'Converting {dir / d}'): 47 | cls = 0 # single-class dataset 48 | with open((dir / 'labels' / im).with_suffix('.txt'), 'a') as f: 49 | for r in x[images == im]: 50 | w, h = r[6], r[7] # image width, height 51 | xywh = xyxy2xywh(np.array([[r[1] / w, r[2] / h, r[3] / w, r[4] / h]]))[0] # instance 52 | f.write(f"{cls} {xywh[0]:.5f} {xywh[1]:.5f} {xywh[2]:.5f} {xywh[3]:.5f}\n") # write label 53 | -------------------------------------------------------------------------------- /data/VOC.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC 3 | # Example usage: python train.py --data VOC.yaml 4 | # parent 5 | # ├── yolov5 6 | # └── datasets 7 | # └── VOC ← downloads here 8 | 9 | 10 | # 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, ..] 11 | path: ../datasets/VOC 12 | train: # train images (relative to 'path') 16551 images 13 | - images/train2012 14 | - images/train2007 15 | - images/val2012 16 | - images/val2007 17 | val: # val images (relative to 'path') 4952 images 18 | - images/test2007 19 | test: # test images (optional) 20 | - images/test2007 21 | 22 | # Classes 23 | nc: 20 # number of classes 24 | names: ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 25 | 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'] # class names 26 | 27 | 28 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 29 | download: | 30 | import xml.etree.ElementTree as ET 31 | 32 | from tqdm import tqdm 33 | from utils.general import download, Path 34 | 35 | 36 | def convert_label(path, lb_path, year, image_id): 37 | def convert_box(size, box): 38 | dw, dh = 1. / size[0], 1. / size[1] 39 | 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] 40 | return x * dw, y * dh, w * dw, h * dh 41 | 42 | in_file = open(path / f'VOC{year}/Annotations/{image_id}.xml') 43 | out_file = open(lb_path, 'w') 44 | tree = ET.parse(in_file) 45 | root = tree.getroot() 46 | size = root.find('size') 47 | w = int(size.find('width').text) 48 | h = int(size.find('height').text) 49 | 50 | for obj in root.iter('object'): 51 | cls = obj.find('name').text 52 | if cls in yaml['names'] and not int(obj.find('difficult').text) == 1: 53 | xmlbox = obj.find('bndbox') 54 | bb = convert_box((w, h), [float(xmlbox.find(x).text) for x in ('xmin', 'xmax', 'ymin', 'ymax')]) 55 | cls_id = yaml['names'].index(cls) # class id 56 | out_file.write(" ".join([str(a) for a in (cls_id, *bb)]) + '\n') 57 | 58 | 59 | # Download 60 | dir = Path(yaml['path']) # dataset root dir 61 | url = 'https://github.com/ultralytics/yolov5/releases/download/v1.0/' 62 | urls = [url + 'VOCtrainval_06-Nov-2007.zip', # 446MB, 5012 images 63 | url + 'VOCtest_06-Nov-2007.zip', # 438MB, 4953 images 64 | url + 'VOCtrainval_11-May-2012.zip'] # 1.95GB, 17126 images 65 | download(urls, dir=dir / 'images', delete=False) 66 | 67 | # Convert 68 | path = dir / f'images/VOCdevkit' 69 | for year, image_set in ('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test'): 70 | imgs_path = dir / 'images' / f'{image_set}{year}' 71 | lbs_path = dir / 'labels' / f'{image_set}{year}' 72 | imgs_path.mkdir(exist_ok=True, parents=True) 73 | lbs_path.mkdir(exist_ok=True, parents=True) 74 | 75 | image_ids = open(path / f'VOC{year}/ImageSets/Main/{image_set}.txt').read().strip().split() 76 | for id in tqdm(image_ids, desc=f'{image_set}{year}'): 77 | f = path / f'VOC{year}/JPEGImages/{id}.jpg' # old img path 78 | lb_path = (lbs_path / f.name).with_suffix('.txt') # new label path 79 | f.rename(imgs_path / f.name) # move image 80 | convert_label(path, lb_path, year, id) # convert labels to YOLO format 81 | -------------------------------------------------------------------------------- /data/VisDrone.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # VisDrone2019-DET dataset https://github.com/VisDrone/VisDrone-Dataset 3 | # Example usage: python train.py --data VisDrone.yaml 4 | # parent 5 | # ├── yolov5 6 | # └── datasets 7 | # └── VisDrone ← downloads here 8 | 9 | 10 | # 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, ..] 11 | path: ../datasets/VisDrone # dataset root dir 12 | train: VisDrone2019-DET-train/images # train images (relative to 'path') 6471 images 13 | val: VisDrone2019-DET-val/images # val images (relative to 'path') 548 images 14 | test: VisDrone2019-DET-test-dev/images # test images (optional) 1610 images 15 | 16 | # Classes 17 | nc: 10 # number of classes 18 | names: ['pedestrian', 'people', 'bicycle', 'car', 'van', 'truck', 'tricycle', 'awning-tricycle', 'bus', 'motor'] 19 | 20 | 21 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 22 | download: | 23 | from utils.general import download, os, Path 24 | 25 | def visdrone2yolo(dir): 26 | from PIL import Image 27 | from tqdm import tqdm 28 | 29 | def convert_box(size, box): 30 | # Convert VisDrone box to YOLO xywh box 31 | dw = 1. / size[0] 32 | dh = 1. / size[1] 33 | return (box[0] + box[2] / 2) * dw, (box[1] + box[3] / 2) * dh, box[2] * dw, box[3] * dh 34 | 35 | (dir / 'labels').mkdir(parents=True, exist_ok=True) # make labels directory 36 | pbar = tqdm((dir / 'annotations').glob('*.txt'), desc=f'Converting {dir}') 37 | for f in pbar: 38 | img_size = Image.open((dir / 'images' / f.name).with_suffix('.jpg')).size 39 | lines = [] 40 | with open(f, 'r') as file: # read annotation.txt 41 | for row in [x.split(',') for x in file.read().strip().splitlines()]: 42 | if row[4] == '0': # VisDrone 'ignored regions' class 0 43 | continue 44 | cls = int(row[5]) - 1 45 | box = convert_box(img_size, tuple(map(int, row[:4]))) 46 | lines.append(f"{cls} {' '.join(f'{x:.6f}' for x in box)}\n") 47 | with open(str(f).replace(os.sep + 'annotations' + os.sep, os.sep + 'labels' + os.sep), 'w') as fl: 48 | fl.writelines(lines) # write label.txt 49 | 50 | 51 | # Download 52 | dir = Path(yaml['path']) # dataset root dir 53 | urls = ['https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-train.zip', 54 | 'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-val.zip', 55 | 'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-test-dev.zip', 56 | 'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-test-challenge.zip'] 57 | download(urls, dir=dir) 58 | 59 | # Convert 60 | for d in 'VisDrone2019-DET-train', 'VisDrone2019-DET-val', 'VisDrone2019-DET-test-dev': 61 | visdrone2yolo(dir / d) # convert VisDrone annotations to YOLO labels 62 | -------------------------------------------------------------------------------- /data/coco.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # COCO 2017 dataset http://cocodataset.org 3 | # Example usage: python train.py --data coco.yaml 4 | # parent 5 | # ├── yolov5 6 | # └── datasets 7 | # └── coco ← downloads here 8 | 9 | 10 | # 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, ..] 11 | path: ../datasets/coco # dataset root dir 12 | train: train2017.txt # train images (relative to 'path') 118287 images 13 | val: val2017.txt # train images (relative to 'path') 5000 images 14 | test: test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794 15 | 16 | # Classes 17 | nc: 80 # number of classes 18 | names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 19 | 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 20 | 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 21 | 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 22 | 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 23 | 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 24 | 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 25 | 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 26 | 'hair drier', 'toothbrush'] # class names 27 | 28 | 29 | # Download script/URL (optional) 30 | download: | 31 | from utils.general import download, Path 32 | 33 | # Download labels 34 | segments = False # segment or box labels 35 | dir = Path(yaml['path']) # dataset root dir 36 | url = 'https://github.com/ultralytics/yolov5/releases/download/v1.0/' 37 | urls = [url + ('coco2017labels-segments.zip' if segments else 'coco2017labels.zip')] # labels 38 | download(urls, dir=dir.parent) 39 | 40 | # Download data 41 | urls = ['http://images.cocodataset.org/zips/train2017.zip', # 19G, 118k images 42 | 'http://images.cocodataset.org/zips/val2017.zip', # 1G, 5k images 43 | 'http://images.cocodataset.org/zips/test2017.zip'] # 7G, 41k images (optional) 44 | download(urls, dir=dir / 'images', threads=3) 45 | -------------------------------------------------------------------------------- /data/coco128.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) 3 | # Example usage: python train.py --data coco128.yaml 4 | # parent 5 | # ├── yolov5 6 | # └── datasets 7 | # └── coco128 ← downloads here 8 | 9 | 10 | # 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, ..] 11 | path: ../datasets/coco128 # dataset root dir 12 | train: images/train2017 # train images (relative to 'path') 128 images 13 | val: images/train2017 # val images (relative to 'path') 128 images 14 | test: # test images (optional) 15 | 16 | # Classes 17 | nc: 80 # number of classes 18 | names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 19 | 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 20 | 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 21 | 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 22 | 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 23 | 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 24 | 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 25 | 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 26 | 'hair drier', 'toothbrush'] # class names 27 | 28 | 29 | # Download script/URL (optional) 30 | download: https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip -------------------------------------------------------------------------------- /data/hyps/hyp.finetune.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # Hyperparameters for VOC finetuning 3 | # python train.py --batch 64 --weights yolov5m.pt --data VOC.yaml --img 512 --epochs 50 4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 5 | 6 | # Hyperparameter Evolution Results 7 | # Generations: 306 8 | # P R mAP.5 mAP.5:.95 box obj cls 9 | # Metrics: 0.6 0.936 0.896 0.684 0.0115 0.00805 0.00146 10 | 11 | lr0: 0.0032 12 | lrf: 0.12 13 | momentum: 0.843 14 | weight_decay: 0.00036 15 | warmup_epochs: 2.0 16 | warmup_momentum: 0.5 17 | warmup_bias_lr: 0.05 18 | box: 0.0296 19 | cls: 0.243 20 | cls_pw: 0.631 21 | obj: 0.301 22 | obj_pw: 0.911 23 | iou_t: 0.2 24 | anchor_t: 2.91 25 | # anchors: 3.63 26 | fl_gamma: 0.0 27 | hsv_h: 0.0138 28 | hsv_s: 0.664 29 | hsv_v: 0.464 30 | degrees: 0.373 31 | translate: 0.245 32 | scale: 0.898 33 | shear: 0.602 34 | perspective: 0.0 35 | flipud: 0.00856 36 | fliplr: 0.5 37 | mosaic: 1.0 38 | mixup: 0.243 39 | copy_paste: 0.0 40 | -------------------------------------------------------------------------------- /data/hyps/hyp.finetune_objects365.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | lr0: 0.00258 4 | lrf: 0.17 5 | momentum: 0.779 6 | weight_decay: 0.00058 7 | warmup_epochs: 1.33 8 | warmup_momentum: 0.86 9 | warmup_bias_lr: 0.0711 10 | box: 0.0539 11 | cls: 0.299 12 | cls_pw: 0.825 13 | obj: 0.632 14 | obj_pw: 1.0 15 | iou_t: 0.2 16 | anchor_t: 3.44 17 | anchors: 3.2 18 | fl_gamma: 0.0 19 | hsv_h: 0.0188 20 | hsv_s: 0.704 21 | hsv_v: 0.36 22 | degrees: 0.0 23 | translate: 0.0902 24 | scale: 0.491 25 | shear: 0.0 26 | perspective: 0.0 27 | flipud: 0.0 28 | fliplr: 0.5 29 | mosaic: 1.0 30 | mixup: 0.0 31 | copy_paste: 0.0 32 | -------------------------------------------------------------------------------- /data/hyps/hyp.scratch-high.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # Hyperparameters for high-augmentation COCO training from scratch 3 | # python train.py --batch 32 --cfg yolov5m6.yaml --weights '' --data coco.yaml --img 1280 --epochs 300 4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 5 | 6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 7 | lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) 8 | momentum: 0.937 # SGD momentum/Adam beta1 9 | weight_decay: 0.0005 # optimizer weight decay 5e-4 10 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 11 | warmup_momentum: 0.8 # warmup initial momentum 12 | warmup_bias_lr: 0.1 # warmup initial bias lr 13 | box: 0.05 # box loss gain 14 | cls: 0.3 # cls loss gain 15 | cls_pw: 1.0 # cls BCELoss positive_weight 16 | obj: 0.7 # obj loss gain (scale with pixels) 17 | obj_pw: 1.0 # obj BCELoss positive_weight 18 | iou_t: 0.20 # IoU training threshold 19 | anchor_t: 4.0 # anchor-multiple threshold 20 | # anchors: 3 # anchors per output layer (0 to ignore) 21 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 22 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 23 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 24 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 25 | degrees: 0.0 # image rotation (+/- deg) 26 | translate: 0.1 # image translation (+/- fraction) 27 | scale: 0.9 # image scale (+/- gain) 28 | shear: 0.0 # image shear (+/- deg) 29 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 30 | flipud: 0.0 # image flip up-down (probability) 31 | fliplr: 0.5 # image flip left-right (probability) 32 | mosaic: 1.0 # image mosaic (probability) 33 | mixup: 0.1 # image mixup (probability) 34 | copy_paste: 0.1 # segment copy-paste (probability) -------------------------------------------------------------------------------- /data/hyps/hyp.scratch-low.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # Hyperparameters for low-augmentation COCO training from scratch 3 | # python train.py --batch 64 --cfg yolov5n6.yaml --weights '' --data coco.yaml --img 640 --epochs 300 --linear 4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 5 | 6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 7 | lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf) 8 | momentum: 0.937 # SGD momentum/Adam beta1 9 | weight_decay: 0.0005 # optimizer weight decay 5e-4 10 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 11 | warmup_momentum: 0.8 # warmup initial momentum 12 | warmup_bias_lr: 0.1 # warmup initial bias lr 13 | box: 0.05 # box loss gain 14 | cls: 0.5 # cls loss gain 15 | cls_pw: 1.0 # cls BCELoss positive_weight 16 | obj: 1.0 # obj loss gain (scale with pixels) 17 | obj_pw: 1.0 # obj BCELoss positive_weight 18 | iou_t: 0.20 # IoU training threshold 19 | anchor_t: 4.0 # anchor-multiple threshold 20 | # anchors: 3 # anchors per output layer (0 to ignore) 21 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 22 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 23 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 24 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 25 | degrees: 0.0 # image rotation (+/- deg) 26 | translate: 0.1 # image translation (+/- fraction) 27 | scale: 0.5 # image scale (+/- gain) 28 | shear: 0.0 # image shear (+/- deg) 29 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 30 | flipud: 0.0 # image flip up-down (probability) 31 | fliplr: 0.5 # image flip left-right (probability) 32 | mosaic: 1.0 # image mosaic (probability) 33 | mixup: 0.0 # image mixup (probability) 34 | copy_paste: 0.0 # segment copy-paste (probability) -------------------------------------------------------------------------------- /data/hyps/hyp.scratch.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # Hyperparameters for COCO training from scratch 3 | # python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 5 | 6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 7 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) 8 | momentum: 0.937 # SGD momentum/Adam beta1 9 | weight_decay: 0.0005 # optimizer weight decay 5e-4 10 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 11 | warmup_momentum: 0.8 # warmup initial momentum 12 | warmup_bias_lr: 0.1 # warmup initial bias lr 13 | 14 | box: 0.05 # box loss gain 15 | obj: 1.0 # obj loss gain (scale with pixels) 16 | obj_pw: 1.0 # obj BCELoss positive_weight 17 | cls: 0.5 # cls loss gain 18 | cls_pw: 1.0 # cls BCELoss positive_weight 19 | 20 | degree: 0.9 # cls loss gain 21 | degree_pw: 1.0 # degree BCELoss positive_weight 22 | 23 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 24 | 25 | iou_t: 0.20 # IoU training threshold 26 | anchor_t: 4.0 # anchor-multiple threshold 27 | # anchors: 3 # anchors per output layer (0 to ignore) 28 | 29 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 30 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 31 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 32 | degrees: 0.0 # image rotation (+/- deg) 33 | translate: 0.1 # image translation (+/- fraction) 34 | scale: 0.5 # image scale (+/- gain) 35 | shear: 0.0 # image shear (+/- deg) 36 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 37 | flipud: 0.0 # image flip up-down (probability) 38 | fliplr: 0.5 # image flip left-right (probability) 39 | mosaic: 1.0 # image mosaic (probability) 40 | mixup: 0.0 # image mixup (probability) 41 | copy_paste: 0.0 # segment copy-paste (probability) 42 | -------------------------------------------------------------------------------- /data/images/bus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/data/images/bus.jpg -------------------------------------------------------------------------------- /data/images/zidane.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/data/images/zidane.jpg -------------------------------------------------------------------------------- /data/scripts/download_weights.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 3 | # Download latest models from https://github.com/ultralytics/yolov5/releases 4 | # Example usage: bash path/to/download_weights.sh 5 | # parent 6 | # └── yolov5 7 | # ├── yolov5s.pt ← downloads here 8 | # ├── yolov5m.pt 9 | # └── ... 10 | 11 | python - <= cls >= 0, f'incorrect class index {cls}' 74 | 75 | # Write YOLO label 76 | if id not in shapes: 77 | shapes[id] = Image.open(file).size 78 | box = xyxy2xywhn(box[None].astype(np.float), w=shapes[id][0], h=shapes[id][1], clip=True) 79 | with open((labels / id).with_suffix('.txt'), 'a') as f: 80 | f.write(f"{cls} {' '.join(f'{x:.6f}' for x in box[0])}\n") # write label.txt 81 | except Exception as e: 82 | print(f'WARNING: skipping one label for {file}: {e}') 83 | 84 | 85 | # Download manually from https://challenge.xviewdataset.org 86 | dir = Path(yaml['path']) # dataset root dir 87 | # urls = ['https://d307kc0mrhucc3.cloudfront.net/train_labels.zip', # train labels 88 | # 'https://d307kc0mrhucc3.cloudfront.net/train_images.zip', # 15G, 847 train images 89 | # 'https://d307kc0mrhucc3.cloudfront.net/val_images.zip'] # 5G, 282 val images (no labels) 90 | # download(urls, dir=dir, delete=False) 91 | 92 | # Convert labels 93 | convert_labels(dir / 'xView_train.geojson') 94 | 95 | # Move images 96 | images = Path(dir / 'images') 97 | images.mkdir(parents=True, exist_ok=True) 98 | Path(dir / 'train_images').rename(dir / 'images' / 'train') 99 | Path(dir / 'val_images').rename(dir / 'images' / 'val') 100 | 101 | # Split 102 | autosplit(dir / 'images' / 'train') 103 | -------------------------------------------------------------------------------- /datasets/Annotations/000000.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000000.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000000.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 1 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 319 21 | 77 22 | 1308 23 | 936 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000001.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000001.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000001.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 4 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 654 21 | 314 22 | 740 23 | 359 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000002.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000002.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000002.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 1 15 | WarShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 590 21 | 119 22 | 1896 23 | 1017 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000003.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000003.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000003.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 6 15 | WarShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 245 21 | 315 22 | 412 23 | 657 24 | 25 | 26 | 27 | 6 28 | WarShip 29 | Unspecified 30 | 0 31 | 0 32 | 33 | 390 34 | 334 35 | 537 36 | 644 37 | 38 | 39 | 40 | 6 41 | WarShip 42 | Unspecified 43 | 0 44 | 0 45 | 46 | 502 47 | 364 48 | 607 49 | 631 50 | 51 | 52 | 53 | 7 54 | WarShip 55 | Unspecified 56 | 0 57 | 0 58 | 59 | 811 60 | 387 61 | 972 62 | 645 63 | 64 | 65 | 66 | 5 67 | WarShip 68 | Unspecified 69 | 0 70 | 0 71 | 72 | 1088 73 | 369 74 | 1235 75 | 646 76 | 77 | 78 | -------------------------------------------------------------------------------- /datasets/Annotations/000004.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000004.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000004.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 0 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 446 21 | 156 22 | 780 23 | 476 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000005.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000005.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000005.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 3 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 802 21 | 425 22 | 1140 23 | 596 24 | 25 | 26 | 27 | 4 28 | CommonShip 29 | Unspecified 30 | 0 31 | 0 32 | 33 | 109 34 | 410 35 | 399 36 | 561 37 | 38 | 39 | 40 | 7 41 | CommonShip 42 | Unspecified 43 | 0 44 | 0 45 | 46 | 934 47 | 311 48 | 1000 49 | 373 50 | 51 | 52 | 53 | 6 54 | CommonShip 55 | Unspecified 56 | 0 57 | 0 58 | 59 | 837 60 | 332 61 | 871 62 | 359 63 | 64 | 65 | -------------------------------------------------------------------------------- /datasets/Annotations/000006.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000006.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000006.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 5 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 818 21 | 407 22 | 1169 23 | 1047 24 | 25 | 26 | 27 | 5 28 | CommonShip 29 | Unspecified 30 | 0 31 | 0 32 | 33 | 1187 34 | 312 35 | 1268 36 | 410 37 | 38 | 39 | -------------------------------------------------------------------------------- /datasets/Annotations/000007.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000007.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000007.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 1 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 782 21 | 79 22 | 1407 23 | 536 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000008.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000008.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000008.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 0 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 496 21 | 458 22 | 1518 23 | 722 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000009.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000009.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000009.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 5 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 18 21 | 184 22 | 887 23 | 659 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000010.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000010.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000010.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 0 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 172 21 | 329 22 | 1245 23 | 650 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000011.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000011.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000011.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 4 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 337 21 | 332 22 | 795 23 | 527 24 | 25 | 26 | 27 | 0 28 | CommonShip 29 | Unspecified 30 | 0 31 | 0 32 | 33 | 600 34 | 519 35 | 915 36 | 649 37 | 38 | 39 | -------------------------------------------------------------------------------- /datasets/Annotations/000012.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000012.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000012.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 4 15 | WarShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 144 21 | 92 22 | 1276 23 | 624 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000013.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000013.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000013.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 7 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 111 21 | 177 22 | 928 23 | 591 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000014.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000014.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000014.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 6 15 | WarShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 171 21 | 251 22 | 355 23 | 559 24 | 25 | 26 | 27 | 6 28 | WarShip 29 | Unspecified 30 | 0 31 | 0 32 | 33 | 296 34 | 246 35 | 400 36 | 545 37 | 38 | 39 | 40 | 6 41 | WarShip 42 | Unspecified 43 | 0 44 | 0 45 | 46 | 721 47 | 220 48 | 908 49 | 585 50 | 51 | 52 | 53 | 7 54 | WarShip 55 | Unspecified 56 | 0 57 | 0 58 | 59 | 871 60 | 186 61 | 1063 62 | 597 63 | 64 | 65 | 66 | 5 67 | WarShip 68 | Unspecified 69 | 0 70 | 0 71 | 72 | 1070 73 | 250 74 | 1200 75 | 574 76 | 77 | 78 | -------------------------------------------------------------------------------- /datasets/Annotations/000015.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000015.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000015.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 5 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 483 21 | 157 22 | 1159 23 | 511 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000016.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000016.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000016.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 7 15 | WarShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 922 21 | 175 22 | 1481 23 | 859 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000017.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000017.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000017.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 0 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 256 21 | 320 22 | 1582 23 | 907 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000018.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000018.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000018.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 0 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 194 21 | 373 22 | 1515 23 | 945 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000019.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000019.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000019.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 0 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 80 21 | 307 22 | 1261 23 | 611 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000020.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000020.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000020.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 4 15 | WarShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 26 21 | 1 22 | 1279 23 | 559 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000021.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000021.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000021.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 1 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 518 21 | 343 22 | 1171 23 | 1005 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000022.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000022.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000022.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 4 15 | WarShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 769 21 | 509 22 | 1358 23 | 745 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000023.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000023.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000023.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 0 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 335 21 | 298 22 | 1724 23 | 766 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000024.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000024.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000024.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 0 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 362 21 | 147 22 | 1858 23 | 798 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000025.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000025.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000025.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 3 15 | WarShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 673 21 | 231 22 | 757 23 | 306 24 | 25 | 26 | 27 | 3 28 | WarShip 29 | Unspecified 30 | 0 31 | 0 32 | 33 | 1100 34 | 309 35 | 1202 36 | 389 37 | 38 | 39 | 40 | 3 41 | WarShip 42 | Unspecified 43 | 0 44 | 0 45 | 46 | 767 47 | 325 48 | 828 49 | 415 50 | 51 | 52 | 53 | 1 54 | WarShip 55 | Unspecified 56 | 0 57 | 0 58 | 59 | 353 60 | 345 61 | 420 62 | 431 63 | 64 | 65 | 66 | 1 67 | WarShip 68 | Unspecified 69 | 0 70 | 0 71 | 72 | 446 73 | 259 74 | 482 75 | 304 76 | 77 | 78 | 79 | 3 80 | WarShip 81 | Unspecified 82 | 0 83 | 0 84 | 85 | 907 86 | 235 87 | 945 88 | 280 89 | 90 | 91 | -------------------------------------------------------------------------------- /datasets/Annotations/000026.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000026.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000026.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 5 15 | WarShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 182 21 | 190 22 | 1255 23 | 571 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000027.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000027.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000027.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 4 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 418 21 | 615 22 | 1686 23 | 964 24 | 25 | 26 | 27 | 4 28 | CommonShip 29 | Unspecified 30 | 0 31 | 0 32 | 33 | 467 34 | 429 35 | 1662 36 | 812 37 | 38 | 39 | 40 | 1 41 | CommonShip 42 | Unspecified 43 | 0 44 | 0 45 | 46 | 107 47 | 147 48 | 665 49 | 396 50 | 51 | 52 | -------------------------------------------------------------------------------- /datasets/Annotations/000028.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000028.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000028.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 0 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 435 21 | 362 22 | 1456 23 | 939 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000029.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000029.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000029.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1920 9 | 1080 10 | 3 11 | 12 | 0 13 | 14 | 4 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 824 21 | 324 22 | 1871 23 | 956 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/Annotations/000030.xml: -------------------------------------------------------------------------------- 1 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007 2 | 000030.jpeg 3 | G:/Work/multi-objective/shipdataset/VOC2007_ship/VOC2007/JPEGImages/000030.jpeg 4 | 5 | Unknown 6 | 7 | 8 | 1280 9 | 720 10 | 3 11 | 12 | 0 13 | 14 | 5 15 | CommonShip 16 | Unspecified 17 | 0 18 | 0 19 | 20 | 181 21 | 71 22 | 1226 23 | 563 24 | 25 | 26 | -------------------------------------------------------------------------------- /datasets/MergedLabels/Merged.yaml: -------------------------------------------------------------------------------- 1 | 2 | # train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/] 3 | train: dateset/MergedLabels/train.txt # images 4 | val: dateset/MergedLabels/trainval.txt # images 5 | test: dateset/MergedLabels/test.txt # images 6 | 7 | 8 | # number of classes 9 | nc: 16 10 | 11 | # class names 12 | names: ["WarShip_135", "WarShip_90", "WarShip-45", "WarShip_00", "WarShip_45", "WarShip_90", "WarShip_135", "WarShip_180", 13 | "CommonShip_135", "CommonShip_90" , "CommonShip_45", "CommonShip_00" , "CommonShip_45", "CommonShip_90" , "CommonShip_135", "CommonShip_180" ] -------------------------------------------------------------------------------- /datasets/MergedLabels/images: -------------------------------------------------------------------------------- 1 | ../images -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000000.txt: -------------------------------------------------------------------------------- 1 | 9 0.4231770833333333 0.46805555555555556 0.5151041666666667 0.7953703703703704 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000001.txt: -------------------------------------------------------------------------------- 1 | 12 0.5437500000000001 0.46597222222222223 0.0671875 0.0625 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000002.txt: -------------------------------------------------------------------------------- 1 | 1 0.646875 0.525 0.6802083333333333 0.8314814814814815 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000003.txt: -------------------------------------------------------------------------------- 1 | 6 0.255859375 0.6736111111111112 0.13046875 0.47500000000000003 2 | 6 0.361328125 0.6777777777777778 0.11484375000000001 0.4305555555555556 3 | 6 0.432421875 0.6895833333333333 0.08203125 0.37083333333333335 4 | 7 0.6957031250000001 0.7152777777777778 0.12578125 0.35833333333333334 5 | 5 0.9066406250000001 0.7034722222222223 0.11484375000000001 0.38472222222222224 6 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000004.txt: -------------------------------------------------------------------------------- 1 | 8 0.478125 0.4375 0.2609375 0.4444444444444445 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000005.txt: -------------------------------------------------------------------------------- 1 | 11 0.7578125 0.7076388888888889 0.26406250000000003 0.23750000000000002 2 | 12 0.19765625 0.6729166666666667 0.2265625 0.20972222222222223 3 | 15 0.7546875000000001 0.47361111111111115 0.051562500000000004 0.08611111111111111 4 | 14 0.6664062500000001 0.47847222222222224 0.026562500000000003 0.0375 5 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000006.txt: -------------------------------------------------------------------------------- 1 | 13 0.5169270833333334 0.6722222222222223 0.1828125 0.5925925925925926 2 | 13 0.6388020833333333 0.33333333333333337 0.0421875 0.09074074074074075 3 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000007.txt: -------------------------------------------------------------------------------- 1 | 9 0.56953125 0.2837962962962963 0.3255208333333333 0.42314814814814816 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000008.txt: -------------------------------------------------------------------------------- 1 | 8 0.5239583333333333 0.5453703703703704 0.5322916666666666 0.24444444444444446 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000009.txt: -------------------------------------------------------------------------------- 1 | 13 0.35273437500000004 0.5840277777777778 0.67890625 0.6597222222222222 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000010.txt: -------------------------------------------------------------------------------- 1 | 8 0.552734375 0.6784722222222223 0.8382812500000001 0.44583333333333336 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000011.txt: -------------------------------------------------------------------------------- 1 | 12 0.44140625 0.5951388888888889 0.35781250000000003 0.27083333333333337 2 | 8 0.591015625 0.8097222222222222 0.24609375 0.18055555555555555 3 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000012.txt: -------------------------------------------------------------------------------- 1 | 4 0.55390625 0.49583333333333335 0.884375 0.7388888888888889 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000013.txt: -------------------------------------------------------------------------------- 1 | 15 0.405078125 0.5319444444444444 0.63828125 0.5750000000000001 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000014.txt: -------------------------------------------------------------------------------- 1 | 6 0.20468750000000002 0.5611111111111111 0.14375000000000002 0.4277777777777778 2 | 6 0.27109375 0.5479166666666667 0.08125 0.4152777777777778 3 | 6 0.6355468750000001 0.5576388888888889 0.14609375 0.5069444444444444 4 | 7 0.7546875000000001 0.5423611111111112 0.15000000000000002 0.5708333333333333 5 | 5 0.8859375 0.5708333333333333 0.1015625 0.45 6 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000015.txt: -------------------------------------------------------------------------------- 1 | 13 0.640625 0.4625 0.5281250000000001 0.4916666666666667 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000016.txt: -------------------------------------------------------------------------------- 1 | 7 0.6252604166666667 0.4777777777777778 0.2911458333333333 0.6333333333333333 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000017.txt: -------------------------------------------------------------------------------- 1 | 8 0.47812499999999997 0.5671296296296297 0.690625 0.5435185185185185 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000018.txt: -------------------------------------------------------------------------------- 1 | 8 0.44453125 0.6092592592592593 0.6880208333333333 0.5296296296296297 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000019.txt: -------------------------------------------------------------------------------- 1 | 8 0.523046875 0.6361111111111112 0.9226562500000001 0.4222222222222222 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000020.txt: -------------------------------------------------------------------------------- 1 | 4 0.508984375 0.3875 0.9789062500000001 0.775 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000021.txt: -------------------------------------------------------------------------------- 1 | 9 0.4393229166666667 0.6231481481481481 0.34010416666666665 0.6129629629629629 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000022.txt: -------------------------------------------------------------------------------- 1 | 4 0.5533854166666666 0.5796296296296296 0.3067708333333333 0.21851851851851853 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000023.txt: -------------------------------------------------------------------------------- 1 | 8 0.5356770833333333 0.4916666666666667 0.7234375 0.43333333333333335 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000024.txt: -------------------------------------------------------------------------------- 1 | 8 0.5776041666666667 0.4365740740740741 0.7791666666666667 0.6027777777777777 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000025.txt: -------------------------------------------------------------------------------- 1 | 3 0.5578125 0.3715277777777778 0.065625 0.10416666666666667 2 | 3 0.8984375 0.48333333333333334 0.07968750000000001 0.11111111111111112 3 | 3 0.622265625 0.5125000000000001 0.047656250000000004 0.125 4 | 1 0.30117187500000003 0.5375 0.05234375 0.11944444444444445 5 | 1 0.36171875000000003 0.38958333333333334 0.028125 0.0625 6 | 3 0.72265625 0.35625 0.029687500000000002 0.0625 7 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000026.txt: -------------------------------------------------------------------------------- 1 | 5 0.560546875 0.5270833333333333 0.8382812500000001 0.5291666666666667 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000027.txt: -------------------------------------------------------------------------------- 1 | 12 0.5473958333333333 0.7300925925925926 0.6604166666666667 0.3231481481481482 2 | 12 0.55390625 0.5736111111111112 0.6223958333333334 0.35462962962962963 3 | 9 0.20052083333333334 0.250462962962963 0.290625 0.23055555555555557 4 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000028.txt: -------------------------------------------------------------------------------- 1 | 8 0.49192708333333335 0.6013888888888889 0.5317708333333333 0.5342592592592593 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000029.txt: -------------------------------------------------------------------------------- 1 | 12 0.7013020833333333 0.5916666666666667 0.5453125 0.5851851851851853 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/labels/000030.txt: -------------------------------------------------------------------------------- 1 | 13 0.548828125 0.4388888888888889 0.81640625 0.6833333333333333 2 | -------------------------------------------------------------------------------- /datasets/MergedLabels/test.txt: -------------------------------------------------------------------------------- 1 | ./datasets/MergedLabels/images/000021.jpeg 2 | ./datasets/MergedLabels/images/000022.jpeg 3 | ./datasets/MergedLabels/images/000023.jpeg 4 | ./datasets/MergedLabels/images/000024.jpeg 5 | ./datasets/MergedLabels/images/000025.jpeg 6 | ./datasets/MergedLabels/images/000026.jpeg 7 | ./datasets/MergedLabels/images/000027.jpeg 8 | ./datasets/MergedLabels/images/000028.jpeg 9 | ./datasets/MergedLabels/images/000029.jpeg 10 | ./datasets/MergedLabels/images/000030.jpeg -------------------------------------------------------------------------------- /datasets/MergedLabels/train.txt: -------------------------------------------------------------------------------- 1 | ./datasets/MergedLabels/images/000000.jpeg 2 | ./datasets/MergedLabels/images/000001.jpeg 3 | ./datasets/MergedLabels/images/000002.jpeg 4 | ./datasets/MergedLabels/images/000003.jpeg 5 | ./datasets/MergedLabels/images/000004.jpeg 6 | ./datasets/MergedLabels/images/000005.jpeg 7 | ./datasets/MergedLabels/images/000006.jpeg 8 | ./datasets/MergedLabels/images/000007.jpeg 9 | ./datasets/MergedLabels/images/000008.jpeg 10 | ./datasets/MergedLabels/images/000009.jpeg 11 | ./datasets/MergedLabels/images/000010.jpeg 12 | ./datasets/MergedLabels/images/000011.jpeg 13 | ./datasets/MergedLabels/images/000012.jpeg 14 | ./datasets/MergedLabels/images/000013.jpeg 15 | ./datasets/MergedLabels/images/000014.jpeg 16 | ./datasets/MergedLabels/images/000015.jpeg 17 | -------------------------------------------------------------------------------- /datasets/MergedLabels/trainval.txt: -------------------------------------------------------------------------------- 1 | ./datasets/MergedLabels/images/000016.jpeg 2 | ./datasets/MergedLabels/images/000017.jpeg 3 | ./datasets/MergedLabels/images/000018.jpeg 4 | ./datasets/MergedLabels/images/000019.jpeg 5 | ./datasets/MergedLabels/images/000020.jpeg -------------------------------------------------------------------------------- /datasets/MultiLabels/Multiple.yaml: -------------------------------------------------------------------------------- 1 | 2 | # train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/] 3 | train: datasets/MultiLabels/train.txt # images & multiLabels 4 | 5 | val: datasets/MergedLabels/trainval.txt # images & mergedLabels 6 | test: datasets/MergedLabels/test.txt # images & mergedLabels 7 | 8 | 9 | # number of classes 10 | nc: 2 # classes 11 | nc1: 8 # degrees 12 | 13 | # class names 14 | names: [ "WarShip", "CommonShip" ] # 2 classes 15 | others: [ "135", "90", "45", "00", "45", "90", "135", "180" ] # 8 degrees -------------------------------------------------------------------------------- /datasets/MultiLabels/images: -------------------------------------------------------------------------------- 1 | ../images -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000000.txt: -------------------------------------------------------------------------------- 1 | 1 0.4231770833333333 0.46805555555555556 0.5151041666666667 0.7953703703703704 1 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000001.txt: -------------------------------------------------------------------------------- 1 | 1 0.5437500000000001 0.46597222222222223 0.0671875 0.0625 4 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000002.txt: -------------------------------------------------------------------------------- 1 | 0 0.646875 0.525 0.6802083333333333 0.8314814814814815 1 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000003.txt: -------------------------------------------------------------------------------- 1 | 0 0.255859375 0.6736111111111112 0.13046875 0.47500000000000003 6 2 | 0 0.361328125 0.6777777777777778 0.11484375000000001 0.4305555555555556 6 3 | 0 0.432421875 0.6895833333333333 0.08203125 0.37083333333333335 6 4 | 0 0.6957031250000001 0.7152777777777778 0.12578125 0.35833333333333334 7 5 | 0 0.9066406250000001 0.7034722222222223 0.11484375000000001 0.38472222222222224 5 6 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000004.txt: -------------------------------------------------------------------------------- 1 | 1 0.478125 0.4375 0.2609375 0.4444444444444445 0 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000005.txt: -------------------------------------------------------------------------------- 1 | 1 0.7578125 0.7076388888888889 0.26406250000000003 0.23750000000000002 3 2 | 1 0.19765625 0.6729166666666667 0.2265625 0.20972222222222223 4 3 | 1 0.7546875000000001 0.47361111111111115 0.051562500000000004 0.08611111111111111 7 4 | 1 0.6664062500000001 0.47847222222222224 0.026562500000000003 0.0375 6 5 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000006.txt: -------------------------------------------------------------------------------- 1 | 1 0.5169270833333334 0.6722222222222223 0.1828125 0.5925925925925926 5 2 | 1 0.6388020833333333 0.33333333333333337 0.0421875 0.09074074074074075 5 3 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000007.txt: -------------------------------------------------------------------------------- 1 | 1 0.56953125 0.2837962962962963 0.3255208333333333 0.42314814814814816 1 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000008.txt: -------------------------------------------------------------------------------- 1 | 1 0.5239583333333333 0.5453703703703704 0.5322916666666666 0.24444444444444446 0 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000009.txt: -------------------------------------------------------------------------------- 1 | 1 0.35273437500000004 0.5840277777777778 0.67890625 0.6597222222222222 5 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000010.txt: -------------------------------------------------------------------------------- 1 | 1 0.552734375 0.6784722222222223 0.8382812500000001 0.44583333333333336 0 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000011.txt: -------------------------------------------------------------------------------- 1 | 1 0.44140625 0.5951388888888889 0.35781250000000003 0.27083333333333337 4 2 | 1 0.591015625 0.8097222222222222 0.24609375 0.18055555555555555 0 3 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000012.txt: -------------------------------------------------------------------------------- 1 | 0 0.55390625 0.49583333333333335 0.884375 0.7388888888888889 4 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000013.txt: -------------------------------------------------------------------------------- 1 | 1 0.405078125 0.5319444444444444 0.63828125 0.5750000000000001 7 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000014.txt: -------------------------------------------------------------------------------- 1 | 0 0.20468750000000002 0.5611111111111111 0.14375000000000002 0.4277777777777778 6 2 | 0 0.27109375 0.5479166666666667 0.08125 0.4152777777777778 6 3 | 0 0.6355468750000001 0.5576388888888889 0.14609375 0.5069444444444444 6 4 | 0 0.7546875000000001 0.5423611111111112 0.15000000000000002 0.5708333333333333 7 5 | 0 0.8859375 0.5708333333333333 0.1015625 0.45 5 6 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000015.txt: -------------------------------------------------------------------------------- 1 | 1 0.640625 0.4625 0.5281250000000001 0.4916666666666667 5 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000016.txt: -------------------------------------------------------------------------------- 1 | 0 0.6252604166666667 0.4777777777777778 0.2911458333333333 0.6333333333333333 7 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000017.txt: -------------------------------------------------------------------------------- 1 | 1 0.47812499999999997 0.5671296296296297 0.690625 0.5435185185185185 0 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000018.txt: -------------------------------------------------------------------------------- 1 | 1 0.44453125 0.6092592592592593 0.6880208333333333 0.5296296296296297 0 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000019.txt: -------------------------------------------------------------------------------- 1 | 1 0.523046875 0.6361111111111112 0.9226562500000001 0.4222222222222222 0 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000020.txt: -------------------------------------------------------------------------------- 1 | 0 0.508984375 0.3875 0.9789062500000001 0.775 4 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000021.txt: -------------------------------------------------------------------------------- 1 | 1 0.4393229166666667 0.6231481481481481 0.34010416666666665 0.6129629629629629 1 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000022.txt: -------------------------------------------------------------------------------- 1 | 0 0.5533854166666666 0.5796296296296296 0.3067708333333333 0.21851851851851853 4 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000023.txt: -------------------------------------------------------------------------------- 1 | 1 0.5356770833333333 0.4916666666666667 0.7234375 0.43333333333333335 0 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000024.txt: -------------------------------------------------------------------------------- 1 | 1 0.5776041666666667 0.4365740740740741 0.7791666666666667 0.6027777777777777 0 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000025.txt: -------------------------------------------------------------------------------- 1 | 0 0.5578125 0.3715277777777778 0.065625 0.10416666666666667 3 2 | 0 0.8984375 0.48333333333333334 0.07968750000000001 0.11111111111111112 3 3 | 0 0.622265625 0.5125000000000001 0.047656250000000004 0.125 3 4 | 0 0.30117187500000003 0.5375 0.05234375 0.11944444444444445 1 5 | 0 0.36171875000000003 0.38958333333333334 0.028125 0.0625 1 6 | 0 0.72265625 0.35625 0.029687500000000002 0.0625 3 7 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000026.txt: -------------------------------------------------------------------------------- 1 | 0 0.560546875 0.5270833333333333 0.8382812500000001 0.5291666666666667 5 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000027.txt: -------------------------------------------------------------------------------- 1 | 1 0.5473958333333333 0.7300925925925926 0.6604166666666667 0.3231481481481482 4 2 | 1 0.55390625 0.5736111111111112 0.6223958333333334 0.35462962962962963 4 3 | 1 0.20052083333333334 0.250462962962963 0.290625 0.23055555555555557 1 4 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000028.txt: -------------------------------------------------------------------------------- 1 | 1 0.49192708333333335 0.6013888888888889 0.5317708333333333 0.5342592592592593 0 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000029.txt: -------------------------------------------------------------------------------- 1 | 1 0.7013020833333333 0.5916666666666667 0.5453125 0.5851851851851853 4 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/labels/000030.txt: -------------------------------------------------------------------------------- 1 | 1 0.548828125 0.4388888888888889 0.81640625 0.6833333333333333 5 2 | -------------------------------------------------------------------------------- /datasets/MultiLabels/test.txt: -------------------------------------------------------------------------------- 1 | ./datasets/MultiLabels/images/000021.jpeg 2 | ./datasets/MultiLabels/images/000022.jpeg 3 | ./datasets/MultiLabels/images/000023.jpeg 4 | ./datasets/MultiLabels/images/000024.jpeg 5 | ./datasets/MultiLabels/images/000025.jpeg 6 | ./datasets/MultiLabels/images/000026.jpeg 7 | ./datasets/MultiLabels/images/000027.jpeg 8 | ./datasets/MultiLabels/images/000028.jpeg 9 | ./datasets/MultiLabels/images/000029.jpeg 10 | ./datasets/MultiLabels/images/000030.jpeg -------------------------------------------------------------------------------- /datasets/MultiLabels/train.txt: -------------------------------------------------------------------------------- 1 | ./datasets/MultiLabels/images/000000.jpeg 2 | ./datasets/MultiLabels/images/000001.jpeg 3 | ./datasets/MultiLabels/images/000002.jpeg 4 | ./datasets/MultiLabels/images/000003.jpeg 5 | ./datasets/MultiLabels/images/000004.jpeg 6 | ./datasets/MultiLabels/images/000005.jpeg 7 | ./datasets/MultiLabels/images/000006.jpeg 8 | ./datasets/MultiLabels/images/000007.jpeg 9 | ./datasets/MultiLabels/images/000008.jpeg 10 | ./datasets/MultiLabels/images/000009.jpeg 11 | ./datasets/MultiLabels/images/000010.jpeg 12 | ./datasets/MultiLabels/images/000011.jpeg 13 | ./datasets/MultiLabels/images/000012.jpeg 14 | ./datasets/MultiLabels/images/000013.jpeg 15 | ./datasets/MultiLabels/images/000014.jpeg 16 | ./datasets/MultiLabels/images/000015.jpeg 17 | -------------------------------------------------------------------------------- /datasets/MultiLabels/trainval.txt: -------------------------------------------------------------------------------- 1 | ./datasets/MultiLabels/images/000016.jpeg 2 | ./datasets/MultiLabels/images/000017.jpeg 3 | ./datasets/MultiLabels/images/000018.jpeg 4 | ./datasets/MultiLabels/images/000019.jpeg 5 | ./datasets/MultiLabels/images/000020.jpeg -------------------------------------------------------------------------------- /datasets/images/000000.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000000.jpeg -------------------------------------------------------------------------------- /datasets/images/000001.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000001.jpeg -------------------------------------------------------------------------------- /datasets/images/000002.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000002.jpeg -------------------------------------------------------------------------------- /datasets/images/000003.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000003.jpeg -------------------------------------------------------------------------------- /datasets/images/000004.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000004.jpeg -------------------------------------------------------------------------------- /datasets/images/000005.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000005.jpeg -------------------------------------------------------------------------------- /datasets/images/000006.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000006.jpeg -------------------------------------------------------------------------------- /datasets/images/000007.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000007.jpeg -------------------------------------------------------------------------------- /datasets/images/000008.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000008.jpeg -------------------------------------------------------------------------------- /datasets/images/000009.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000009.jpeg -------------------------------------------------------------------------------- /datasets/images/000010.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000010.jpeg -------------------------------------------------------------------------------- /datasets/images/000011.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000011.jpeg -------------------------------------------------------------------------------- /datasets/images/000012.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000012.jpeg -------------------------------------------------------------------------------- /datasets/images/000013.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000013.jpeg -------------------------------------------------------------------------------- /datasets/images/000014.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000014.jpeg -------------------------------------------------------------------------------- /datasets/images/000015.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000015.jpeg -------------------------------------------------------------------------------- /datasets/images/000016.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000016.jpeg -------------------------------------------------------------------------------- /datasets/images/000017.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000017.jpeg -------------------------------------------------------------------------------- /datasets/images/000018.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000018.jpeg -------------------------------------------------------------------------------- /datasets/images/000019.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000019.jpeg -------------------------------------------------------------------------------- /datasets/images/000020.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000020.jpeg -------------------------------------------------------------------------------- /datasets/images/000021.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000021.jpeg -------------------------------------------------------------------------------- /datasets/images/000022.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000022.jpeg -------------------------------------------------------------------------------- /datasets/images/000023.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000023.jpeg -------------------------------------------------------------------------------- /datasets/images/000024.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000024.jpeg -------------------------------------------------------------------------------- /datasets/images/000025.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000025.jpeg -------------------------------------------------------------------------------- /datasets/images/000026.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000026.jpeg -------------------------------------------------------------------------------- /datasets/images/000027.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000027.jpeg -------------------------------------------------------------------------------- /datasets/images/000028.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000028.jpeg -------------------------------------------------------------------------------- /datasets/images/000029.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000029.jpeg -------------------------------------------------------------------------------- /datasets/images/000030.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/datasets/images/000030.jpeg -------------------------------------------------------------------------------- /datasets/split-datasets.py: -------------------------------------------------------------------------------- 1 | import random, os 2 | 3 | def split( src, shuffle=True, train=0.55, val=0.25): 4 | full_list = os.listdir(src + "/images") 5 | 6 | n_total = len(full_list) 7 | offset = int(n_total * train) 8 | offset2 = int(n_total * val) 9 | if n_total==0 or offset<1: 10 | return [],full_list 11 | if shuffle: 12 | random.shuffle(full_list) 13 | 14 | sublist = full_list[:offset] 15 | with open( "src/MergedLabels/train.txt" , "w") as f: 16 | for ii in sublist: 17 | f.write( "src/MergedLabels/images/" + ii + "\n") 18 | sublist = full_list[offset: offset+offset2 ] 19 | with open( "src/MergedLabels/eval.txt" , "w") as f: 20 | for ii in sublist: 21 | f.write( "src/MergedLabels/images/" + ii + "\n") 22 | sublist = full_list[ offset+offset2 :] 23 | with open( "src/MergedLabels/test.txt" , "w") as f: 24 | for ii in sublist: 25 | f.write( "src/MergedLabels/images/" + ii + "\n") 26 | print("MergedLabels split OK !") 27 | 28 | 29 | 30 | sublist = full_list[:offset] 31 | with open( "src/MultiLabels/train.txt" , "w") as f: 32 | for ii in sublist: 33 | f.write( "src/MultiLabels/images/" + ii + "\n") 34 | sublist = full_list[offset: offset+offset2 ] 35 | with open( "src/MultiLabels/eval.txt" , "w") as f: 36 | for ii in sublist: 37 | f.write( "src/MultiLabels/images/" + ii + "\n") 38 | sublist = full_list[ offset+offset2 :] 39 | with open( "src/MultiLabels/test.txt" , "w") as f: 40 | for ii in sublist: 41 | f.write( "src/MultiLabels/images/" + ii + "\n") 42 | print("MultiLabels split OK !") 43 | 44 | return 45 | 46 | 47 | split( os.getcwd() ) -------------------------------------------------------------------------------- /datasets/voc2myYOLO.py: -------------------------------------------------------------------------------- 1 | import xml.etree.ElementTree as ET 2 | import os 3 | from tqdm import tqdm 4 | 5 | yaml = {} 6 | yaml['names'] = [ "WarShip", "CommonShip" ] # define the 1st Labels by yourself 7 | yaml['others'] = [ "0", "1", "2", "3", "4", "5", "6", "7" ] # define the 2nd Labels by yourself 8 | 9 | def convert_label(path, image_id): 10 | def convert_box(size, box): 11 | dw, dh = 1. / size[0], 1. / size[1] 12 | 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] 13 | return x * dw, y * dh, w * dw, h * dh 14 | 15 | in_file = open(f"{path}/../Annotations/{image_id}.xml") 16 | out_file = open(f"{path}/labels/{image_id}.txt", 'w') 17 | tree = ET.parse(in_file) 18 | root = tree.getroot() 19 | size = root.find('size') 20 | w = int(size.find('width').text) 21 | h = int(size.find('height').text) 22 | 23 | for obj in root.iter('object'): 24 | cls = obj.find('name').text # CHANGEQ BY YOUR LABEL 25 | other = obj.find('direction').text # CHANGEQ BY YOUR LABEL 26 | if cls not in yaml['names']: 27 | yaml['names'].append( cls ) 28 | if other not in yaml['others']: 29 | yaml['others'].append( other ) 30 | if cls in yaml['names'] and not int(obj.find('difficult').text) == 1: 31 | xmlbox = obj.find('bndbox') 32 | bb = convert_box((w, h), [float(xmlbox.find(x).text) for x in ('xmin', 'xmax', 'ymin', 'ymax')]) 33 | 34 | cls_id = yaml['names'].index(cls) # class id 35 | other_id = yaml['others'].index(other) # other-labels id 36 | 37 | out_file.write(" ".join([str(a) for a in (cls_id , *bb, other_id)]) + '\n') 38 | 39 | 40 | 41 | if __name__ == '__main__': 42 | 43 | VOCRoot = os.getcwd() 44 | try: 45 | os.mkdir(VOCRoot + "/labels") 46 | except: 47 | pass # "rm -rf VOCRoot + \"/labels/*\"" 48 | for xml in tqdm( os.listdir( VOCRoot + '/../Annotations/' ) ): 49 | convert_label( VOCRoot, xml.split(".")[0] ) 50 | print( yaml["names"] ) 51 | print( yaml["others"] ) -------------------------------------------------------------------------------- /datasets/voc2yolo.py: -------------------------------------------------------------------------------- 1 | import xml.etree.ElementTree as ET 2 | import os 3 | from tqdm import tqdm 4 | 5 | yaml = {} 6 | yaml['names'] = [ "WarShip", "CommonShip" ] # define the 1st Labels by yourself 7 | yaml['others'] = [ "0", "1", "2", "3", "4", "5", "6", "7" ] # define the 2nd Labels by yourself 8 | 9 | def convertMerge_labels(path, image_id): 10 | def convert_box(size, box): 11 | dw, dh = 1. / size[0], 1. / size[1] 12 | 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] 13 | return x * dw, y * dh, w * dw, h * dh 14 | 15 | in_file = open(f"{path}/../Annotations/{image_id}.xml") 16 | out_file = open(f"{path}//labels/{image_id}.txt", 'w') 17 | tree = ET.parse(in_file) 18 | root = tree.getroot() 19 | size = root.find('size') 20 | w = int(size.find('width').text) 21 | h = int(size.find('height').text) 22 | 23 | for obj in root.iter('object'): 24 | cls = obj.find('name').text # CHANGEQ BY YOUR LABEL 25 | other = obj.find('direction').text # CHANGEQ BY YOUR LABEL 26 | if cls not in yaml['names']: 27 | yaml['names'].append( cls ) 28 | if other not in yaml['others']: 29 | yaml['others'].append( other ) 30 | if cls in yaml['names'] and not int(obj.find('difficult').text) == 1: 31 | xmlbox = obj.find('bndbox') 32 | bb = convert_box((w, h), [float(xmlbox.find(x).text) for x in ('xmin', 'xmax', 'ymin', 'ymax')]) 33 | 34 | c0 = yaml['names'].index(cls) 35 | lenc0 = yaml['names'].__len__() 36 | c1 = yaml['others'].index(other) 37 | lenc1 = yaml['others'].__len__() 38 | 39 | # 树形结构 下的 叶子节点 id 40 | cls_id = c1 + c0 * lenc0 41 | 42 | out_file.write(" ".join([str(a) for a in (cls_id, *bb)]) + '\n') 43 | 44 | """ 45 | ↓↓↓↓↓↓↓↓↓↓↓↓ MultiLabels of three Type of label or more ↓↓↓↓↓↓↓ 46 | c0 = yaml['names'].index(cls) 47 | lenc0 = yaml['names'].__len__() 48 | c1 = yaml['other'].index(other) 49 | lenc1 = yaml['others'].__len__() 50 | c3 = yaml['another'].index(colors) 51 | lenc3 = yaml['another'].__len__() 52 | 53 | # 树形结构 下的 叶子节点 id 54 | cls_id = c1 + c0 * lenc0 + c1 * lenc2 * lenc3 """ 55 | 56 | 57 | 58 | if __name__ == '__main__': 59 | 60 | VOCRoot = './' # (your-project)/datasets/MergedLabels 61 | try: 62 | os.mkdir(VOCRoot + "/labels") 63 | except: 64 | pass # "rm -rf VOCRoot + \"/labels/*\"" 65 | for xml in tqdm( os.listdir( VOCRoot + '/../Annotations/' ) ): 66 | convertMerge_labels( VOCRoot, xml.split(".")[0] ) 67 | 68 | print( yaml["names"] ) 69 | print( yaml["others"] ) -------------------------------------------------------------------------------- /models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/models/__init__.py -------------------------------------------------------------------------------- /models/experimental.py: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | """ 3 | Experimental modules 4 | """ 5 | 6 | import numpy as np 7 | import torch 8 | import torch.nn as nn 9 | 10 | from models.common import Conv 11 | from utils.downloads import attempt_download 12 | 13 | 14 | class CrossConv(nn.Module): 15 | # Cross Convolution Downsample 16 | def __init__(self, c1, c2, k=3, s=1, g=1, e=1.0, shortcut=False): 17 | # ch_in, ch_out, kernel, stride, groups, expansion, shortcut 18 | super().__init__() 19 | c_ = int(c2 * e) # hidden channels 20 | self.cv1 = Conv(c1, c_, (1, k), (1, s)) 21 | self.cv2 = Conv(c_, c2, (k, 1), (s, 1), g=g) 22 | self.add = shortcut and c1 == c2 23 | 24 | def forward(self, x): 25 | return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x)) 26 | 27 | 28 | class Sum(nn.Module): 29 | # Weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 30 | def __init__(self, n, weight=False): # n: number of inputs 31 | super().__init__() 32 | self.weight = weight # apply weights boolean 33 | self.iter = range(n - 1) # iter object 34 | if weight: 35 | self.w = nn.Parameter(-torch.arange(1., n) / 2, requires_grad=True) # layer weights 36 | 37 | def forward(self, x): 38 | y = x[0] # no weight 39 | if self.weight: 40 | w = torch.sigmoid(self.w) * 2 41 | for i in self.iter: 42 | y = y + x[i + 1] * w[i] 43 | else: 44 | for i in self.iter: 45 | y = y + x[i + 1] 46 | return y 47 | 48 | 49 | class MixConv2d(nn.Module): 50 | # Mixed Depth-wise Conv https://arxiv.org/abs/1907.09595 51 | def __init__(self, c1, c2, k=(1, 3), s=1, equal_ch=True): 52 | super().__init__() 53 | groups = len(k) 54 | if equal_ch: # equal c_ per group 55 | i = torch.linspace(0, groups - 1E-6, c2).floor() # c2 indices 56 | c_ = [(i == g).sum() for g in range(groups)] # intermediate channels 57 | else: # equal weight.numel() per group 58 | b = [c2] + [0] * groups 59 | a = np.eye(groups + 1, groups, k=-1) 60 | a -= np.roll(a, 1, axis=1) 61 | a *= np.array(k) ** 2 62 | a[0] = 1 63 | c_ = np.linalg.lstsq(a, b, rcond=None)[0].round() # solve for equal weight indices, ax = b 64 | 65 | self.m = nn.ModuleList([nn.Conv2d(c1, int(c_[g]), k[g], s, k[g] // 2, bias=False) for g in range(groups)]) 66 | self.bn = nn.BatchNorm2d(c2) 67 | self.act = nn.LeakyReLU(0.1, inplace=True) 68 | 69 | def forward(self, x): 70 | return x + self.act(self.bn(torch.cat([m(x) for m in self.m], 1))) 71 | 72 | 73 | class Ensemble(nn.ModuleList): 74 | # Ensemble of models 75 | def __init__(self): 76 | super().__init__() 77 | 78 | def forward(self, x, augment=False, profile=False, visualize=False): 79 | y = [] 80 | for module in self: 81 | y.append(module(x, augment, profile, visualize)[0]) 82 | # y = torch.stack(y).max(0)[0] # max ensemble 83 | # y = torch.stack(y).mean(0) # mean ensemble 84 | y = torch.cat(y, 1) # nms ensemble 85 | return y, None # inference, train output 86 | 87 | 88 | def attempt_load(weights, map_location=None, inplace=True, fuse=True): 89 | from models.yolo import Detect, Model 90 | 91 | # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a 92 | model = Ensemble() 93 | for w in weights if isinstance(weights, list) else [weights]: 94 | ckpt = torch.load(attempt_download(w), map_location=map_location) # load 95 | if fuse: 96 | model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval()) # FP32 model 97 | else: 98 | model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().eval()) # without layer fuse 99 | 100 | 101 | # Compatibility updates 102 | for m in model.modules(): 103 | if type(m) in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model]: 104 | m.inplace = inplace # pytorch 1.7.0 compatibility 105 | if type(m) is Detect: 106 | if not isinstance(m.anchor_grid, list): # new Detect Layer compatibility 107 | delattr(m, 'anchor_grid') 108 | setattr(m, 'anchor_grid', [torch.zeros(1)] * m.nl) 109 | elif type(m) is Conv: 110 | m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatibility 111 | 112 | if len(model) == 1: 113 | return model[-1] # return model 114 | else: 115 | print(f'Ensemble created with {weights}\n') 116 | for k in ['names']: 117 | setattr(model, k, getattr(model[-1], k)) 118 | model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride # max stride 119 | return model # return ensemble 120 | -------------------------------------------------------------------------------- /models/hub/anchors.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # Default anchors for COCO data 3 | 4 | 5 | # P5 ------------------------------------------------------------------------------------------------------------------- 6 | # P5-640: 7 | anchors_p5_640: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | 13 | # P6 ------------------------------------------------------------------------------------------------------------------- 14 | # P6-640: thr=0.25: 0.9964 BPR, 5.54 anchors past thr, n=12, img_size=640, metric_all=0.281/0.716-mean/best, past_thr=0.469-mean: 9,11, 21,19, 17,41, 43,32, 39,70, 86,64, 65,131, 134,130, 120,265, 282,180, 247,354, 512,387 15 | anchors_p6_640: 16 | - [9,11, 21,19, 17,41] # P3/8 17 | - [43,32, 39,70, 86,64] # P4/16 18 | - [65,131, 134,130, 120,265] # P5/32 19 | - [282,180, 247,354, 512,387] # P6/64 20 | 21 | # P6-1280: thr=0.25: 0.9950 BPR, 5.55 anchors past thr, n=12, img_size=1280, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 22 | anchors_p6_1280: 23 | - [19,27, 44,40, 38,94] # P3/8 24 | - [96,68, 86,152, 180,137] # P4/16 25 | - [140,301, 303,264, 238,542] # P5/32 26 | - [436,615, 739,380, 925,792] # P6/64 27 | 28 | # P6-1920: thr=0.25: 0.9950 BPR, 5.55 anchors past thr, n=12, img_size=1920, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 28,41, 67,59, 57,141, 144,103, 129,227, 270,205, 209,452, 455,396, 358,812, 653,922, 1109,570, 1387,1187 29 | anchors_p6_1920: 30 | - [28,41, 67,59, 57,141] # P3/8 31 | - [144,103, 129,227, 270,205] # P4/16 32 | - [209,452, 455,396, 358,812] # P5/32 33 | - [653,922, 1109,570, 1387,1187] # P6/64 34 | 35 | 36 | # P7 ------------------------------------------------------------------------------------------------------------------- 37 | # P7-640: thr=0.25: 0.9962 BPR, 6.76 anchors past thr, n=15, img_size=640, metric_all=0.275/0.733-mean/best, past_thr=0.466-mean: 11,11, 13,30, 29,20, 30,46, 61,38, 39,92, 78,80, 146,66, 79,163, 149,150, 321,143, 157,303, 257,402, 359,290, 524,372 38 | anchors_p7_640: 39 | - [11,11, 13,30, 29,20] # P3/8 40 | - [30,46, 61,38, 39,92] # P4/16 41 | - [78,80, 146,66, 79,163] # P5/32 42 | - [149,150, 321,143, 157,303] # P6/64 43 | - [257,402, 359,290, 524,372] # P7/128 44 | 45 | # P7-1280: thr=0.25: 0.9968 BPR, 6.71 anchors past thr, n=15, img_size=1280, metric_all=0.273/0.732-mean/best, past_thr=0.463-mean: 19,22, 54,36, 32,77, 70,83, 138,71, 75,173, 165,159, 148,334, 375,151, 334,317, 251,626, 499,474, 750,326, 534,814, 1079,818 46 | anchors_p7_1280: 47 | - [19,22, 54,36, 32,77] # P3/8 48 | - [70,83, 138,71, 75,173] # P4/16 49 | - [165,159, 148,334, 375,151] # P5/32 50 | - [334,317, 251,626, 499,474] # P6/64 51 | - [750,326, 534,814, 1079,818] # P7/128 52 | 53 | # P7-1920: thr=0.25: 0.9968 BPR, 6.71 anchors past thr, n=15, img_size=1920, metric_all=0.273/0.732-mean/best, past_thr=0.463-mean: 29,34, 81,55, 47,115, 105,124, 207,107, 113,259, 247,238, 222,500, 563,227, 501,476, 376,939, 749,711, 1126,489, 801,1222, 1618,1227 54 | anchors_p7_1920: 55 | - [29,34, 81,55, 47,115] # P3/8 56 | - [105,124, 207,107, 113,259] # P4/16 57 | - [247,238, 222,500, 563,227] # P5/32 58 | - [501,476, 376,939, 749,711] # P6/64 59 | - [1126,489, 801,1222, 1618,1227] # P7/128 60 | -------------------------------------------------------------------------------- /models/hub/yolov3-spp.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # darknet53 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 17 | [-1, 1, Bottleneck, [64]], 18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 19 | [-1, 2, Bottleneck, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 21 | [-1, 8, Bottleneck, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 23 | [-1, 8, Bottleneck, [512]], 24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 25 | [-1, 4, Bottleneck, [1024]], # 10 26 | ] 27 | 28 | # YOLOv3-SPP head 29 | head: 30 | [[-1, 1, Bottleneck, [1024, False]], 31 | [-1, 1, SPP, [512, [5, 9, 13]]], 32 | [-1, 1, Conv, [1024, 3, 1]], 33 | [-1, 1, Conv, [512, 1, 1]], 34 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large) 35 | 36 | [-2, 1, Conv, [256, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 38 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 39 | [-1, 1, Bottleneck, [512, False]], 40 | [-1, 1, Bottleneck, [512, False]], 41 | [-1, 1, Conv, [256, 1, 1]], 42 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium) 43 | 44 | [-2, 1, Conv, [128, 1, 1]], 45 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 46 | [[-1, 6], 1, Concat, [1]], # cat backbone P3 47 | [-1, 1, Bottleneck, [256, False]], 48 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small) 49 | 50 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 51 | ] 52 | -------------------------------------------------------------------------------- /models/hub/yolov3-tiny.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10,14, 23,27, 37,58] # P4/16 9 | - [81,82, 135,169, 344,319] # P5/32 10 | 11 | # YOLOv3-tiny backbone 12 | backbone: 13 | # [from, number, module, args] 14 | [[-1, 1, Conv, [16, 3, 1]], # 0 15 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 1-P1/2 16 | [-1, 1, Conv, [32, 3, 1]], 17 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 3-P2/4 18 | [-1, 1, Conv, [64, 3, 1]], 19 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 5-P3/8 20 | [-1, 1, Conv, [128, 3, 1]], 21 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 7-P4/16 22 | [-1, 1, Conv, [256, 3, 1]], 23 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 9-P5/32 24 | [-1, 1, Conv, [512, 3, 1]], 25 | [-1, 1, nn.ZeroPad2d, [[0, 1, 0, 1]]], # 11 26 | [-1, 1, nn.MaxPool2d, [2, 1, 0]], # 12 27 | ] 28 | 29 | # YOLOv3-tiny head 30 | head: 31 | [[-1, 1, Conv, [1024, 3, 1]], 32 | [-1, 1, Conv, [256, 1, 1]], 33 | [-1, 1, Conv, [512, 3, 1]], # 15 (P5/32-large) 34 | 35 | [-2, 1, Conv, [128, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 37 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 38 | [-1, 1, Conv, [256, 3, 1]], # 19 (P4/16-medium) 39 | 40 | [[19, 15], 1, Detect, [nc, anchors]], # Detect(P4, P5) 41 | ] 42 | -------------------------------------------------------------------------------- /models/hub/yolov3.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # darknet53 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 17 | [-1, 1, Bottleneck, [64]], 18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 19 | [-1, 2, Bottleneck, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 21 | [-1, 8, Bottleneck, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 23 | [-1, 8, Bottleneck, [512]], 24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 25 | [-1, 4, Bottleneck, [1024]], # 10 26 | ] 27 | 28 | # YOLOv3 head 29 | head: 30 | [[-1, 1, Bottleneck, [1024, False]], 31 | [-1, 1, Conv, [512, [1, 1]]], 32 | [-1, 1, Conv, [1024, 3, 1]], 33 | [-1, 1, Conv, [512, 1, 1]], 34 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large) 35 | 36 | [-2, 1, Conv, [256, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 38 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 39 | [-1, 1, Bottleneck, [512, False]], 40 | [-1, 1, Bottleneck, [512, False]], 41 | [-1, 1, Conv, [256, 1, 1]], 42 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium) 43 | 44 | [-2, 1, Conv, [128, 1, 1]], 45 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 46 | [[-1, 6], 1, Concat, [1]], # cat backbone P3 47 | [-1, 1, Bottleneck, [256, False]], 48 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small) 49 | 50 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 51 | ] 52 | -------------------------------------------------------------------------------- /models/hub/yolov5-bifpn.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2 16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, C3, [128]], 18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 19 | [-1, 9, C3, [256]], 20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, C3, [512]] 22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 1, SPP, [1024, [5, 9, 13]]], 24 | [-1, 3, C3, [1024, False]], # 9 25 | ] 26 | 27 | # YOLOv5 BiFPN head 28 | head: 29 | [[-1, 1, Conv, [512, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 32 | [-1, 3, C3, [512, False]], # 13 33 | 34 | [-1, 1, Conv, [256, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 38 | 39 | [-1, 1, Conv, [256, 3, 2]], 40 | [[-1, 14, 6], 1, Concat, [1]], # cat P4 41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 42 | 43 | [-1, 1, Conv, [512, 3, 2]], 44 | [[-1, 10], 1, Concat, [1]], # cat head P5 45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 46 | 47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /models/hub/yolov5-fpn.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2 16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, Bottleneck, [128]], 18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 19 | [-1, 9, BottleneckCSP, [256]], 20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, BottleneckCSP, [512]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 1, SPP, [1024, [5, 9, 13]]], 24 | [-1, 6, BottleneckCSP, [1024]], # 9 25 | ] 26 | 27 | # YOLOv5 FPN head 28 | head: 29 | [[-1, 3, BottleneckCSP, [1024, False]], # 10 (P5/32-large) 30 | 31 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 1, Conv, [512, 1, 1]], 34 | [-1, 3, BottleneckCSP, [512, False]], # 14 (P4/16-medium) 35 | 36 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 1, Conv, [256, 1, 1]], 39 | [-1, 3, BottleneckCSP, [256, False]], # 18 (P3/8-small) 40 | 41 | [[18, 14, 10], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 42 | ] 43 | -------------------------------------------------------------------------------- /models/hub/yolov5-p2.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 3 8 | 9 | # YOLOv5 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [[-1, 1, Focus, [64, 3]], # 0-P1/2 13 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 14 | [-1, 3, C3, [128]], 15 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 16 | [-1, 9, C3, [256]], 17 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 18 | [-1, 9, C3, [512]], 19 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 20 | [-1, 1, SPP, [1024, [5, 9, 13]]], 21 | [-1, 3, C3, [1024, False]], # 9 22 | ] 23 | 24 | # YOLOv5 head 25 | head: 26 | [[-1, 1, Conv, [512, 1, 1]], 27 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 28 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 29 | [-1, 3, C3, [512, False]], # 13 30 | 31 | [-1, 1, Conv, [256, 1, 1]], 32 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 33 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 34 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 35 | 36 | [-1, 1, Conv, [128, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 38 | [[-1, 2], 1, Concat, [1]], # cat backbone P2 39 | [-1, 1, C3, [128, False]], # 21 (P2/4-xsmall) 40 | 41 | [-1, 1, Conv, [128, 3, 2]], 42 | [[-1, 18], 1, Concat, [1]], # cat head P3 43 | [-1, 3, C3, [256, False]], # 24 (P3/8-small) 44 | 45 | [-1, 1, Conv, [256, 3, 2]], 46 | [[-1, 14], 1, Concat, [1]], # cat head P4 47 | [-1, 3, C3, [512, False]], # 27 (P4/16-medium) 48 | 49 | [-1, 1, Conv, [512, 3, 2]], 50 | [[-1, 10], 1, Concat, [1]], # cat head P5 51 | [-1, 3, C3, [1024, False]], # 30 (P5/32-large) 52 | 53 | [[21, 24, 27, 30], 1, Detect, [nc, anchors]], # Detect(P2, P3, P4, P5) 54 | ] 55 | -------------------------------------------------------------------------------- /models/hub/yolov5-p6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 3 8 | 9 | # YOLOv5 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [[-1, 1, Focus, [64, 3]], # 0-P1/2 13 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 14 | [-1, 3, C3, [128]], 15 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 16 | [-1, 9, C3, [256]], 17 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 18 | [-1, 9, C3, [512]], 19 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 20 | [-1, 3, C3, [768]], 21 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 22 | [-1, 1, SPP, [1024, [3, 5, 7]]], 23 | [-1, 3, C3, [1024, False]], # 11 24 | ] 25 | 26 | # YOLOv5 head 27 | head: 28 | [[-1, 1, Conv, [768, 1, 1]], 29 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 30 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 31 | [-1, 3, C3, [768, False]], # 15 32 | 33 | [-1, 1, Conv, [512, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 36 | [-1, 3, C3, [512, False]], # 19 37 | 38 | [-1, 1, Conv, [256, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 40 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 41 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 42 | 43 | [-1, 1, Conv, [256, 3, 2]], 44 | [[-1, 20], 1, Concat, [1]], # cat head P4 45 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 46 | 47 | [-1, 1, Conv, [512, 3, 2]], 48 | [[-1, 16], 1, Concat, [1]], # cat head P5 49 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 50 | 51 | [-1, 1, Conv, [768, 3, 2]], 52 | [[-1, 12], 1, Concat, [1]], # cat head P6 53 | [-1, 3, C3, [1024, False]], # 32 (P5/64-xlarge) 54 | 55 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 56 | ] 57 | -------------------------------------------------------------------------------- /models/hub/yolov5-p7.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 3 8 | 9 | # YOLOv5 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [[-1, 1, Focus, [64, 3]], # 0-P1/2 13 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 14 | [-1, 3, C3, [128]], 15 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 16 | [-1, 9, C3, [256]], 17 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 18 | [-1, 9, C3, [512]], 19 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 20 | [-1, 3, C3, [768]], 21 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 22 | [-1, 3, C3, [1024]], 23 | [-1, 1, Conv, [1280, 3, 2]], # 11-P7/128 24 | [-1, 1, SPP, [1280, [3, 5]]], 25 | [-1, 3, C3, [1280, False]], # 13 26 | ] 27 | 28 | # YOLOv5 head 29 | head: 30 | [[-1, 1, Conv, [1024, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 32 | [[-1, 10], 1, Concat, [1]], # cat backbone P6 33 | [-1, 3, C3, [1024, False]], # 17 34 | 35 | [-1, 1, Conv, [768, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 37 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 38 | [-1, 3, C3, [768, False]], # 21 39 | 40 | [-1, 1, Conv, [512, 1, 1]], 41 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 42 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 43 | [-1, 3, C3, [512, False]], # 25 44 | 45 | [-1, 1, Conv, [256, 1, 1]], 46 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 47 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 48 | [-1, 3, C3, [256, False]], # 29 (P3/8-small) 49 | 50 | [-1, 1, Conv, [256, 3, 2]], 51 | [[-1, 26], 1, Concat, [1]], # cat head P4 52 | [-1, 3, C3, [512, False]], # 32 (P4/16-medium) 53 | 54 | [-1, 1, Conv, [512, 3, 2]], 55 | [[-1, 22], 1, Concat, [1]], # cat head P5 56 | [-1, 3, C3, [768, False]], # 35 (P5/32-large) 57 | 58 | [-1, 1, Conv, [768, 3, 2]], 59 | [[-1, 18], 1, Concat, [1]], # cat head P6 60 | [-1, 3, C3, [1024, False]], # 38 (P6/64-xlarge) 61 | 62 | [-1, 1, Conv, [1024, 3, 2]], 63 | [[-1, 14], 1, Concat, [1]], # cat head P7 64 | [-1, 3, C3, [1280, False]], # 41 (P7/128-xxlarge) 65 | 66 | [[29, 32, 35, 38, 41], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6, P7) 67 | ] 68 | -------------------------------------------------------------------------------- /models/hub/yolov5-panet.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2 16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, BottleneckCSP, [128]], 18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 19 | [-1, 9, BottleneckCSP, [256]], 20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, BottleneckCSP, [512]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 1, SPP, [1024, [5, 9, 13]]], 24 | [-1, 3, BottleneckCSP, [1024, False]], # 9 25 | ] 26 | 27 | # YOLOv5 PANet head 28 | head: 29 | [[-1, 1, Conv, [512, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 32 | [-1, 3, BottleneckCSP, [512, False]], # 13 33 | 34 | [-1, 1, Conv, [256, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 37 | [-1, 3, BottleneckCSP, [256, False]], # 17 (P3/8-small) 38 | 39 | [-1, 1, Conv, [256, 3, 2]], 40 | [[-1, 14], 1, Concat, [1]], # cat head P4 41 | [-1, 3, BottleneckCSP, [512, False]], # 20 (P4/16-medium) 42 | 43 | [-1, 1, Conv, [512, 3, 2]], 44 | [[-1, 10], 1, Concat, [1]], # cat head P5 45 | [-1, 3, BottleneckCSP, [1024, False]], # 23 (P5/32-large) 46 | 47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /models/hub/yolov5l6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [19,27, 44,40, 38,94] # P3/8 9 | - [96,68, 86,152, 180,137] # P4/16 10 | - [140,301, 303,264, 238,542] # P5/32 11 | - [436,615, 739,380, 925,792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [768]], 25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 26 | [-1, 3, C3, [1024]], 27 | [-1, 1, SPPF, [1024, 5]], # 11 28 | ] 29 | 30 | # YOLOv5 v6.0 head 31 | head: 32 | [[-1, 1, Conv, [768, 1, 1]], 33 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 34 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 35 | [-1, 3, C3, [768, False]], # 15 36 | 37 | [-1, 1, Conv, [512, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 39 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 40 | [-1, 3, C3, [512, False]], # 19 41 | 42 | [-1, 1, Conv, [256, 1, 1]], 43 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 44 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 45 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 46 | 47 | [-1, 1, Conv, [256, 3, 2]], 48 | [[-1, 20], 1, Concat, [1]], # cat head P4 49 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 50 | 51 | [-1, 1, Conv, [512, 3, 2]], 52 | [[-1, 16], 1, Concat, [1]], # cat head P5 53 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 54 | 55 | [-1, 1, Conv, [768, 3, 2]], 56 | [[-1, 12], 1, Concat, [1]], # cat head P6 57 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 58 | 59 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 60 | ] 61 | -------------------------------------------------------------------------------- /models/hub/yolov5m6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [19,27, 44,40, 38,94] # P3/8 9 | - [96,68, 86,152, 180,137] # P4/16 10 | - [140,301, 303,264, 238,542] # P5/32 11 | - [436,615, 739,380, 925,792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [768]], 25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 26 | [-1, 3, C3, [1024]], 27 | [-1, 1, SPPF, [1024, 5]], # 11 28 | ] 29 | 30 | # YOLOv5 v6.0 head 31 | head: 32 | [[-1, 1, Conv, [768, 1, 1]], 33 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 34 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 35 | [-1, 3, C3, [768, False]], # 15 36 | 37 | [-1, 1, Conv, [512, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 39 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 40 | [-1, 3, C3, [512, False]], # 19 41 | 42 | [-1, 1, Conv, [256, 1, 1]], 43 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 44 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 45 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 46 | 47 | [-1, 1, Conv, [256, 3, 2]], 48 | [[-1, 20], 1, Concat, [1]], # cat head P4 49 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 50 | 51 | [-1, 1, Conv, [512, 3, 2]], 52 | [[-1, 16], 1, Concat, [1]], # cat head P5 53 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 54 | 55 | [-1, 1, Conv, [768, 3, 2]], 56 | [[-1, 12], 1, Concat, [1]], # cat head P6 57 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 58 | 59 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 60 | ] 61 | -------------------------------------------------------------------------------- /models/hub/yolov5n6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [19,27, 44,40, 38,94] # P3/8 9 | - [96,68, 86,152, 180,137] # P4/16 10 | - [140,301, 303,264, 238,542] # P5/32 11 | - [436,615, 739,380, 925,792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [768]], 25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 26 | [-1, 3, C3, [1024]], 27 | [-1, 1, SPPF, [1024, 5]], # 11 28 | ] 29 | 30 | # YOLOv5 v6.0 head 31 | head: 32 | [[-1, 1, Conv, [768, 1, 1]], 33 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 34 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 35 | [-1, 3, C3, [768, False]], # 15 36 | 37 | [-1, 1, Conv, [512, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 39 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 40 | [-1, 3, C3, [512, False]], # 19 41 | 42 | [-1, 1, Conv, [256, 1, 1]], 43 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 44 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 45 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 46 | 47 | [-1, 1, Conv, [256, 3, 2]], 48 | [[-1, 20], 1, Concat, [1]], # cat head P4 49 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 50 | 51 | [-1, 1, Conv, [512, 3, 2]], 52 | [[-1, 16], 1, Concat, [1]], # cat head P5 53 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 54 | 55 | [-1, 1, Conv, [768, 3, 2]], 56 | [[-1, 12], 1, Concat, [1]], # cat head P6 57 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 58 | 59 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 60 | ] 61 | -------------------------------------------------------------------------------- /models/hub/yolov5s-ghost.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2 16 | [-1, 1, GhostConv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, C3Ghost, [128]], 18 | [-1, 1, GhostConv, [256, 3, 2]], # 3-P3/8 19 | [-1, 9, C3Ghost, [256]], 20 | [-1, 1, GhostConv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, C3Ghost, [512]], 22 | [-1, 1, GhostConv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 1, SPP, [1024, [5, 9, 13]]], 24 | [-1, 3, C3Ghost, [1024, False]], # 9 25 | ] 26 | 27 | # YOLOv5 head 28 | head: 29 | [[-1, 1, GhostConv, [512, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 32 | [-1, 3, C3Ghost, [512, False]], # 13 33 | 34 | [-1, 1, GhostConv, [256, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 37 | [-1, 3, C3Ghost, [256, False]], # 17 (P3/8-small) 38 | 39 | [-1, 1, GhostConv, [256, 3, 2]], 40 | [[-1, 14], 1, Concat, [1]], # cat head P4 41 | [-1, 3, C3Ghost, [512, False]], # 20 (P4/16-medium) 42 | 43 | [-1, 1, GhostConv, [512, 3, 2]], 44 | [[-1, 10], 1, Concat, [1]], # cat head P5 45 | [-1, 3, C3Ghost, [1024, False]], # 23 (P5/32-large) 46 | 47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /models/hub/yolov5s-transformer.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2 16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, C3, [128]], 18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 19 | [-1, 9, C3, [256]], 20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, C3, [512]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 1, SPP, [1024, [5, 9, 13]]], 24 | [-1, 3, C3TR, [1024, False]], # 9 <-------- C3TR() Transformer module 25 | ] 26 | 27 | # YOLOv5 head 28 | head: 29 | [[-1, 1, Conv, [512, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 32 | [-1, 3, C3, [512, False]], # 13 33 | 34 | [-1, 1, Conv, [256, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 38 | 39 | [-1, 1, Conv, [256, 3, 2]], 40 | [[-1, 14], 1, Concat, [1]], # cat head P4 41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 42 | 43 | [-1, 1, Conv, [512, 3, 2]], 44 | [[-1, 10], 1, Concat, [1]], # cat head P5 45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 46 | 47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /models/hub/yolov5s6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [19,27, 44,40, 38,94] # P3/8 9 | - [96,68, 86,152, 180,137] # P4/16 10 | - [140,301, 303,264, 238,542] # P5/32 11 | - [436,615, 739,380, 925,792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [768]], 25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 26 | [-1, 3, C3, [1024]], 27 | [-1, 1, SPPF, [1024, 5]], # 11 28 | ] 29 | 30 | # YOLOv5 v6.0 head 31 | head: 32 | [[-1, 1, Conv, [768, 1, 1]], 33 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 34 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 35 | [-1, 3, C3, [768, False]], # 15 36 | 37 | [-1, 1, Conv, [512, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 39 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 40 | [-1, 3, C3, [512, False]], # 19 41 | 42 | [-1, 1, Conv, [256, 1, 1]], 43 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 44 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 45 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 46 | 47 | [-1, 1, Conv, [256, 3, 2]], 48 | [[-1, 20], 1, Concat, [1]], # cat head P4 49 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 50 | 51 | [-1, 1, Conv, [512, 3, 2]], 52 | [[-1, 16], 1, Concat, [1]], # cat head P5 53 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 54 | 55 | [-1, 1, Conv, [768, 3, 2]], 56 | [[-1, 12], 1, Concat, [1]], # cat head P6 57 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 58 | 59 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 60 | ] 61 | -------------------------------------------------------------------------------- /models/hub/yolov5x6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.33 # model depth multiple 6 | width_multiple: 1.25 # layer channel multiple 7 | anchors: 8 | - [19,27, 44,40, 38,94] # P3/8 9 | - [96,68, 86,152, 180,137] # P4/16 10 | - [140,301, 303,264, 238,542] # P5/32 11 | - [436,615, 739,380, 925,792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [768]], 25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 26 | [-1, 3, C3, [1024]], 27 | [-1, 1, SPPF, [1024, 5]], # 11 28 | ] 29 | 30 | # YOLOv5 v6.0 head 31 | head: 32 | [[-1, 1, Conv, [768, 1, 1]], 33 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 34 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 35 | [-1, 3, C3, [768, False]], # 15 36 | 37 | [-1, 1, Conv, [512, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 39 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 40 | [-1, 3, C3, [512, False]], # 19 41 | 42 | [-1, 1, Conv, [256, 1, 1]], 43 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 44 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 45 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 46 | 47 | [-1, 1, Conv, [256, 3, 2]], 48 | [[-1, 20], 1, Concat, [1]], # cat head P4 49 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 50 | 51 | [-1, 1, Conv, [512, 3, 2]], 52 | [[-1, 16], 1, Concat, [1]], # cat head P5 53 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 54 | 55 | [-1, 1, Conv, [768, 3, 2]], 56 | [[-1, 12], 1, Concat, [1]], # cat head P6 57 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 58 | 59 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 60 | ] 61 | -------------------------------------------------------------------------------- /models/yolov5l.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, C3, [128]], 18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 19 | [-1, 6, C3, [256]], 20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, C3, [512]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 3, C3, [1024]], 24 | [-1, 1, SPPF, [1024, 5]], # 9 25 | ] 26 | 27 | # YOLOv5 v6.0 head 28 | head: 29 | [[-1, 1, Conv, [512, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 32 | [-1, 3, C3, [512, False]], # 13 33 | 34 | [-1, 1, Conv, [256, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 38 | 39 | [-1, 1, Conv, [256, 3, 2]], 40 | [[-1, 14], 1, Concat, [1]], # cat head P4 41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 42 | 43 | [-1, 1, Conv, [512, 3, 2]], 44 | [[-1, 10], 1, Concat, [1]], # cat head P5 45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 46 | 47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /models/yolov5m.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, C3, [128]], 18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 19 | [-1, 6, C3, [256]], 20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, C3, [512]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 3, C3, [1024]], 24 | [-1, 1, SPPF, [1024, 5]], # 9 25 | ] 26 | 27 | # YOLOv5 v6.0 head 28 | head: 29 | [[-1, 1, Conv, [512, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 32 | [-1, 3, C3, [512, False]], # 13 33 | 34 | [-1, 1, Conv, [256, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 38 | 39 | [-1, 1, Conv, [256, 3, 2]], 40 | [[-1, 14], 1, Concat, [1]], # cat head P4 41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 42 | 43 | [-1, 1, Conv, [512, 3, 2]], 44 | [[-1, 10], 1, Concat, [1]], # cat head P5 45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 46 | 47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /models/yolov5n.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, C3, [128]], 18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 19 | [-1, 6, C3, [256]], 20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, C3, [512]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 3, C3, [1024]], 24 | [-1, 1, SPPF, [1024, 5]], # 9 25 | ] 26 | 27 | # YOLOv5 v6.0 head 28 | head: 29 | [[-1, 1, Conv, [512, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 32 | [-1, 3, C3, [512, False]], # 13 33 | 34 | [-1, 1, Conv, [256, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 38 | 39 | [-1, 1, Conv, [256, 3, 2]], 40 | [[-1, 14], 1, Concat, [1]], # cat head P4 41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 42 | 43 | [-1, 1, Conv, [512, 3, 2]], 44 | [[-1, 10], 1, Concat, [1]], # cat head P5 45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 46 | 47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /models/yolov5s.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, C3, [128]], 18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 19 | [-1, 6, C3, [256]], 20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, C3, [512]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 3, C3, [1024]], 24 | [-1, 1, SPPF, [1024, 5]], # 9 25 | ] 26 | 27 | # YOLOv5 v6.0 head 28 | head: 29 | [[-1, 1, Conv, [512, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 32 | [-1, 3, C3, [512, False]], # 13 33 | 34 | [-1, 1, Conv, [256, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 38 | 39 | [-1, 1, Conv, [256, 3, 2]], 40 | [[-1, 14], 1, Concat, [1]], # cat head P4 41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 42 | 43 | [-1, 1, Conv, [512, 3, 2]], 44 | [[-1, 10], 1, Concat, [1]], # cat head P5 45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 46 | 47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /models/yolov5x.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.33 # model depth multiple 6 | width_multiple: 1.25 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, C3, [128]], 18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 19 | [-1, 6, C3, [256]], 20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, C3, [512]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 3, C3, [1024]], 24 | [-1, 1, SPPF, [1024, 5]], # 9 25 | ] 26 | 27 | # YOLOv5 v6.0 head 28 | head: 29 | [[-1, 1, Conv, [512, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 32 | [-1, 3, C3, [512, False]], # 13 33 | 34 | [-1, 1, Conv, [256, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 38 | 39 | [-1, 1, Conv, [256, 3, 2]], 40 | [[-1, 14], 1, Concat, [1]], # cat head P4 41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 42 | 43 | [-1, 1, Conv, [512, 3, 2]], 44 | [[-1, 10], 1, Concat, [1]], # cat head P5 45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 46 | 47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /outputs/run.sh: -------------------------------------------------------------------------------- 1 | cd /home/gy/NSD/yolov5-6.0 && export Use_Double_Head=1 &&nohup python train.py \ 2 | --weights '' \ 3 | --device 3 \ 4 | --cfg /home/gy/NSD/yolov5-6.0/outputs/yolov5s.yaml \ 5 | > /home/gy/NSD/yolov5-6.0/outputs/yolov5s.out & -------------------------------------------------------------------------------- /outputs/yolov5s.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 2 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10,13, 16,30, 33,23] # P3/8 9 | - [30,61, 62,45, 59,119] # P4/16 10 | - [116,90, 156,198, 373,326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 17 | [-1, 3, C3, [128]], 18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 19 | [-1, 6, C3, [256]], 20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 21 | [-1, 9, C3, [512]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 23 | [-1, 3, C3, [1024]], 24 | [-1, 1, SPPF, [1024, 5]], # 9 25 | ] 26 | 27 | # YOLOv5 v6.0 head 28 | head: 29 | [[-1, 1, Conv, [512, 1, 1]], 30 | # 31 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | # 37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 38 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 39 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 40 | 41 | [-1, 1, Conv, [256, 3, 2]], 42 | # 43 | [[-1, 14], 1, Concat, [1]], # cat head P4 44 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 45 | 46 | [-1, 1, Conv, [512, 3, 2]], 47 | # 48 | [[-1, 10], 1, Concat, [1]], # cat head P5 49 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 50 | 51 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 52 | ] 53 | -------------------------------------------------------------------------------- /outputs/yolov5s/Double_Head+FocalLoss/hyp.yaml: -------------------------------------------------------------------------------- 1 | lr0: 0.01 2 | lrf: 0.1 3 | momentum: 0.937 4 | weight_decay: 0.0005 5 | warmup_epochs: 3.0 6 | warmup_momentum: 0.8 7 | warmup_bias_lr: 0.1 8 | box: 0.05 9 | obj: 1.0 10 | obj_pw: 1.0 11 | cls: 0.5 12 | cls_pw: 1.0 13 | degree: 0.9 14 | degree_pw: 1.0 15 | fl_gamma: 1.5 16 | iou_t: 0.2 17 | anchor_t: 4.0 18 | hsv_h: 0.015 19 | hsv_s: 0.7 20 | hsv_v: 0.4 21 | degrees: 0.0 22 | translate: 0.1 23 | scale: 0.5 24 | shear: 0.0 25 | perspective: 0.0 26 | flipud: 0.0 27 | fliplr: 0.0 28 | mosaic: 1.0 29 | mixup: 0.0 30 | copy_paste: 0.0 31 | -------------------------------------------------------------------------------- /outputs/yolov5s/Double_Head+FocalLoss/opt.yaml: -------------------------------------------------------------------------------- 1 | weights: '' 2 | cfg: /home/gy/NSD/yolov5-6.0/outputs/yolov5s.yaml 3 | data: /home/gy/NSD/yolov5-6.0/Rship.yaml 4 | hyp: /home/gy/NSD/yolov5-6.0/outputs/yolov5s/hyp.scratch.yaml 5 | epochs: 300 6 | batch_size: 8 7 | imgsz: 640 8 | rect: false 9 | resume: false 10 | nosave: false 11 | noval: false 12 | noautoanchor: false 13 | evolve: null 14 | bucket: '' 15 | cache: null 16 | image_weights: false 17 | device: 2,3 18 | multi_scale: false 19 | single_cls: false 20 | adam: false 21 | sync_bn: false 22 | workers: 8 23 | project: /home/gy/NSD/yolov5-6.0/outputs/yolov5s 24 | name: Double_Head.fl_gamma 25 | exist_ok: false 26 | quad: false 27 | linear_lr: false 28 | label_smoothing: 0.0 29 | patience: 100 30 | freeze: 0 31 | save_period: -1 32 | local_rank: -1 33 | entity: null 34 | upload_dataset: false 35 | bbox_interval: -1 36 | artifact_alias: latest 37 | save_dir: /home/gy/NSD/yolov5-6.0/outputs/yolov5s/Double_Head.fl_gamma 38 | -------------------------------------------------------------------------------- /outputs/yolov5s/hyp.scratch.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | # Hyperparameters for COCO training from scratch 3 | # python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 5 | 6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 7 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) 8 | momentum: 0.937 # SGD momentum/Adam beta1 9 | weight_decay: 0.0005 # optimizer weight decay 5e-4 10 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 11 | warmup_momentum: 0.8 # warmup initial momentum 12 | warmup_bias_lr: 0.1 # warmup initial bias lr 13 | 14 | box: 0.05 # box loss gain 15 | obj: 1.0 # obj loss gain (scale with pixels) 16 | obj_pw: 1.0 # obj BCELoss positive_weight 17 | cls: 0.5 # cls loss gain 18 | cls_pw: 1.0 # cls BCELoss positive_weight 19 | 20 | degree: 0.9 # cls loss gain 21 | degree_pw: 1.0 # degree BCELoss positive_weight 22 | 23 | fl_gamma: 1.5 # focal loss gamma (efficientDet default gamma=1.5) 24 | 25 | iou_t: 0.20 # IoU training threshold 26 | anchor_t: 4.0 # anchor-multiple threshold 27 | # anchors: 3 # anchors per output layer (0 to ignore) 28 | 29 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 30 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 31 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 32 | degrees: 0.0 # image rotation (+/- deg) 33 | translate: 0.1 # image translation (+/- fraction) 34 | scale: 0.5 # image scale (+/- gain) 35 | shear: 0.0 # image shear (+/- deg) 36 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 37 | flipud: 0.0 # image flip up-down (probability) 38 | fliplr: 0.0 # image flip left-right (probability) 39 | mosaic: 1.0 # image mosaic (probability) 40 | mixup: 0.0 # image mixup (probability) 41 | copy_paste: 0.0 # segment copy-paste (probability) 42 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # pip install -r requirements.txt 2 | 3 | # Base ---------------------------------------- 4 | matplotlib>=3.2.2 5 | numpy>=1.18.5 6 | opencv-python>=4.1.2 7 | Pillow>=7.1.2 8 | PyYAML>=5.3.1 9 | requests>=2.23.0 10 | scipy>=1.4.1 11 | torch>=1.7.0 12 | torchvision>=0.8.1 13 | tqdm>=4.41.0 14 | 15 | # Logging ------------------------------------- 16 | tensorboard>=2.4.1 17 | # wandb 18 | 19 | # Plotting ------------------------------------ 20 | pandas>=1.1.4 21 | seaborn>=0.11.0 22 | 23 | # Export -------------------------------------- 24 | # coremltools>=4.1 # CoreML export 25 | # onnx>=1.9.0 # ONNX export 26 | # onnx-simplifier>=0.3.6 # ONNX simplifier 27 | # scikit-learn==0.19.2 # CoreML quantization 28 | # tensorflow>=2.4.1 # TFLite export 29 | # tensorflowjs>=3.9.0 # TF.js export 30 | 31 | # Extras -------------------------------------- 32 | # albumentations>=1.0.3 33 | # Cython # for pycocotools https://github.com/cocodataset/cocoapi/issues/172 34 | # pycocotools>=2.0 # COCO mAP 35 | # roboflow 36 | thop # FLOPs computation 37 | -------------------------------------------------------------------------------- /utils/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /utils/activations.py: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | """ 3 | Activation functions 4 | """ 5 | 6 | import torch 7 | import torch.nn as nn 8 | import torch.nn.functional as F 9 | 10 | 11 | # SiLU https://arxiv.org/pdf/1606.08415.pdf ---------------------------------------------------------------------------- 12 | class SiLU(nn.Module): # export-friendly version of nn.SiLU() 13 | @staticmethod 14 | def forward(x): 15 | return x * torch.sigmoid(x) 16 | 17 | 18 | class Hardswish(nn.Module): # export-friendly version of nn.Hardswish() 19 | @staticmethod 20 | def forward(x): 21 | # return x * F.hardsigmoid(x) # for torchscript and CoreML 22 | return x * F.hardtanh(x + 3, 0., 6.) / 6. # for torchscript, CoreML and ONNX 23 | 24 | 25 | # Mish https://github.com/digantamisra98/Mish -------------------------------------------------------------------------- 26 | class Mish(nn.Module): 27 | @staticmethod 28 | def forward(x): 29 | return x * F.softplus(x).tanh() 30 | 31 | 32 | class MemoryEfficientMish(nn.Module): 33 | class F(torch.autograd.Function): 34 | @staticmethod 35 | def forward(ctx, x): 36 | ctx.save_for_backward(x) 37 | return x.mul(torch.tanh(F.softplus(x))) # x * tanh(ln(1 + exp(x))) 38 | 39 | @staticmethod 40 | def backward(ctx, grad_output): 41 | x = ctx.saved_tensors[0] 42 | sx = torch.sigmoid(x) 43 | fx = F.softplus(x).tanh() 44 | return grad_output * (fx + x * sx * (1 - fx * fx)) 45 | 46 | def forward(self, x): 47 | return self.F.apply(x) 48 | 49 | 50 | # FReLU https://arxiv.org/abs/2007.11824 ------------------------------------------------------------------------------- 51 | class FReLU(nn.Module): 52 | def __init__(self, c1, k=3): # ch_in, kernel 53 | super().__init__() 54 | self.conv = nn.Conv2d(c1, c1, k, 1, 1, groups=c1, bias=False) 55 | self.bn = nn.BatchNorm2d(c1) 56 | 57 | def forward(self, x): 58 | return torch.max(x, self.bn(self.conv(x))) 59 | 60 | 61 | # ACON https://arxiv.org/pdf/2009.04759.pdf ---------------------------------------------------------------------------- 62 | class AconC(nn.Module): 63 | r""" ACON activation (activate or not). 64 | AconC: (p1*x-p2*x) * sigmoid(beta*(p1*x-p2*x)) + p2*x, beta is a learnable parameter 65 | according to "Activate or Not: Learning Customized Activation" . 66 | """ 67 | 68 | def __init__(self, c1): 69 | super().__init__() 70 | self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1)) 71 | self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1)) 72 | self.beta = nn.Parameter(torch.ones(1, c1, 1, 1)) 73 | 74 | def forward(self, x): 75 | dpx = (self.p1 - self.p2) * x 76 | return dpx * torch.sigmoid(self.beta * dpx) + self.p2 * x 77 | 78 | 79 | class MetaAconC(nn.Module): 80 | r""" ACON activation (activate or not). 81 | MetaAconC: (p1*x-p2*x) * sigmoid(beta*(p1*x-p2*x)) + p2*x, beta is generated by a small network 82 | according to "Activate or Not: Learning Customized Activation" . 83 | """ 84 | 85 | def __init__(self, c1, k=1, s=1, r=16): # ch_in, kernel, stride, r 86 | super().__init__() 87 | c2 = max(r, c1 // r) 88 | self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1)) 89 | self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1)) 90 | self.fc1 = nn.Conv2d(c1, c2, k, s, bias=True) 91 | self.fc2 = nn.Conv2d(c2, c1, k, s, bias=True) 92 | # self.bn1 = nn.BatchNorm2d(c2) 93 | # self.bn2 = nn.BatchNorm2d(c1) 94 | 95 | def forward(self, x): 96 | y = x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True) 97 | # batch-size 1 bug/instabilities https://github.com/ultralytics/yolov5/issues/2891 98 | # beta = torch.sigmoid(self.bn2(self.fc2(self.bn1(self.fc1(y))))) # bug/unstable 99 | beta = torch.sigmoid(self.fc2(self.fc1(y))) # bug patch BN layers removed 100 | dpx = (self.p1 - self.p2) * x 101 | return dpx * torch.sigmoid(beta * dpx) + self.p2 * x 102 | -------------------------------------------------------------------------------- /utils/autoanchor.py: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | """ 3 | Auto-anchor utils 4 | """ 5 | 6 | import random 7 | 8 | import numpy as np 9 | import torch 10 | import yaml 11 | from tqdm import tqdm 12 | 13 | from utils.general import colorstr 14 | 15 | 16 | def check_anchor_order(m): 17 | # Check anchor order against stride order for YOLOv5 Detect() module m, and correct if necessary 18 | a = m.anchors.prod(-1).view(-1) # anchor area 19 | da = a[-1] - a[0] # delta a 20 | ds = m.stride[-1] - m.stride[0] # delta s 21 | if da.sign() != ds.sign(): # same order 22 | print('Reversing anchor order') 23 | m.anchors[:] = m.anchors.flip(0) 24 | 25 | 26 | def check_anchors(dataset, model, thr=4.0, imgsz=640): 27 | # Check anchor fit to data, recompute if necessary 28 | prefix = colorstr('autoanchor: ') 29 | print(f'\n{prefix}Analyzing anchors... ', end='') 30 | m = model.module.model[-1] if hasattr(model, 'module') else model.model[-1] # Detect() 31 | shapes = imgsz * dataset.shapes / dataset.shapes.max(1, keepdims=True) 32 | scale = np.random.uniform(0.9, 1.1, size=(shapes.shape[0], 1)) # augment scale 33 | wh = torch.tensor(np.concatenate([l[:, 3:5] * s for s, l in zip(shapes * scale, dataset.labels)])).float() # wh 34 | 35 | def metric(k): # compute metric 36 | r = wh[:, None] / k[None] 37 | x = torch.min(r, 1. / r).min(2)[0] # ratio metric 38 | best = x.max(1)[0] # best_x 39 | aat = (x > 1. / thr).float().sum(1).mean() # anchors above threshold 40 | bpr = (best > 1. / thr).float().mean() # best possible recall 41 | return bpr, aat 42 | 43 | anchors = m.anchors.clone() * m.stride.to(m.anchors.device).view(-1, 1, 1) # current anchors 44 | bpr, aat = metric(anchors.cpu().view(-1, 2)) 45 | print(f'anchors/target = {aat:.2f}, Best Possible Recall (BPR) = {bpr:.4f}', end='') 46 | if bpr < 0.98: # threshold to recompute 47 | print('. Attempting to improve anchors, please wait...') 48 | na = m.anchors.numel() // 2 # number of anchors 49 | try: 50 | anchors = kmean_anchors(dataset, n=na, img_size=imgsz, thr=thr, gen=1000, verbose=False) 51 | except Exception as e: 52 | print(f'{prefix}ERROR: {e}') 53 | new_bpr = metric(anchors)[0] 54 | if new_bpr > bpr: # replace anchors 55 | anchors = torch.tensor(anchors, device=m.anchors.device).type_as(m.anchors) 56 | m.anchors[:] = anchors.clone().view_as(m.anchors) / m.stride.to(m.anchors.device).view(-1, 1, 1) # loss 57 | check_anchor_order(m) 58 | print(f'{prefix}New anchors saved to model. Update model *.yaml to use these anchors in the future.') 59 | else: 60 | print(f'{prefix}Original anchors better than new anchors. Proceeding with original anchors.') 61 | print('') # newline 62 | 63 | 64 | def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen=1000, verbose=True): 65 | """ Creates kmeans-evolved anchors from training dataset 66 | 67 | Arguments: 68 | dataset: path to data.yaml, or a loaded dataset 69 | n: number of anchors 70 | img_size: image size used for training 71 | thr: anchor-label wh ratio threshold hyperparameter hyp['anchor_t'] used for training, default=4.0 72 | gen: generations to evolve anchors using genetic algorithm 73 | verbose: print all results 74 | 75 | Return: 76 | k: kmeans evolved anchors 77 | 78 | Usage: 79 | from utils.autoanchor import *; _ = kmean_anchors() 80 | """ 81 | from scipy.cluster.vq import kmeans 82 | 83 | thr = 1. / thr 84 | prefix = colorstr('autoanchor: ') 85 | 86 | def metric(k, wh): # compute metrics 87 | r = wh[:, None] / k[None] 88 | x = torch.min(r, 1. / r).min(2)[0] # ratio metric 89 | # x = wh_iou(wh, torch.tensor(k)) # iou metric 90 | return x, x.max(1)[0] # x, best_x 91 | 92 | def anchor_fitness(k): # mutation fitness 93 | _, best = metric(torch.tensor(k, dtype=torch.float32), wh) 94 | return (best * (best > thr).float()).mean() # fitness 95 | 96 | def print_results(k): 97 | k = k[np.argsort(k.prod(1))] # sort small to large 98 | x, best = metric(k, wh0) 99 | bpr, aat = (best > thr).float().mean(), (x > thr).float().mean() * n # best possible recall, anch > thr 100 | print(f'{prefix}thr={thr:.2f}: {bpr:.4f} best possible recall, {aat:.2f} anchors past thr') 101 | print(f'{prefix}n={n}, img_size={img_size}, metric_all={x.mean():.3f}/{best.mean():.3f}-mean/best, ' 102 | f'past_thr={x[x > thr].mean():.3f}-mean: ', end='') 103 | for i, x in enumerate(k): 104 | print('%i,%i' % (round(x[0]), round(x[1])), end=', ' if i < len(k) - 1 else '\n') # use in *.cfg 105 | return k 106 | 107 | if isinstance(dataset, str): # *.yaml file 108 | with open(dataset, errors='ignore') as f: 109 | data_dict = yaml.safe_load(f) # model dict 110 | from utils.datasets import LoadImagesAndLabels 111 | dataset = LoadImagesAndLabels(data_dict['train'], augment=True, rect=True) 112 | 113 | # Get label wh 114 | shapes = img_size * dataset.shapes / dataset.shapes.max(1, keepdims=True) 115 | wh0 = np.concatenate([l[:, 3:5] * s for s, l in zip(shapes, dataset.labels)]) # wh 116 | 117 | # Filter 118 | i = (wh0 < 3.0).any(1).sum() 119 | if i: 120 | print(f'{prefix}WARNING: Extremely small objects found. {i} of {len(wh0)} labels are < 3 pixels in size.') 121 | wh = wh0[(wh0 >= 2.0).any(1)] # filter > 2 pixels 122 | # wh = wh * (np.random.rand(wh.shape[0], 1) * 0.9 + 0.1) # multiply by random scale 0-1 123 | 124 | # Kmeans calculation 125 | print(f'{prefix}Running kmeans for {n} anchors on {len(wh)} points...') 126 | s = wh.std(0) # sigmas for whitening 127 | k, dist = kmeans(wh / s, n, iter=30) # points, mean distance 128 | assert len(k) == n, f'{prefix}ERROR: scipy.cluster.vq.kmeans requested {n} points but returned only {len(k)}' 129 | k *= s 130 | wh = torch.tensor(wh, dtype=torch.float32) # filtered 131 | wh0 = torch.tensor(wh0, dtype=torch.float32) # unfiltered 132 | k = print_results(k) 133 | 134 | # Plot 135 | # k, d = [None] * 20, [None] * 20 136 | # for i in tqdm(range(1, 21)): 137 | # k[i-1], d[i-1] = kmeans(wh / s, i) # points, mean distance 138 | # fig, ax = plt.subplots(1, 2, figsize=(14, 7), tight_layout=True) 139 | # ax = ax.ravel() 140 | # ax[0].plot(np.arange(1, 21), np.array(d) ** 2, marker='.') 141 | # fig, ax = plt.subplots(1, 2, figsize=(14, 7)) # plot wh 142 | # ax[0].hist(wh[wh[:, 0]<100, 0],400) 143 | # ax[1].hist(wh[wh[:, 1]<100, 1],400) 144 | # fig.savefig('wh.png', dpi=200) 145 | 146 | # Evolve 147 | npr = np.random 148 | f, sh, mp, s = anchor_fitness(k), k.shape, 0.9, 0.1 # fitness, generations, mutation prob, sigma 149 | pbar = tqdm(range(gen), desc=f'{prefix}Evolving anchors with Genetic Algorithm:') # progress bar 150 | for _ in pbar: 151 | v = np.ones(sh) 152 | while (v == 1).all(): # mutate until a change occurs (prevent duplicates) 153 | v = ((npr.random(sh) < mp) * random.random() * npr.randn(*sh) * s + 1).clip(0.3, 3.0) 154 | kg = (k.copy() * v).clip(min=2.0) 155 | fg = anchor_fitness(kg) 156 | if fg > f: 157 | f, k = fg, kg.copy() 158 | pbar.desc = f'{prefix}Evolving anchors with Genetic Algorithm: fitness = {f:.4f}' 159 | if verbose: 160 | print_results(k) 161 | 162 | return print_results(k) 163 | -------------------------------------------------------------------------------- /utils/aws/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/utils/aws/__init__.py -------------------------------------------------------------------------------- /utils/aws/mime.sh: -------------------------------------------------------------------------------- 1 | # AWS EC2 instance startup 'MIME' script https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/ 2 | # This script will run on every instance restart, not only on first start 3 | # --- DO NOT COPY ABOVE COMMENTS WHEN PASTING INTO USERDATA --- 4 | 5 | Content-Type: multipart/mixed; boundary="//" 6 | MIME-Version: 1.0 7 | 8 | --// 9 | Content-Type: text/cloud-config; charset="us-ascii" 10 | MIME-Version: 1.0 11 | Content-Transfer-Encoding: 7bit 12 | Content-Disposition: attachment; filename="cloud-config.txt" 13 | 14 | #cloud-config 15 | cloud_final_modules: 16 | - [scripts-user, always] 17 | 18 | --// 19 | Content-Type: text/x-shellscript; charset="us-ascii" 20 | MIME-Version: 1.0 21 | Content-Transfer-Encoding: 7bit 22 | Content-Disposition: attachment; filename="userdata.txt" 23 | 24 | #!/bin/bash 25 | # --- paste contents of userdata.sh here --- 26 | --// 27 | -------------------------------------------------------------------------------- /utils/aws/resume.py: -------------------------------------------------------------------------------- 1 | # Resume all interrupted trainings in yolov5/ dir including DDP trainings 2 | # Usage: $ python utils/aws/resume.py 3 | 4 | import os 5 | import sys 6 | from pathlib import Path 7 | 8 | import torch 9 | import yaml 10 | 11 | FILE = Path(__file__).resolve() 12 | ROOT = FILE.parents[2] # YOLOv5 root directory 13 | if str(ROOT) not in sys.path: 14 | sys.path.append(str(ROOT)) # add ROOT to PATH 15 | 16 | port = 0 # --master_port 17 | path = Path('').resolve() 18 | for last in path.rglob('*/**/last.pt'): 19 | ckpt = torch.load(last) 20 | if ckpt['optimizer'] is None: 21 | continue 22 | 23 | # Load opt.yaml 24 | with open(last.parent.parent / 'opt.yaml', errors='ignore') as f: 25 | opt = yaml.safe_load(f) 26 | 27 | # Get device count 28 | d = opt['device'].split(',') # devices 29 | nd = len(d) # number of devices 30 | ddp = nd > 1 or (nd == 0 and torch.cuda.device_count() > 1) # distributed data parallel 31 | 32 | if ddp: # multi-GPU 33 | port += 1 34 | cmd = f'python -m torch.distributed.run --nproc_per_node {nd} --master_port {port} train.py --resume {last}' 35 | else: # single-GPU 36 | cmd = f'python train.py --resume {last}' 37 | 38 | cmd += ' > /dev/null 2>&1 &' # redirect output to dev/null and run in daemon thread 39 | print(cmd) 40 | os.system(cmd) 41 | -------------------------------------------------------------------------------- /utils/aws/userdata.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # AWS EC2 instance startup script https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html 3 | # This script will run only once on first instance start (for a re-start script see mime.sh) 4 | # /home/ubuntu (ubuntu) or /home/ec2-user (amazon-linux) is working dir 5 | # Use >300 GB SSD 6 | 7 | cd home/ubuntu 8 | if [ ! -d yolov5 ]; then 9 | echo "Running first-time script." # install dependencies, download COCO, pull Docker 10 | git clone https://github.com/ultralytics/yolov5 -b master && sudo chmod -R 777 yolov5 11 | cd yolov5 12 | bash data/scripts/get_coco.sh && echo "COCO done." & 13 | sudo docker pull ultralytics/yolov5:latest && echo "Docker done." & 14 | python -m pip install --upgrade pip && pip install -r requirements.txt && python detect.py && echo "Requirements done." & 15 | wait && echo "All tasks done." # finish background tasks 16 | else 17 | echo "Running re-start script." # resume interrupted runs 18 | i=0 19 | list=$(sudo docker ps -qa) # container list i.e. $'one\ntwo\nthree\nfour' 20 | while IFS= read -r id; do 21 | ((i++)) 22 | echo "restarting container $i: $id" 23 | sudo docker start $id 24 | # sudo docker exec -it $id python train.py --resume # single-GPU 25 | sudo docker exec -d $id python utils/aws/resume.py # multi-scenario 26 | done <<<"$list" 27 | fi 28 | -------------------------------------------------------------------------------- /utils/callbacks.py: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | """ 3 | Callback utils 4 | """ 5 | 6 | 7 | class Callbacks: 8 | """" 9 | Handles all registered callbacks for YOLOv5 Hooks 10 | """ 11 | 12 | # Define the available callbacks 13 | _callbacks = { 14 | 'on_pretrain_routine_start': [], 15 | 'on_pretrain_routine_end': [], 16 | 17 | 'on_train_start': [], 18 | 'on_train_epoch_start': [], 19 | 'on_train_batch_start': [], 20 | 'optimizer_step': [], 21 | 'on_before_zero_grad': [], 22 | 'on_train_batch_end': [], 23 | 'on_train_epoch_end': [], 24 | 25 | 'on_val_start': [], 26 | 'on_val_batch_start': [], 27 | 'on_val_image_end': [], 28 | 'on_val_batch_end': [], 29 | 'on_val_end': [], 30 | 31 | 'on_fit_epoch_end': [], # fit = train + val 32 | 'on_model_save': [], 33 | 'on_train_end': [], 34 | 35 | 'teardown': [], 36 | } 37 | 38 | def register_action(self, hook, name='', callback=None): 39 | """ 40 | Register a new action to a callback hook 41 | 42 | Args: 43 | hook The callback hook name to register the action to 44 | name The name of the action for later reference 45 | callback The callback to fire 46 | """ 47 | assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}" 48 | assert callable(callback), f"callback '{callback}' is not callable" 49 | self._callbacks[hook].append({'name': name, 'callback': callback}) 50 | 51 | def get_registered_actions(self, hook=None): 52 | """" 53 | Returns all the registered actions by callback hook 54 | 55 | Args: 56 | hook The name of the hook to check, defaults to all 57 | """ 58 | if hook: 59 | return self._callbacks[hook] 60 | else: 61 | return self._callbacks 62 | 63 | def run(self, hook, *args, **kwargs): 64 | """ 65 | Loop through the registered actions and fire all callbacks 66 | 67 | Args: 68 | hook The name of the hook to check, defaults to all 69 | args Arguments to receive from YOLOv5 70 | kwargs Keyword Arguments to receive from YOLOv5 71 | """ 72 | 73 | assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}" 74 | 75 | for logger in self._callbacks[hook]: 76 | logger['callback'](*args, **kwargs) -------------------------------------------------------------------------------- /utils/downloads.py: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | """ 3 | Download utils 4 | """ 5 | 6 | import os 7 | import platform 8 | import subprocess 9 | import time 10 | import urllib 11 | from pathlib import Path 12 | from zipfile import ZipFile 13 | 14 | import requests 15 | import torch 16 | 17 | 18 | def gsutil_getsize(url=''): 19 | # gs://bucket/file size https://cloud.google.com/storage/docs/gsutil/commands/du 20 | s = subprocess.check_output(f'gsutil du {url}', shell=True).decode('utf-8') 21 | return eval(s.split(' ')[0]) if len(s) else 0 # bytes 22 | 23 | 24 | def safe_download(file, url, url2=None, min_bytes=1E0, error_msg=''): 25 | # Attempts to download file from url or url2, checks and removes incomplete downloads < min_bytes 26 | file = Path(file) 27 | assert_msg = f"Downloaded file '{file}' does not exist or size is < min_bytes={min_bytes}" 28 | try: # url1 29 | print(f'Downloading {url} to {file}...') 30 | torch.hub.download_url_to_file(url, str(file)) 31 | assert file.exists() and file.stat().st_size > min_bytes, assert_msg # check 32 | except Exception as e: # url2 33 | file.unlink(missing_ok=True) # remove partial downloads 34 | print(f'ERROR: {e}\nRe-attempting {url2 or url} to {file}...') 35 | os.system(f"curl -L '{url2 or url}' -o '{file}' --retry 3 -C -") # curl download, retry and resume on fail 36 | finally: 37 | if not file.exists() or file.stat().st_size < min_bytes: # check 38 | file.unlink(missing_ok=True) # remove partial downloads 39 | print(f"ERROR: {assert_msg}\n{error_msg}") 40 | print('') 41 | 42 | 43 | def attempt_download(file, repo='ultralytics/yolov5'): # from utils.downloads import *; attempt_download() 44 | # Attempt file download if does not exist 45 | file = Path(str(file).strip().replace("'", '')) 46 | 47 | if not file.exists(): 48 | # URL specified 49 | name = Path(urllib.parse.unquote(str(file))).name # decode '%2F' to '/' etc. 50 | if str(file).startswith(('http:/', 'https:/')): # download 51 | url = str(file).replace(':/', '://') # Pathlib turns :// -> :/ 52 | name = name.split('?')[0] # parse authentication https://url.com/file.txt?auth... 53 | safe_download(file=name, url=url, min_bytes=1E5) 54 | return name 55 | 56 | # GitHub assets 57 | file.parent.mkdir(parents=True, exist_ok=True) # make parent dir (if required) 58 | try: 59 | response = requests.get(f'https://api.github.com/repos/{repo}/releases/latest').json() # github api 60 | assets = [x['name'] for x in response['assets']] # release assets, i.e. ['yolov5s.pt', 'yolov5m.pt', ...] 61 | tag = response['tag_name'] # i.e. 'v1.0' 62 | except: # fallback plan 63 | assets = ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 64 | 'yolov5s6.pt', 'yolov5m6.pt', 'yolov5l6.pt', 'yolov5x6.pt'] 65 | try: 66 | tag = subprocess.check_output('git tag', shell=True, stderr=subprocess.STDOUT).decode().split()[-1] 67 | except: 68 | tag = 'v5.0' # current release 69 | 70 | if name in assets: 71 | safe_download(file, 72 | url=f'https://github.com/{repo}/releases/download/{tag}/{name}', 73 | # url2=f'https://storage.googleapis.com/{repo}/ckpt/{name}', # backup url (optional) 74 | min_bytes=1E5, 75 | error_msg=f'{file} missing, try downloading from https://github.com/{repo}/releases/') 76 | 77 | return str(file) 78 | 79 | 80 | def gdrive_download(id='16TiPfZj7htmTyhntwcZyEEAejOUxuT6m', file='tmp.zip'): 81 | # Downloads a file from Google Drive. from yolov5.utils.downloads import *; gdrive_download() 82 | t = time.time() 83 | file = Path(file) 84 | cookie = Path('cookie') # gdrive cookie 85 | print(f'Downloading https://drive.google.com/uc?export=download&id={id} as {file}... ', end='') 86 | file.unlink(missing_ok=True) # remove existing file 87 | cookie.unlink(missing_ok=True) # remove existing cookie 88 | 89 | # Attempt file download 90 | out = "NUL" if platform.system() == "Windows" else "/dev/null" 91 | os.system(f'curl -c ./cookie -s -L "drive.google.com/uc?export=download&id={id}" > {out}') 92 | if os.path.exists('cookie'): # large file 93 | s = f'curl -Lb ./cookie "drive.google.com/uc?export=download&confirm={get_token()}&id={id}" -o {file}' 94 | else: # small file 95 | s = f'curl -s -L -o {file} "drive.google.com/uc?export=download&id={id}"' 96 | r = os.system(s) # execute, capture return 97 | cookie.unlink(missing_ok=True) # remove existing cookie 98 | 99 | # Error check 100 | if r != 0: 101 | file.unlink(missing_ok=True) # remove partial 102 | print('Download error ') # raise Exception('Download error') 103 | return r 104 | 105 | # Unzip if archive 106 | if file.suffix == '.zip': 107 | print('unzipping... ', end='') 108 | ZipFile(file).extractall(path=file.parent) # unzip 109 | file.unlink() # remove zip 110 | 111 | print(f'Done ({time.time() - t:.1f}s)') 112 | return r 113 | 114 | 115 | def get_token(cookie="./cookie"): 116 | with open(cookie) as f: 117 | for line in f: 118 | if "download" in line: 119 | return line.split()[-1] 120 | return "" 121 | 122 | # Google utils: https://cloud.google.com/storage/docs/reference/libraries ---------------------------------------------- 123 | # 124 | # 125 | # def upload_blob(bucket_name, source_file_name, destination_blob_name): 126 | # # Uploads a file to a bucket 127 | # # https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-python 128 | # 129 | # storage_client = storage.Client() 130 | # bucket = storage_client.get_bucket(bucket_name) 131 | # blob = bucket.blob(destination_blob_name) 132 | # 133 | # blob.upload_from_filename(source_file_name) 134 | # 135 | # print('File {} uploaded to {}.'.format( 136 | # source_file_name, 137 | # destination_blob_name)) 138 | # 139 | # 140 | # def download_blob(bucket_name, source_blob_name, destination_file_name): 141 | # # Uploads a blob from a bucket 142 | # storage_client = storage.Client() 143 | # bucket = storage_client.get_bucket(bucket_name) 144 | # blob = bucket.blob(source_blob_name) 145 | # 146 | # blob.download_to_filename(destination_file_name) 147 | # 148 | # print('Blob {} downloaded to {}.'.format( 149 | # source_blob_name, 150 | # destination_file_name)) 151 | -------------------------------------------------------------------------------- /utils/flask_rest_api/README.md: -------------------------------------------------------------------------------- 1 | # Flask REST API 2 | 3 | [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) [API](https://en.wikipedia.org/wiki/API)s are 4 | commonly used to expose Machine Learning (ML) models to other services. This folder contains an example REST API 5 | created using Flask to expose the YOLOv5s model from [PyTorch Hub](https://pytorch.org/hub/ultralytics_yolov5/). 6 | 7 | ## Requirements 8 | 9 | [Flask](https://palletsprojects.com/p/flask/) is required. Install with: 10 | 11 | ```shell 12 | $ pip install Flask 13 | ``` 14 | 15 | ## Run 16 | 17 | After Flask installation run: 18 | 19 | ```shell 20 | $ python3 restapi.py --port 5000 21 | ``` 22 | 23 | Then use [curl](https://curl.se/) to perform a request: 24 | 25 | ```shell 26 | $ curl -X POST -F image=@zidane.jpg 'http://localhost:5000/v1/object-detection/yolov5s' 27 | ``` 28 | 29 | The model inference results are returned as a JSON response: 30 | 31 | ```json 32 | [ 33 | { 34 | "class": 0, 35 | "confidence": 0.8900438547, 36 | "height": 0.9318675399, 37 | "name": "person", 38 | "width": 0.3264600933, 39 | "xcenter": 0.7438579798, 40 | "ycenter": 0.5207948685 41 | }, 42 | { 43 | "class": 0, 44 | "confidence": 0.8440024257, 45 | "height": 0.7155083418, 46 | "name": "person", 47 | "width": 0.6546785235, 48 | "xcenter": 0.427829951, 49 | "ycenter": 0.6334488392 50 | }, 51 | { 52 | "class": 27, 53 | "confidence": 0.3771208823, 54 | "height": 0.3902671337, 55 | "name": "tie", 56 | "width": 0.0696444362, 57 | "xcenter": 0.3675483763, 58 | "ycenter": 0.7991207838 59 | }, 60 | { 61 | "class": 27, 62 | "confidence": 0.3527112305, 63 | "height": 0.1540903747, 64 | "name": "tie", 65 | "width": 0.0336618312, 66 | "xcenter": 0.7814827561, 67 | "ycenter": 0.5065554976 68 | } 69 | ] 70 | ``` 71 | 72 | An example python script to perform inference using [requests](https://docs.python-requests.org/en/master/) is given 73 | in `example_request.py` 74 | -------------------------------------------------------------------------------- /utils/flask_rest_api/example_request.py: -------------------------------------------------------------------------------- 1 | """Perform test request""" 2 | import pprint 3 | 4 | import requests 5 | 6 | DETECTION_URL = "http://localhost:5000/v1/object-detection/yolov5s" 7 | TEST_IMAGE = "zidane.jpg" 8 | 9 | image_data = open(TEST_IMAGE, "rb").read() 10 | 11 | response = requests.post(DETECTION_URL, files={"image": image_data}).json() 12 | 13 | pprint.pprint(response) 14 | -------------------------------------------------------------------------------- /utils/flask_rest_api/restapi.py: -------------------------------------------------------------------------------- 1 | """ 2 | Run a rest API exposing the yolov5s object detection model 3 | """ 4 | import argparse 5 | import io 6 | 7 | import torch 8 | from PIL import Image 9 | from flask import Flask, request 10 | 11 | app = Flask(__name__) 12 | 13 | DETECTION_URL = "/v1/object-detection/yolov5s" 14 | 15 | 16 | @app.route(DETECTION_URL, methods=["POST"]) 17 | def predict(): 18 | if not request.method == "POST": 19 | return 20 | 21 | if request.files.get("image"): 22 | image_file = request.files["image"] 23 | image_bytes = image_file.read() 24 | 25 | img = Image.open(io.BytesIO(image_bytes)) 26 | 27 | results = model(img, size=640) # reduce size=320 for faster inference 28 | return results.pandas().xyxy[0].to_json(orient="records") 29 | 30 | 31 | if __name__ == "__main__": 32 | parser = argparse.ArgumentParser(description="Flask API exposing YOLOv5 model") 33 | parser.add_argument("--port", default=5000, type=int, help="port number") 34 | args = parser.parse_args() 35 | 36 | model = torch.hub.load("ultralytics/yolov5", "yolov5s", force_reload=True) # force_reload to recache 37 | app.run(host="0.0.0.0", port=args.port) # debug=True causes Restarting with stat 38 | -------------------------------------------------------------------------------- /utils/google_app_engine/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gcr.io/google-appengine/python 2 | 3 | # Create a virtualenv for dependencies. This isolates these packages from 4 | # system-level packages. 5 | # Use -p python3 or -p python3.7 to select python version. Default is version 2. 6 | RUN virtualenv /env -p python3 7 | 8 | # Setting these environment variables are the same as running 9 | # source /env/bin/activate. 10 | ENV VIRTUAL_ENV /env 11 | ENV PATH /env/bin:$PATH 12 | 13 | RUN apt-get update && apt-get install -y python-opencv 14 | 15 | # Copy the application's requirements.txt and run pip to install all 16 | # dependencies into the virtualenv. 17 | ADD requirements.txt /app/requirements.txt 18 | RUN pip install -r /app/requirements.txt 19 | 20 | # Add the application source code. 21 | ADD . /app 22 | 23 | # Run a WSGI server to serve the application. gunicorn must be declared as 24 | # a dependency in requirements.txt. 25 | CMD gunicorn -b :$PORT main:app 26 | -------------------------------------------------------------------------------- /utils/google_app_engine/additional_requirements.txt: -------------------------------------------------------------------------------- 1 | # add these requirements in your app on top of the existing ones 2 | pip==19.2 3 | Flask==1.0.2 4 | gunicorn==19.9.0 5 | -------------------------------------------------------------------------------- /utils/google_app_engine/app.yaml: -------------------------------------------------------------------------------- 1 | runtime: custom 2 | env: flex 3 | 4 | service: yolov5app 5 | 6 | liveness_check: 7 | initial_delay_sec: 600 8 | 9 | manual_scaling: 10 | instances: 1 11 | resources: 12 | cpu: 1 13 | memory_gb: 4 14 | disk_size_gb: 20 -------------------------------------------------------------------------------- /utils/loggers/__init__.py: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license 2 | """ 3 | Logging utils 4 | """ 5 | 6 | import warnings 7 | from threading import Thread 8 | 9 | import torch 10 | from torch.utils.tensorboard import SummaryWriter 11 | 12 | from utils.general import colorstr, emojis 13 | from utils.loggers.wandb.wandb_utils import WandbLogger 14 | from utils.plots import plot_images, plot_results 15 | from utils.torch_utils import de_parallel 16 | 17 | LOGGERS = ('csv', 'tb', 'wandb') # text-file, TensorBoard, Weights & Biases 18 | 19 | try: 20 | import wandb 21 | 22 | assert hasattr(wandb, '__version__') # verify package import not local dir 23 | except (ImportError, AssertionError): 24 | wandb = None 25 | 26 | 27 | class Loggers(): 28 | # YOLOv5 Loggers class 29 | def __init__(self, save_dir=None, weights=None, opt=None, hyp=None, logger=None, include=LOGGERS): 30 | self.save_dir = save_dir 31 | self.weights = weights 32 | self.opt = opt 33 | self.hyp = hyp 34 | self.logger = logger # for printing results to console 35 | self.include = include 36 | self.keys = ['train/box_loss', 'train/obj_loss', 'train/cls_loss', # train loss 37 | 'metrics/precision', 'metrics/recall', 'metrics/mAP_0.5', 'metrics/mAP_0.5:0.95', # metrics 38 | 'val/box_loss', 'val/obj_loss', 'val/cls_loss', # val loss 39 | 'x/lr0', 'x/lr1', 'x/lr2'] # params 40 | for k in LOGGERS: 41 | setattr(self, k, None) # init empty logger dictionary 42 | self.csv = True # always log to csv 43 | 44 | # Message 45 | if not wandb: 46 | prefix = colorstr('Weights & Biases: ') 47 | s = f"{prefix}run 'pip install wandb' to automatically track and visualize YOLOv5 🚀 runs (RECOMMENDED)" 48 | print(emojis(s)) 49 | 50 | # TensorBoard 51 | s = self.save_dir 52 | if 'tb' in self.include and not self.opt.evolve: 53 | prefix = colorstr('TensorBoard: ') 54 | self.logger.info(f"{prefix}Start with 'tensorboard --logdir {s.parent}', view at http://localhost:6006/") 55 | self.tb = SummaryWriter(str(s)) 56 | 57 | # W&B 58 | if wandb and 'wandb' in self.include: 59 | wandb_artifact_resume = isinstance(self.opt.resume, str) and self.opt.resume.startswith('wandb-artifact://') 60 | run_id = torch.load(self.weights).get('wandb_id') if self.opt.resume and not wandb_artifact_resume else None 61 | self.opt.hyp = self.hyp # add hyperparameters 62 | self.wandb = WandbLogger(self.opt, run_id) 63 | else: 64 | self.wandb = None 65 | 66 | def on_pretrain_routine_end(self): 67 | # Callback runs on pre-train routine end 68 | paths = self.save_dir.glob('*labels*.jpg') # training labels 69 | if self.wandb: 70 | self.wandb.log({"Labels": [wandb.Image(str(x), caption=x.name) for x in paths]}) 71 | 72 | def on_train_batch_end(self, ni, model, imgs, targets, paths, plots, sync_bn): 73 | # Callback runs on train batch end 74 | if plots: 75 | if ni == 0: 76 | if not sync_bn: # tb.add_graph() --sync known issue https://github.com/ultralytics/yolov5/issues/3754 77 | with warnings.catch_warnings(): 78 | warnings.simplefilter('ignore') # suppress jit trace warning 79 | self.tb.add_graph(torch.jit.trace(de_parallel(model), imgs[0:1], strict=False), []) 80 | if ni < 3: 81 | f = self.save_dir / f'train_batch{ni}.jpg' # filename 82 | Thread(target=plot_images, args=(imgs, targets, paths, f), daemon=True).start() 83 | if self.wandb and ni == 10: 84 | files = sorted(self.save_dir.glob('train*.jpg')) 85 | self.wandb.log({'Mosaics': [wandb.Image(str(f), caption=f.name) for f in files if f.exists()]}) 86 | 87 | def on_train_epoch_end(self, epoch): 88 | # Callback runs on train epoch end 89 | if self.wandb: 90 | self.wandb.current_epoch = epoch + 1 91 | 92 | def on_val_image_end(self, pred, predn, path, names, im): 93 | # Callback runs on val image end 94 | if self.wandb: 95 | self.wandb.val_one_image(pred, predn, path, names, im) 96 | 97 | def on_val_end(self): 98 | # Callback runs on val end 99 | if self.wandb: 100 | files = sorted(self.save_dir.glob('val*.jpg')) 101 | self.wandb.log({"Validation": [wandb.Image(str(f), caption=f.name) for f in files]}) 102 | 103 | def on_fit_epoch_end(self, vals, epoch, best_fitness, fi): 104 | # Callback runs at the end of each fit (train+val) epoch 105 | x = {k: v for k, v in zip(self.keys, vals)} # dict 106 | if self.csv: 107 | file = self.save_dir / 'results.csv' 108 | n = len(x) + 1 # number of cols 109 | s = '' if file.exists() else (('%20s,' * n % tuple(['epoch'] + self.keys)).rstrip(',') + '\n') # add header 110 | with open(file, 'a') as f: 111 | f.write(s + ('%20.5g,' * n % tuple([epoch] + vals)).rstrip(',') + '\n') 112 | 113 | if self.tb: 114 | for k, v in x.items(): 115 | self.tb.add_scalar(k, v, epoch) 116 | 117 | if self.wandb: 118 | self.wandb.log(x) 119 | self.wandb.end_epoch(best_result=best_fitness == fi) 120 | 121 | def on_model_save(self, last, epoch, final_epoch, best_fitness, fi): 122 | # Callback runs on model save event 123 | if self.wandb: 124 | if ((epoch + 1) % self.opt.save_period == 0 and not final_epoch) and self.opt.save_period != -1: 125 | self.wandb.log_model(last.parent, self.opt, epoch, fi, best_model=best_fitness == fi) 126 | 127 | def on_train_end(self, last, best, plots, epoch): 128 | # Callback runs on training end 129 | if plots: 130 | plot_results(file=self.save_dir / 'results.csv') # save results.png 131 | files = ['results.png', 'confusion_matrix.png', *[f'{x}_curve.png' for x in ('F1', 'PR', 'P', 'R')]] 132 | files = [(self.save_dir / f) for f in files if (self.save_dir / f).exists()] # filter 133 | 134 | if self.tb: 135 | import cv2 136 | for f in files: 137 | self.tb.add_image(f.stem, cv2.imread(str(f))[..., ::-1], epoch, dataformats='HWC') 138 | 139 | if self.wandb: 140 | self.wandb.log({"Results": [wandb.Image(str(f), caption=f.name) for f in files]}) 141 | # Calling wandb.log. TODO: Refactor this into WandbLogger.log_model 142 | if not self.opt.evolve: 143 | wandb.log_artifact(str(best if best.exists() else last), type='model', 144 | name='run_' + self.wandb.wandb_run.id + '_model', 145 | aliases=['latest', 'best', 'stripped']) 146 | self.wandb.finish_run() 147 | else: 148 | self.wandb.finish_run() 149 | self.wandb = WandbLogger(self.opt) 150 | -------------------------------------------------------------------------------- /utils/loggers/wandb/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/utils/loggers/wandb/__init__.py -------------------------------------------------------------------------------- /utils/loggers/wandb/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/utils/loggers/wandb/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /utils/loggers/wandb/__pycache__/wandb_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-keys/yolov5-6.0-RetinaNet-MultiLabel/f7a1bc5cf4e47aa3ba42dfa611327cbc0e20da17/utils/loggers/wandb/__pycache__/wandb_utils.cpython-37.pyc -------------------------------------------------------------------------------- /utils/loggers/wandb/log_dataset.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | from wandb_utils import WandbLogger 4 | 5 | WANDB_ARTIFACT_PREFIX = 'wandb-artifact://' 6 | 7 | 8 | def create_dataset_artifact(opt): 9 | logger = WandbLogger(opt, None, job_type='Dataset Creation') # TODO: return value unused 10 | 11 | 12 | if __name__ == '__main__': 13 | parser = argparse.ArgumentParser() 14 | parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path') 15 | parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset') 16 | parser.add_argument('--project', type=str, default='YOLOv5', help='name of W&B Project') 17 | parser.add_argument('--entity', default=None, help='W&B entity') 18 | parser.add_argument('--name', type=str, default='log dataset', help='name of W&B run') 19 | 20 | opt = parser.parse_args() 21 | opt.resume = False # Explicitly disallow resume check for dataset upload job 22 | 23 | create_dataset_artifact(opt) 24 | -------------------------------------------------------------------------------- /utils/loggers/wandb/sweep.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from pathlib import Path 3 | 4 | import wandb 5 | 6 | FILE = Path(__file__).resolve() 7 | ROOT = FILE.parents[3] # YOLOv5 root directory 8 | if str(ROOT) not in sys.path: 9 | sys.path.append(str(ROOT)) # add ROOT to PATH 10 | 11 | from train import train, parse_opt 12 | from utils.general import increment_path 13 | from utils.torch_utils import select_device 14 | from utils.callbacks import Callbacks 15 | 16 | 17 | def sweep(): 18 | wandb.init() 19 | # Get hyp dict from sweep agent 20 | hyp_dict = vars(wandb.config).get("_items") 21 | 22 | # Workaround: get necessary opt args 23 | opt = parse_opt(known=True) 24 | opt.batch_size = hyp_dict.get("batch_size") 25 | opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok or opt.evolve)) 26 | opt.epochs = hyp_dict.get("epochs") 27 | opt.nosave = True 28 | opt.data = hyp_dict.get("data") 29 | device = select_device(opt.device, batch_size=opt.batch_size) 30 | 31 | # train 32 | train(hyp_dict, opt, device, callbacks=Callbacks()) 33 | 34 | 35 | if __name__ == "__main__": 36 | sweep() 37 | -------------------------------------------------------------------------------- /utils/loggers/wandb/sweep.yaml: -------------------------------------------------------------------------------- 1 | # Hyperparameters for training 2 | # To set range- 3 | # Provide min and max values as: 4 | # parameter: 5 | # 6 | # min: scalar 7 | # max: scalar 8 | # OR 9 | # 10 | # Set a specific list of search space- 11 | # parameter: 12 | # values: [scalar1, scalar2, scalar3...] 13 | # 14 | # You can use grid, bayesian and hyperopt search strategy 15 | # For more info on configuring sweeps visit - https://docs.wandb.ai/guides/sweeps/configuration 16 | 17 | program: utils/loggers/wandb/sweep.py 18 | method: random 19 | metric: 20 | name: metrics/mAP_0.5 21 | goal: maximize 22 | 23 | parameters: 24 | # hyperparameters: set either min, max range or values list 25 | data: 26 | value: "data/coco128.yaml" 27 | batch_size: 28 | values: [64] 29 | epochs: 30 | values: [10] 31 | 32 | lr0: 33 | distribution: uniform 34 | min: 1e-5 35 | max: 1e-1 36 | lrf: 37 | distribution: uniform 38 | min: 0.01 39 | max: 1.0 40 | momentum: 41 | distribution: uniform 42 | min: 0.6 43 | max: 0.98 44 | weight_decay: 45 | distribution: uniform 46 | min: 0.0 47 | max: 0.001 48 | warmup_epochs: 49 | distribution: uniform 50 | min: 0.0 51 | max: 5.0 52 | warmup_momentum: 53 | distribution: uniform 54 | min: 0.0 55 | max: 0.95 56 | warmup_bias_lr: 57 | distribution: uniform 58 | min: 0.0 59 | max: 0.2 60 | box: 61 | distribution: uniform 62 | min: 0.02 63 | max: 0.2 64 | cls: 65 | distribution: uniform 66 | min: 0.2 67 | max: 4.0 68 | cls_pw: 69 | distribution: uniform 70 | min: 0.5 71 | max: 2.0 72 | obj: 73 | distribution: uniform 74 | min: 0.2 75 | max: 4.0 76 | obj_pw: 77 | distribution: uniform 78 | min: 0.5 79 | max: 2.0 80 | iou_t: 81 | distribution: uniform 82 | min: 0.1 83 | max: 0.7 84 | anchor_t: 85 | distribution: uniform 86 | min: 2.0 87 | max: 8.0 88 | fl_gamma: 89 | distribution: uniform 90 | min: 0.0 91 | max: 0.1 92 | hsv_h: 93 | distribution: uniform 94 | min: 0.0 95 | max: 0.1 96 | hsv_s: 97 | distribution: uniform 98 | min: 0.0 99 | max: 0.9 100 | hsv_v: 101 | distribution: uniform 102 | min: 0.0 103 | max: 0.9 104 | degrees: 105 | distribution: uniform 106 | min: 0.0 107 | max: 45.0 108 | translate: 109 | distribution: uniform 110 | min: 0.0 111 | max: 0.9 112 | scale: 113 | distribution: uniform 114 | min: 0.0 115 | max: 0.9 116 | shear: 117 | distribution: uniform 118 | min: 0.0 119 | max: 10.0 120 | perspective: 121 | distribution: uniform 122 | min: 0.0 123 | max: 0.001 124 | flipud: 125 | distribution: uniform 126 | min: 0.0 127 | max: 1.0 128 | fliplr: 129 | distribution: uniform 130 | min: 0.0 131 | max: 1.0 132 | mosaic: 133 | distribution: uniform 134 | min: 0.0 135 | max: 1.0 136 | mixup: 137 | distribution: uniform 138 | min: 0.0 139 | max: 1.0 140 | copy_paste: 141 | distribution: uniform 142 | min: 0.0 143 | max: 1.0 144 | --------------------------------------------------------------------------------