Skip to content

Commit 8480211

Browse files
committed
Remove duplicate line in setup.cfg (ultralytics#9380)
1 parent a4ed988 commit 8480211

File tree

6 files changed

+471
-12
lines changed

6 files changed

+471
-12
lines changed

data/dt.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2+
# COCO 2017 dataset http://cocodataset.org by Microsoft
3+
# Example usage: python train.py --data coco.yaml
4+
# parent
5+
# ├── yolov5
6+
# └── datasets
7+
# └── coco ← downloads here (20.1 GB)
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: D:\detection\datasets\union2voc_multiClass\yolo_dataset # dataset root dir
12+
train: train.txt # train images (relative to 'path') 118287 images
13+
val: val.txt # val images (relative to 'path') 5000 images
14+
test: test.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794
15+
16+
# Classes
17+
names:
18+
0: Car
19+
1: Bus
20+
2: Cyclist
21+
3: Pedestrian
22+
4: driverless_car
23+
5: Truck
24+
6: Tricyclist
25+
7: Trafficcone
26+
27+
# Download script/URL (optional)
776 Bytes
Binary file not shown.

utils/dataloaders.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def create_dataloader(path,
114114
image_weights=False,
115115
quad=False,
116116
prefix='',
117-
shuffle=False):
117+
shuffle=False,
118+
size_conf=None):
118119
if rect and shuffle:
119120
LOGGER.warning('WARNING: --rect is incompatible with DataLoader shuffle, setting shuffle=False')
120121
shuffle = False
@@ -131,7 +132,8 @@ def create_dataloader(path,
131132
stride=int(stride),
132133
pad=pad,
133134
image_weights=image_weights,
134-
prefix=prefix)
135+
prefix=prefix,
136+
size_conf=size_conf)
135137

