Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit f3e65de

Browse files
authored
Add YOLOv5 data and model directories (#859) (#868)
1 parent fe6826b commit f3e65de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2318
-6
lines changed

src/sparseml/utils/helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import os
2525
import sys
2626
from collections import OrderedDict
27+
from pathlib import Path
2728
from typing import Any, Callable, Dict, Iterable, List, Tuple, Union
2829
from urllib.parse import urlparse
2930

@@ -38,6 +39,7 @@
3839
"FROM_PARAM_TOKEN",
3940
"RECIPE_METADATA_KEY",
4041
"FRAMEWORK_METADATA_KEY",
42+
"ROOT_PATH",
4143
"flatten_iterable",
4244
"convert_to_bool",
4345
"validate_str_iterable",
@@ -70,6 +72,7 @@
7072
FROM_PARAM_TOKEN = "__FROM_PARAM__"
7173
RECIPE_METADATA_KEY = "__metadata__"
7274
FRAMEWORK_METADATA_KEY = "framework_metadata"
75+
ROOT_PATH = Path(__file__).resolve().parents[3]
7376
_LOGGER = logging.getLogger(__name__)
7477

7578

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2+
# Argoverse-HD dataset (ring-front-center camera) http://www.cs.cmu.edu/~mengtial/proj/streaming/ by Argo AI
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
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2+
# Global Wheat 2020 dataset http://www.global-wheat.com/ by University of Saskatchewan
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+
38+
# Download
39+
dir = Path(yaml['path']) # dataset root dir
40+
urls = ['https://zenodo.org/record/4298502/files/global-wheat-codalab-official.zip',
41+
'https://github.com/ultralytics/yolov5/releases/download/v1.0/GlobalWheat2020_labels.zip']
42+
download(urls, dir=dir)
43+
44+
# Make Directories
45+
for p in 'annotations', 'images', 'labels':
46+
(dir / p).mkdir(parents=True, exist_ok=True)
47+
48+
# Move
49+
for p in 'arvalis_1', 'arvalis_2', 'arvalis_3', 'ethz_1', 'rres_1', 'inrae_1', 'usask_1', \
50+
'utokyo_1', 'utokyo_2', 'nau_1', 'uq_1':
51+
(dir / p).rename(dir / 'images' / p) # move to /images
52+
f = (dir / p).with_suffix('.json') # json file
53+
if f.exists():
54+
f.rename((dir / 'annotations' / p).with_suffix('.json')) # move to /annotations
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2+
# Objects365 dataset https://www.objects365.org/ by Megvii
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') 80000 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 Path, download, np, xyxy2xywhn
67+
68+
69+
# Make Directories
70+
dir = Path(yaml['path']) # dataset root dir
71+
for p in 'images', 'labels':
72+
(dir / p).mkdir(parents=True, exist_ok=True)
73+
for q in 'train', 'val':
74+
(dir / p / q).mkdir(parents=True, exist_ok=True)
75+
76+
# Train, Val Splits
77+
for split, patches in [('train', 50 + 1), ('val', 43 + 1)]:
78+
print(f"Processing {split} in {patches} patches ...")
79+
images, labels = dir / 'images' / split, dir / 'labels' / split
80+
81+
# Download
82+
url = f"https://dorc.ks3-cn-beijing.ksyun.com/data-set/2020Objects365%E6%95%B0%E6%8D%AE%E9%9B%86/{split}/"
83+
if split == 'train':
84+
download([f'{url}zhiyuan_objv2_{split}.tar.gz'], dir=dir, delete=False) # annotations json
85+
download([f'{url}patch{i}.tar.gz' for i in range(patches)], dir=images, curl=True, delete=False, threads=8)
86+
elif split == 'val':
87+
download([f'{url}zhiyuan_objv2_{split}.json'], dir=dir, delete=False) # annotations json
88+
download([f'{url}images/v1/patch{i}.tar.gz' for i in range(15 + 1)], dir=images, curl=True, delete=False, threads=8)
89+
download([f'{url}images/v2/patch{i}.tar.gz' for i in range(16, patches)], dir=images, curl=True, delete=False, threads=8)
90+
91+
# Move
92+
for f in tqdm(images.rglob('*.jpg'), desc=f'Moving {split} images'):
93+
f.rename(images / f.name) # move to /images/{split}
94+
95+
# Labels
96+
coco = COCO(dir / f'zhiyuan_objv2_{split}.json')
97+
names = [x["name"] for x in coco.loadCats(coco.getCatIds())]
98+
for cid, cat in enumerate(names):
99+
catIds = coco.getCatIds(catNms=[cat])
100+
imgIds = coco.getImgIds(catIds=catIds)
101+
for im in tqdm(coco.loadImgs(imgIds), desc=f'Class {cid + 1}/{len(names)} {cat}'):
102+
width, height = im["width"], im["height"]
103+
path = Path(im["file_name"]) # image filename
104+
try:
105+
with open(labels / path.with_suffix('.txt').name, 'a') as file:
106+
annIds = coco.getAnnIds(imgIds=im["id"], catIds=catIds, iscrowd=None)
107+
for a in coco.loadAnns(annIds):
108+
x, y, w, h = a['bbox'] # bounding box in xywh (xy top-left corner)
109+
xyxy = np.array([x, y, x + w, y + h])[None] # pixels(1,4)
110+
x, y, w, h = xyxy2xywhn(xyxy, w=width, h=height, clip=True)[0] # normalized and clipped
111+
file.write(f"{cid} {x:.5f} {y:.5f} {w:.5f} {h:.5f}\n")
112+
except Exception as e:
113+
print(e)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2+
# SKU-110K retail items dataset https://github.com/eg4000/SKU110K_CVPR19 by Trax Retail
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+
28+
# Download
29+
dir = Path(yaml['path']) # dataset root dir
30+
parent = Path(dir.parent) # download dir
31+
urls = ['http://trax-geometry.s3.amazonaws.com/cvpr_challenge/SKU110K_fixed.tar.gz']
32+
download(urls, dir=parent, delete=False)
33+
34+
# Rename directories
35+
if dir.exists():
36+
shutil.rmtree(dir)
37+
(parent / 'SKU110K_fixed').rename(dir) # rename dir
38+
(dir / 'labels').mkdir(parents=True, exist_ok=True) # create labels dir
39+
40+
# Convert labels
41+
names = 'image', 'x1', 'y1', 'x2', 'y2', 'class', 'image_width', 'image_height' # column names
42+
for d in 'annotations_train.csv', 'annotations_val.csv', 'annotations_test.csv':
43+
x = pd.read_csv(dir / 'annotations' / d, names=names).values # annotations
44+
images, unique_images = x[:, 0], np.unique(x[:, 0])
45+
with open((dir / d).with_suffix('.txt').__str__().replace('annotations_', ''), 'w') as f:
46+
f.writelines(f'./images/{s}\n' for s in unique_images)
47+
for im in tqdm(unique_images, desc=f'Converting {dir / d}'):
48+
cls = 0 # single-class dataset
49+
with open((dir / 'labels' / im).with_suffix('.txt'), 'a') as f:
50+
for r in x[images == im]:
51+
w, h = r[6], r[7] # image width, height
52+
xywh = xyxy2xywh(np.array([[r[1] / w, r[2] / h, r[3] / w, r[4] / h]]))[0] # instance
53+
f.write(f"{cls} {xywh[0]:.5f} {xywh[1]:.5f} {xywh[2]:.5f} {xywh[3]:.5f}\n") # write label

src/sparseml/yolov5/data/VOC.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2+
# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC by University of Oxford
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, threads=3)
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

0 commit comments

Comments
 (0)