Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
2c7c075
Update restapi.py (#2967)
glenn-jocher Apr 28, 2021
33712d6
Global Wheat Detection 2020 Dataset Auto-Download (#2968)
glenn-jocher Apr 28, 2021
dbce1bc
Objects365 Dataset (#2932)
ferdinandl007 Apr 29, 2021
a833ee2
Update check_requirements() exclude list (#2974)
glenn-jocher Apr 29, 2021
955eea8
Make cache saving optional (#2977)
glenn-jocher Apr 29, 2021
41f5cc5
YOLOv5 AWS Inferentia Inplace compatibility updates (#2953)
jluntamazon Apr 30, 2021
9b91db6
Created using Colaboratory
glenn-jocher Apr 30, 2021
d08575e
PyTorch Hub load directly when possible (#2986)
glenn-jocher Apr 30, 2021
801b469
Improve performance of dataset Logger (#2943)
AyushExel Apr 30, 2021
54652fe
Objects365 update
glenn-jocher Apr 30, 2021
f55730e
Objects365 bug fix
glenn-jocher Apr 30, 2021
4d7bca7
Add unzip flag to download() (#3002)
glenn-jocher May 1, 2021
37eaffe
Curl update (#3004)
glenn-jocher May 1, 2021
c1a44ed
Update hubconf.py for unified loading (#3005)
glenn-jocher May 1, 2021
7c89c82
cleanup
glenn-jocher May 1, 2021
31ee54c
Hubconf.py bug fix (#3007)
glenn-jocher May 1, 2021
e2a80c6
Add support for FP16 (half) to export.py (#3010)
hodovo May 2, 2021
fcd5702
Add is_colab() function (#3018)
glenn-jocher May 3, 2021
41cc7ca
Add NMS threshold checks (#3020)
glenn-jocher May 3, 2021
b292837
Fix ONNX export using --grid --simplify --dynamic simultaneously (#2982)
jylink May 3, 2021
5189b3a
Objects365 Update
glenn-jocher May 4, 2021
8cab907
download() ThreadPool update (#3027)
glenn-jocher May 4, 2021
4c7d686
FROM nvcr.io/nvidia/pytorch:21.04-py3 (#3030)
glenn-jocher May 4, 2021
85b6fdd
FROM nvcr.io/nvidia/pytorch:21.03-py3
glenn-jocher May 4, 2021
b18ca31
use check_file for --data (#3035)
AyushExel May 5, 2021
b8be76f
Add get_coco128.sh for downloading the coco128 dataset (#3047)
zldrobit May 6, 2021
3ef3a95
Do not optimize CoreML TorchScript model (#3055)
glenn-jocher May 6, 2021
f2de1ad
Comment fix (#3058)
kepler62f May 7, 2021
e97d129
Update export.py with --train mode argument (#3066)
glenn-jocher May 7, 2021
d2a1728
Explicitly convert artifact path to posix_path (#3067)
AyushExel May 7, 2021
251aeaf
Update P5 + P6 model ensembling (#3082)
glenn-jocher May 8, 2021
91547ed
Update detect.py (#3087)
glenn-jocher May 9, 2021
57b0d3a
Add check_python() (#3088)
glenn-jocher May 9, 2021
525f4f8
Add --optimize argument (#3093)
glenn-jocher May 10, 2021
60fe544
Update train.py (#3099)
glenn-jocher May 10, 2021
d6a71ae
Update GlobalWheat2020.yaml test: # 1276 images (#3101)
glenn-jocher May 10, 2021
25f8ab8
detect.py streaming source `--save-crop` bug fix (#3102)
glenn-jocher May 10, 2021
abfcf9e
Replace print() with logging.info() in trainloader (#3103)
glenn-jocher May 10, 2021
52c0570
Update Colors() (#3046)
glenn-jocher May 12, 2021
c1c7eb0
Update JSON response (#3139)
glenn-jocher May 12, 2021
7918eed
Update https://ultralytics.com/images/zidane.jpg (#3140)
glenn-jocher May 12, 2021
bd6f6a7
Add yolov5/__init__.py (#3127)
KC-Zhang May 12, 2021
d9b4e6b
Add `--include torchscript onnx coreml` argument (#3137)
CristiFati May 12, 2021
f12cef8
TorchScript, ONNX, CoreML Export tutorial title (#3142)
glenn-jocher May 12, 2021
b098600
Update requirements.txt `onnx>=1.9.0` (#3143)
glenn-jocher May 12, 2021
1935266
Scope imports for torch.hub.list() improvement (#3144)
glenn-jocher May 12, 2021
06372b1
Scope all hubconf.py imports for torch.hub.list() (#3145)
glenn-jocher May 12, 2021
17b0f71
SKU-110K CVPR2019 Dataset Auto-Download (#3167)
glenn-jocher May 14, 2021
be86c21
rename class autoShape -> AutoShape (#3173)
developer0hye May 16, 2021
9ab561d
Parameterize ONNX `--opset-version` (#3154)
CristiFati May 16, 2021
b133baa
Add `device` argument to PyTorch Hub models (#3104)
cgerum May 16, 2021
ae53f50
Plot labels histogram colors (#3192)
glenn-jocher May 17, 2021
36b0a9e
Add CAP_PROP_FRAME_COUNT for YouTube sources (#3193)
glenn-jocher May 17, 2021
ffb47ff
Silent Patches Bug Fix (#3214)
glenn-jocher May 17, 2021
13a1c72
Update datasets.py (#3216)
glenn-jocher May 17, 2021
3f74cd9
Parameterize max_det + inference default at 1000 (#3215)
adrianholovaty May 17, 2021
b7cd1f5
TensorBoard add_graph() fix (#3236)
glenn-jocher May 19, 2021
7b0eb95
`plot_one_box()` default `color=(128, 128, 128)` (#3240)
yeric1789 May 19, 2021
7b863a3
Add Cython (#3217)
glenn-jocher May 19, 2021
7b36e38
Check CoreML models.train() mode (#3262)
glenn-jocher May 20, 2021
10d56d7
Assert `--image-weights` not combined with DDP (#3275)
glenn-jocher May 21, 2021
f340235
check `batch_size % utilized_device_count` (#3276)
glenn-jocher May 21, 2021
683cefe
YouTube stream ending fix (#3277)
glenn-jocher May 21, 2021
dd7f0b7
Fix TypeError: 'PosixPath' object is not iterable (#3285)
glenn-jocher May 21, 2021
19100ba
Improves docs and handling of entities and resuming by WandbLogger (#…
charlesfrye May 21, 2021
0e2f2cb
Update LoadStreams init fallbacks (#3295)
glenn-jocher May 23, 2021
a039b77
PyTorch Hub `crops = results.crop()` return values (#3282)
yeric1789 May 23, 2021
ee24ae1
Comment Cython (#3297)
glenn-jocher May 23, 2021
9f3a388
Improved check_requirements() robustness (#3298)
glenn-jocher May 23, 2021
d65b1b2
Merge branch 'master' of https://github.com/ultralytics/yolov5 into u…
markurtz May 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ $ pip install -r requirements.txt
* [Supervisely Ecosystem](https://github.com/ultralytics/yolov5/issues/2518)  🌟 NEW
* [Multi-GPU Training](https://github.com/ultralytics/yolov5/issues/475)
* [PyTorch Hub](https://github.com/ultralytics/yolov5/issues/36)  ⭐ NEW
* [ONNX and TorchScript Export](https://github.com/ultralytics/yolov5/issues/251)
* [TorchScript, ONNX, CoreML Export](https://github.com/ultralytics/yolov5/issues/251) 🚀
* [Test-Time Augmentation (TTA)](https://github.com/ultralytics/yolov5/issues/303)
* [Model Ensembling](https://github.com/ultralytics/yolov5/issues/318)
* [Model Pruning/Sparsity](https://github.com/ultralytics/yolov5/issues/304)
Expand Down Expand Up @@ -130,7 +130,7 @@ import torch
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')

# Image
img = 'https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg'
img = 'https://ultralytics.com/images/zidane.jpg'

# Inference
results = model(img)
Expand Down
Empty file added __init__.py
Empty file.
55 changes: 55 additions & 0 deletions data/GlobalWheat2020.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Global Wheat 2020 dataset http://www.global-wheat.com/
# Train command: python train.py --data GlobalWheat2020.yaml
# Default dataset location is next to YOLOv5:
# /parent_folder
# /datasets/GlobalWheat2020
# /yolov5


# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: # 3422 images
- ../datasets/GlobalWheat2020/images/arvalis_1
- ../datasets/GlobalWheat2020/images/arvalis_2
- ../datasets/GlobalWheat2020/images/arvalis_3
- ../datasets/GlobalWheat2020/images/ethz_1
- ../datasets/GlobalWheat2020/images/rres_1
- ../datasets/GlobalWheat2020/images/inrae_1
- ../datasets/GlobalWheat2020/images/usask_1

val: # 748 images (WARNING: train set contains ethz_1)
- ../datasets/GlobalWheat2020/images/ethz_1

test: # 1276 images
- ../datasets/GlobalWheat2020/images/utokyo_1
- ../datasets/GlobalWheat2020/images/utokyo_2
- ../datasets/GlobalWheat2020/images/nau_1
- ../datasets/GlobalWheat2020/images/uq_1

# number of classes
nc: 1

# class names
names: [ 'wheat_head' ]


# download command/URL (optional) --------------------------------------------------------------------------------------
download: |
from utils.general import download, Path

# Download
dir = Path('../datasets/GlobalWheat2020') # dataset directory
urls = ['https://zenodo.org/record/4298502/files/global-wheat-codalab-official.zip',
'https://github.com/ultralytics/yolov5/releases/download/v1.0/GlobalWheat2020_labels.zip']
download(urls, dir=dir)

# Make Directories
for p in 'annotations', 'images', 'labels':
(dir / p).mkdir(parents=True, exist_ok=True)

# Move
for p in 'arvalis_1', 'arvalis_2', 'arvalis_3', 'ethz_1', 'rres_1', 'inrae_1', 'usask_1', \
'utokyo_1', 'utokyo_2', 'nau_1', 'uq_1':
(dir / p).rename(dir / 'images' / p) # move to /images
f = (dir / p).with_suffix('.json') # json file
if f.exists():
f.rename((dir / 'annotations' / p).with_suffix('.json')) # move to /annotations
52 changes: 52 additions & 0 deletions data/SKU-110K.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# SKU-110K retail items dataset https://github.com/eg4000/SKU110K_CVPR19
# Train command: python train.py --data SKU-110K.yaml
# Default dataset location is next to YOLOv5:
# /parent_folder
# /datasets/SKU-110K
# /yolov5


# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: ../datasets/SKU-110K/train.txt # 8219 images
val: ../datasets/SKU-110K/val.txt # 588 images
test: ../datasets/SKU-110K/test.txt # 2936 images

# number of classes
nc: 1

# class names
names: [ 'object' ]


# download command/URL (optional) --------------------------------------------------------------------------------------
download: |
import shutil
from tqdm import tqdm
from utils.general import np, pd, Path, download, xyxy2xywh

# Download
datasets = Path('../datasets') # download directory
urls = ['http://trax-geometry.s3.amazonaws.com/cvpr_challenge/SKU110K_fixed.tar.gz']
download(urls, dir=datasets, delete=False)

# Rename directories
dir = (datasets / 'SKU-110K')
if dir.exists():
shutil.rmtree(dir)
(datasets / 'SKU110K_fixed').rename(dir) # rename dir
(dir / 'labels').mkdir(parents=True, exist_ok=True) # create labels dir

# Convert labels
names = 'image', 'x1', 'y1', 'x2', 'y2', 'class', 'image_width', 'image_height' # column names
for d in 'annotations_train.csv', 'annotations_val.csv', 'annotations_test.csv':
x = pd.read_csv(dir / 'annotations' / d, names=names).values # annotations
images, unique_images = x[:, 0], np.unique(x[:, 0])
with open((dir / d).with_suffix('.txt').__str__().replace('annotations_', ''), 'w') as f:
f.writelines(f'./images/{s}\n' for s in unique_images)
for im in tqdm(unique_images, desc=f'Converting {dir / d}'):
cls = 0 # single-class dataset
with open((dir / 'labels' / im).with_suffix('.txt'), 'a') as f:
for r in x[images == im]:
w, h = r[6], r[7] # image width, height
xywh = xyxy2xywh(np.array([[r[1] / w, r[2] / h, r[3] / w, r[4] / h]]))[0] # instance
f.write(f"{cls} {xywh[0]:.5f} {xywh[1]:.5f} {xywh[2]:.5f} {xywh[3]:.5f}\n") # write label
8 changes: 2 additions & 6 deletions data/visdrone.yaml → data/VisDrone.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# VisDrone2019-DET dataset https://github.com/VisDrone/VisDrone-Dataset
# Train command: python train.py --data visdrone.yaml
# Train command: python train.py --data VisDrone.yaml
# Default dataset location is next to YOLOv5:
# /parent_folder
# /VisDrone
Expand All @@ -20,11 +20,7 @@ names: [ 'pedestrian', 'people', 'bicycle', 'car', 'van', 'truck', 'tricycle', '

# download command/URL (optional) --------------------------------------------------------------------------------------
download: |
import os
from pathlib import Path

from utils.general import download

from utils.general import download, os, Path

def visdrone2yolo(dir):
from PIL import Image
Expand Down
28 changes: 28 additions & 0 deletions data/hyp.finetune_objects365.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lr0: 0.00258
lrf: 0.17
momentum: 0.779
weight_decay: 0.00058
warmup_epochs: 1.33
warmup_momentum: 0.86
warmup_bias_lr: 0.0711
box: 0.0539
cls: 0.299
cls_pw: 0.825
obj: 0.632
obj_pw: 1.0
iou_t: 0.2
anchor_t: 3.44
anchors: 3.2
fl_gamma: 0.0
hsv_h: 0.0188
hsv_s: 0.704
hsv_v: 0.36
degrees: 0.0
translate: 0.0902
scale: 0.491
shear: 0.0
perspective: 0.0
flipud: 0.0
fliplr: 0.5
mosaic: 1.0
mixup: 0.0
102 changes: 102 additions & 0 deletions data/objects365.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Objects365 dataset https://www.objects365.org/
# Train command: python train.py --data objects365.yaml
# Default dataset location is next to YOLOv5:
# /parent_folder
# /datasets/objects365
# /yolov5

# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: ../datasets/objects365/images/train # 1742289 images
val: ../datasets/objects365/images/val # 5570 images

# number of classes
nc: 365

# class names
names: [ 'Person', 'Sneakers', 'Chair', 'Other Shoes', 'Hat', 'Car', 'Lamp', 'Glasses', 'Bottle', 'Desk', 'Cup',
'Street Lights', 'Cabinet/shelf', 'Handbag/Satchel', 'Bracelet', 'Plate', 'Picture/Frame', 'Helmet', 'Book',
'Gloves', 'Storage box', 'Boat', 'Leather Shoes', 'Flower', 'Bench', 'Potted Plant', 'Bowl/Basin', 'Flag',
'Pillow', 'Boots', 'Vase', 'Microphone', 'Necklace', 'Ring', 'SUV', 'Wine Glass', 'Belt', 'Monitor/TV',
'Backpack', 'Umbrella', 'Traffic Light', 'Speaker', 'Watch', 'Tie', 'Trash bin Can', 'Slippers', 'Bicycle',
'Stool', 'Barrel/bucket', 'Van', 'Couch', 'Sandals', 'Basket', 'Drum', 'Pen/Pencil', 'Bus', 'Wild Bird',
'High Heels', 'Motorcycle', 'Guitar', 'Carpet', 'Cell Phone', 'Bread', 'Camera', 'Canned', 'Truck',
'Traffic cone', 'Cymbal', 'Lifesaver', 'Towel', 'Stuffed Toy', 'Candle', 'Sailboat', 'Laptop', 'Awning',
'Bed', 'Faucet', 'Tent', 'Horse', 'Mirror', 'Power outlet', 'Sink', 'Apple', 'Air Conditioner', 'Knife',
'Hockey Stick', 'Paddle', 'Pickup Truck', 'Fork', 'Traffic Sign', 'Balloon', 'Tripod', 'Dog', 'Spoon', 'Clock',
'Pot', 'Cow', 'Cake', 'Dinning Table', 'Sheep', 'Hanger', 'Blackboard/Whiteboard', 'Napkin', 'Other Fish',
'Orange/Tangerine', 'Toiletry', 'Keyboard', 'Tomato', 'Lantern', 'Machinery Vehicle', 'Fan',
'Green Vegetables', 'Banana', 'Baseball Glove', 'Airplane', 'Mouse', 'Train', 'Pumpkin', 'Soccer', 'Skiboard',
'Luggage', 'Nightstand', 'Tea pot', 'Telephone', 'Trolley', 'Head Phone', 'Sports Car', 'Stop Sign',
'Dessert', 'Scooter', 'Stroller', 'Crane', 'Remote', 'Refrigerator', 'Oven', 'Lemon', 'Duck', 'Baseball Bat',
'Surveillance Camera', 'Cat', 'Jug', 'Broccoli', 'Piano', 'Pizza', 'Elephant', 'Skateboard', 'Surfboard',
'Gun', 'Skating and Skiing shoes', 'Gas stove', 'Donut', 'Bow Tie', 'Carrot', 'Toilet', 'Kite', 'Strawberry',
'Other Balls', 'Shovel', 'Pepper', 'Computer Box', 'Toilet Paper', 'Cleaning Products', 'Chopsticks',
'Microwave', 'Pigeon', 'Baseball', 'Cutting/chopping Board', 'Coffee Table', 'Side Table', 'Scissors',
'Marker', 'Pie', 'Ladder', 'Snowboard', 'Cookies', 'Radiator', 'Fire Hydrant', 'Basketball', 'Zebra', 'Grape',
'Giraffe', 'Potato', 'Sausage', 'Tricycle', 'Violin', 'Egg', 'Fire Extinguisher', 'Candy', 'Fire Truck',
'Billiards', 'Converter', 'Bathtub', 'Wheelchair', 'Golf Club', 'Briefcase', 'Cucumber', 'Cigar/Cigarette',
'Paint Brush', 'Pear', 'Heavy Truck', 'Hamburger', 'Extractor', 'Extension Cord', 'Tong', 'Tennis Racket',
'Folder', 'American Football', 'earphone', 'Mask', 'Kettle', 'Tennis', 'Ship', 'Swing', 'Coffee Machine',
'Slide', 'Carriage', 'Onion', 'Green beans', 'Projector', 'Frisbee', 'Washing Machine/Drying Machine',
'Chicken', 'Printer', 'Watermelon', 'Saxophone', 'Tissue', 'Toothbrush', 'Ice cream', 'Hot-air balloon',
'Cello', 'French Fries', 'Scale', 'Trophy', 'Cabbage', 'Hot dog', 'Blender', 'Peach', 'Rice', 'Wallet/Purse',
'Volleyball', 'Deer', 'Goose', 'Tape', 'Tablet', 'Cosmetics', 'Trumpet', 'Pineapple', 'Golf Ball',
'Ambulance', 'Parking meter', 'Mango', 'Key', 'Hurdle', 'Fishing Rod', 'Medal', 'Flute', 'Brush', 'Penguin',
'Megaphone', 'Corn', 'Lettuce', 'Garlic', 'Swan', 'Helicopter', 'Green Onion', 'Sandwich', 'Nuts',
'Speed Limit Sign', 'Induction Cooker', 'Broom', 'Trombone', 'Plum', 'Rickshaw', 'Goldfish', 'Kiwi fruit',
'Router/modem', 'Poker Card', 'Toaster', 'Shrimp', 'Sushi', 'Cheese', 'Notepaper', 'Cherry', 'Pliers', 'CD',
'Pasta', 'Hammer', 'Cue', 'Avocado', 'Hamimelon', 'Flask', 'Mushroom', 'Screwdriver', 'Soap', 'Recorder',
'Bear', 'Eggplant', 'Board Eraser', 'Coconut', 'Tape Measure/Ruler', 'Pig', 'Showerhead', 'Globe', 'Chips',
'Steak', 'Crosswalk Sign', 'Stapler', 'Camel', 'Formula 1', 'Pomegranate', 'Dishwasher', 'Crab',
'Hoverboard', 'Meat ball', 'Rice Cooker', 'Tuba', 'Calculator', 'Papaya', 'Antelope', 'Parrot', 'Seal',
'Butterfly', 'Dumbbell', 'Donkey', 'Lion', 'Urinal', 'Dolphin', 'Electric Drill', 'Hair Dryer', 'Egg tart',
'Jellyfish', 'Treadmill', 'Lighter', 'Grapefruit', 'Game board', 'Mop', 'Radish', 'Baozi', 'Target', 'French',
'Spring Rolls', 'Monkey', 'Rabbit', 'Pencil Case', 'Yak', 'Red Cabbage', 'Binoculars', 'Asparagus', 'Barbell',
'Scallop', 'Noddles', 'Comb', 'Dumpling', 'Oyster', 'Table Tennis paddle', 'Cosmetics Brush/Eyeliner Pencil',
'Chainsaw', 'Eraser', 'Lobster', 'Durian', 'Okra', 'Lipstick', 'Cosmetics Mirror', 'Curling', 'Table Tennis' ]


# download command/URL (optional) --------------------------------------------------------------------------------------
download: |
from pycocotools.coco import COCO
from tqdm import tqdm

from utils.general import download, Path

# Make Directories
dir = Path('../datasets/objects365') # dataset directory
for p in 'images', 'labels':
(dir / p).mkdir(parents=True, exist_ok=True)
for q in 'train', 'val':
(dir / p / q).mkdir(parents=True, exist_ok=True)

# Download
url = "https://dorc.ks3-cn-beijing.ksyun.com/data-set/2020Objects365%E6%95%B0%E6%8D%AE%E9%9B%86/train/"
download([url + 'zhiyuan_objv2_train.tar.gz'], dir=dir, delete=False) # annotations json
download([url + f for f in [f'patch{i}.tar.gz' for i in range(51)]], dir=dir / 'images' / 'train',
curl=True, delete=False, threads=8)

# Move
train = dir / 'images' / 'train'
for f in tqdm(train.rglob('*.jpg'), desc=f'Moving images'):
f.rename(train / f.name) # move to /images/train

# Labels
coco = COCO(dir / 'zhiyuan_objv2_train.json')
names = [x["name"] for x in coco.loadCats(coco.getCatIds())]
for cid, cat in enumerate(names):
catIds = coco.getCatIds(catNms=[cat])
imgIds = coco.getImgIds(catIds=catIds)
for im in tqdm(coco.loadImgs(imgIds), desc=f'Class {cid + 1}/{len(names)} {cat}'):
width, height = im["width"], im["height"]
path = Path(im["file_name"]) # image filename
try:
with open(dir / 'labels' / 'train' / path.with_suffix('.txt').name, 'a') as file:
annIds = coco.getAnnIds(imgIds=im["id"], catIds=catIds, iscrowd=None)
for a in coco.loadAnns(annIds):
x, y, w, h = a['bbox'] # bounding box in xywh (xy top-left corner)
x, y = x + w / 2, y + h / 2 # xy to center
file.write(f"{cid} {x / width:.5f} {y / height:.5f} {w / width:.5f} {h / height:.5f}\n")

except Exception as e:
print(e)
5 changes: 2 additions & 3 deletions data/scripts/get_argoverse_hd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ for val in annotation_files:
img_name = a['images'][img_id]['name']
img_label_name = img_name[:-3] + "txt"

obj_class = annot['category_id']
cls = annot['category_id'] # instance class id
x_center, y_center, width, height = annot['bbox']
x_center = (x_center + width / 2) / 1920. # offset and scale
y_center = (y_center + height / 2) / 1200. # offset and scale
Expand All @@ -46,11 +46,10 @@ for val in annotation_files:
img_dir = "./labels/" + a['seq_dirs'][a['images'][annot['image_id']]['sid']]

Path(img_dir).mkdir(parents=True, exist_ok=True)

if img_dir + "/" + img_label_name not in label_dict:
label_dict[img_dir + "/" + img_label_name] = []

label_dict[img_dir + "/" + img_label_name].append(f"{obj_class} {x_center} {y_center} {width} {height}\n")
label_dict[img_dir + "/" + img_label_name].append(f"{cls} {x_center} {y_center} {width} {height}\n")

for filename in label_dict:
with open(filename, "w") as file:
Expand Down
17 changes: 17 additions & 0 deletions data/scripts/get_coco128.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# COCO128 dataset https://www.kaggle.com/ultralytics/coco128
# Download command: bash data/scripts/get_coco128.sh
# Train command: python train.py --data coco128.yaml
# Default dataset location is next to /yolov5:
# /parent_folder
# /coco128
# /yolov5

# Download/unzip images and labels
d='../' # unzip directory
url=https://github.com/ultralytics/yolov5/releases/download/v1.0/
f='coco128.zip' # or 'coco2017labels-segments.zip', 68 MB
echo 'Downloading' $url$f ' ...'
curl -L $url$f -o $f && unzip -q $f -d $d && rm $f & # download, unzip, remove in background

wait # finish background tasks
13 changes: 7 additions & 6 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import cv2
import torch
import torch.backends.cudnn as cudnn
from numpy import random

from models.experimental import attempt_load
from utils.datasets import LoadStreams, LoadImages
Expand Down Expand Up @@ -69,7 +68,8 @@ def detect(opt):
pred = model(img, augment=opt.augment)[0]

# Apply NMS
pred = non_max_suppression(pred, opt.conf_thres, opt.iou_thres, classes=opt.classes, agnostic=opt.agnostic_nms)
pred = non_max_suppression(pred, opt.conf_thres, opt.iou_thres, opt.classes, opt.agnostic_nms,
max_det=opt.max_det)
t2 = time_synchronized()

# Apply Classifier
Expand All @@ -79,7 +79,7 @@ def detect(opt):
# Process detections
for i, det in enumerate(pred): # detections per image
if webcam: # batch_size >= 1
p, s, im0, frame = path[i], '%g: ' % i, im0s[i].copy(), dataset.count
p, s, im0, frame = path[i], f'{i}: ', im0s[i].copy(), dataset.count
else:
p, s, im0, frame = path, '', im0s.copy(), getattr(dataset, 'frame', 0)

Expand All @@ -88,6 +88,7 @@ def detect(opt):
txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt
s += '%gx%g ' % img.shape[2:] # print string
gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
imc = im0.copy() if opt.save_crop else im0 # for opt.save_crop
if len(det):
# Rescale boxes from img_size to im0 size
det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()
Expand All @@ -108,10 +109,9 @@ def detect(opt):
if save_img or opt.save_crop or view_img: # Add bbox to image
c = int(cls) # integer class
label = None if opt.hide_labels else (names[c] if opt.hide_conf else f'{names[c]} {conf:.2f}')

plot_one_box(xyxy, im0, label=label, color=colors(c, True), line_thickness=opt.line_thickness)
if opt.save_crop:
save_one_box(xyxy, im0s, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)
save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)

# Print time (inference + NMS)
print(f'{s}Done. ({t2 - t1:.3f}s)')
Expand Down Expand Up @@ -154,6 +154,7 @@ def detect(opt):
parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS')
parser.add_argument('--max-det', type=int, default=1000, help='maximum number of detections per image')
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
parser.add_argument('--view-img', action='store_true', help='display results')
parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
Expand All @@ -172,7 +173,7 @@ def detect(opt):
parser.add_argument('--hide-conf', default=False, action='store_true', help='hide confidences')
opt = parser.parse_args()
print(opt)
check_requirements(exclude=('pycocotools', 'thop'))
check_requirements(exclude=('tensorboard', 'pycocotools', 'thop'))

with torch.no_grad():
if opt.update: # update all models (to fix SourceChangeWarning)
Expand Down
Loading