136138
batch_size = min(batch_size, len(dataset))
137139
nd = torch.cuda.device_count() # number of CUDA devices
@@ -393,7 +395,8 @@ def __init__(self,
393395
single_cls=False,
394396
stride=32,
395397
pad=0.0,
396-
prefix=''):
398+
prefix='',
399+
size_conf=None):
397400
self.img_size = img_size
398401
self.augment = augment
399402
self.hyp = hyp
@@ -430,11 +433,12 @@ def __init__(self,
430433
self.label_files = img2label_paths(self.im_files) # labels
431434
cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache')
432435
try:
436+
cache_path.unlink() # remove old cache
433437
cache, exists = np.load(cache_path, allow_pickle=True).item(), True # load dict
434438
assert cache['version'] == self.cache_version # matches current version
435439
assert cache['hash'] == get_hash(self.label_files + self.im_files) # identical hash
436440
except Exception:
437-
cache, exists = self.cache_labels(cache_path, prefix), False # run cache ops
441+
cache, exists = self.cache_labels(cache_path, prefix, size_conf), False # run cache ops
438442

439443
# Display cache
440444
nf, nm, ne, nc, n = cache.pop('results') # found, missing, empty, corrupt, total
@@ -517,13 +521,14 @@ def __init__(self,
517521
pbar.desc = f'{prefix}Caching images ({gb / 1E9:.1f}GB {cache_images})'
518522
pbar.close()
519523

520-
def cache_labels(self, path=Path('./labels.cache'), prefix=''):
524+
def cache_labels(self, path=Path('./labels.cache'), prefix='', size_conf=None):
521525
# Cache dataset labels, check images and read shapes
522526
x = {} # dict
523527
nm, nf, ne, nc, msgs = 0, 0, 0, 0, [] # number missing, found, empty, corrupt, messages
524528
desc = f"{prefix}Scanning '{path.parent / path.stem}' images and labels..."
525529
with Pool(NUM_THREADS) as pool:
526-
pbar = tqdm(pool.imap(verify_image_label, zip(self.im_files, self.label_files, repeat(prefix))),
530+
pbar = tqdm(pool.imap(verify_image_label,
531+
zip(self.im_files, self.label_files, repeat(prefix), repeat(size_conf))),
527532
desc=desc,
528533
total=len(self.im_files),
529534
bar_format=BAR_FORMAT)
@@ -902,7 +907,7 @@ def autosplit(path=DATASETS_DIR / 'coco128/images', weights=(0.9, 0.1, 0.0), ann
902907

903908
def verify_image_label(args):
904909
# Verify one image-label pair
905-
im_file, lb_file, prefix = args
910+
im_file, lb_file, prefix, size_conf = args
906911
nm, nf, ne, nc, msg, segments = 0, 0, 0, 0, '', [] # number (missing, found, empty, corrupt), message, segments
907912
try:
908913
# verify images
@@ -928,6 +933,14 @@ def verify_image_label(args):
928933
segments = [np.array(x[1:], dtype=np.float32).reshape(-1, 2) for x in lb] # (cls, xy1...)
929934
lb = np.concatenate((classes.reshape(-1, 1), segments2boxes(segments)), 1) # (cls, xywh)
930935
lb = np.array(lb, dtype=np.float32)
936+
if size_conf is not None:
937+
size_thres = np.array([size_conf[int(i)] for i in lb[:, 0]], dtype=np.float32) ** 2
938+
areas = (lb[:, 3:] * np.array(shape, dtype=np.float32)).prod(1)
939+
idx = (areas > size_thres[:, 0]) & (areas <= size_thres[:, 1])
940+
if idx.any():
941+
lb = lb[idx.T]
942+
else:
943+
lb = np.zeros((0, 5), dtype=np.float32)
931944
nl = len(lb)
932945
if nl:
933946
assert lb.shape[1] == 5, f'labels require 5 columns, {lb.shape[1]} columns detected'

utils/metrics.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ def ap_per_class(tp, conf, pred_cls, target_cls, plot=False, save_dir='.', names
9191
i = smooth(f1.mean(0), 0.1).argmax() # max F1 index
9292
p, r, f1 = p[:, i], r[:, i], f1[:, i]
9393
tp = (r * nt).round() # true positives
94+
fn = nt - tp
9495
fp = (tp / (p + eps) - tp).round() # false positives
95-
return tp, fp, p, r, f1, ap, unique_classes.astype(int)
96+
return tp, fp, fn, p, r, f1, ap, unique_classes.astype(int)
9697

9798

9899
def compute_ap(recall, precision):
@@ -177,14 +178,14 @@ def process_batch(self, detections, labels):
177178
if not any(m1 == i):
178179
self.matrix[dc, self.nc] += 1 # background FN
179180

180-
def matrix(self):
181+
def get_matrix(self):
181182
return self.matrix
182183

183184
def tp_fp(self):
184185
tp = self.matrix.diagonal() # true positives
185186
fp = self.matrix.sum(1) - tp # false positives
186-
# fn = self.matrix.sum(0) - tp # false negatives (missed detections)
187-
return tp[:-1], fp[:-1] # remove background class
187+
fn = self.matrix.sum(0) - tp # false negatives (missed detections)
188+
return tp[:-1], fp[:-1], fn[:-1] # remove background class
188189

189190
@TryExcept('WARNING: ConfusionMatrix plot failure: ')
190191
def plot(self, normalize=True, save_dir='', names=()):

val.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def run(
265265
# Compute metrics
266266
stats = [torch.cat(x, 0).cpu().numpy() for x in zip(*stats)] # to numpy
267267
if len(stats) and stats[0].any():
268-
tp, fp, p, r, f1, ap, ap_class = ap_per_class(*stats, plot=plots, save_dir=save_dir, names=names)
268+
tp, fp, fn, p, r, f1, ap, ap_class = ap_per_class(*stats, plot=plots, save_dir=save_dir, names=names)
269269
ap50, ap = ap[:, 0], ap.mean(1) # [email protected], [email protected]:0.95
270270
mp, mr, map50, map = p.mean(), r.mean(), ap50.mean(), ap.mean()
271271
nt = np.bincount(stats[3].astype(int), minlength=nc) # number of targets per class

0 commit comments

Comments
 (0)