Replace 'ground truth' with 'labels' (#1337)
Browse files* Replace 'ground truth' with 'labels'
* Using torch... update
- README.md +1 -1
- test.py +5 -5
- tutorial.ipynb +5 -5
- utils/general.py +8 -8
README.md
CHANGED
@@ -87,7 +87,7 @@ To run inference on example images in `data/images`:
|
|
87 |
$ python detect.py --source data/images --weights yolov5s.pt --conf 0.25
|
88 |
|
89 |
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', img_size=640, iou_thres=0.45, output='runs/detect', save_conf=False, save_txt=False, source='data/images', update=False, view_img=False, weights='yolov5s.pt')
|
90 |
-
Using CUDA
|
91 |
|
92 |
Downloading https://github.com/ultralytics/yolov5/releases/download/v3.0/yolov5s.pt to yolov5s.pt... 100%|ββββββββββββββ| 14.5M/14.5M [00:00<00:00, 21.3MB/s]
|
93 |
|
|
|
87 |
$ python detect.py --source data/images --weights yolov5s.pt --conf 0.25
|
88 |
|
89 |
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', img_size=640, iou_thres=0.45, output='runs/detect', save_conf=False, save_txt=False, source='data/images', update=False, view_img=False, weights='yolov5s.pt')
|
90 |
+
Using torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16130MB)
|
91 |
|
92 |
Downloading https://github.com/ultralytics/yolov5/releases/download/v3.0/yolov5s.pt to yolov5s.pt... 100%|ββββββββββββββ| 14.5M/14.5M [00:00<00:00, 21.3MB/s]
|
93 |
|
test.py
CHANGED
@@ -204,8 +204,8 @@ def test(data,
|
|
204 |
|
205 |
# Plot images
|
206 |
if plots and batch_i < 1:
|
207 |
-
f = save_dir / f'test_batch{batch_i}
|
208 |
-
plot_images(img, targets, paths, str(f), names) #
|
209 |
f = save_dir / f'test_batch{batch_i}_pred.jpg'
|
210 |
plot_images(img, output_to_target(output, width, height), paths, str(f), names) # predictions
|
211 |
|
@@ -250,9 +250,9 @@ def test(data,
|
|
250 |
from pycocotools.cocoeval import COCOeval
|
251 |
|
252 |
imgIds = [int(Path(x).stem) for x in dataloader.dataset.img_files]
|
253 |
-
|
254 |
-
|
255 |
-
cocoEval = COCOeval(
|
256 |
cocoEval.params.imgIds = imgIds # image IDs to evaluate
|
257 |
cocoEval.evaluate()
|
258 |
cocoEval.accumulate()
|
|
|
204 |
|
205 |
# Plot images
|
206 |
if plots and batch_i < 1:
|
207 |
+
f = save_dir / f'test_batch{batch_i}_labels.jpg' # filename
|
208 |
+
plot_images(img, targets, paths, str(f), names) # labels
|
209 |
f = save_dir / f'test_batch{batch_i}_pred.jpg'
|
210 |
plot_images(img, output_to_target(output, width, height), paths, str(f), names) # predictions
|
211 |
|
|
|
250 |
from pycocotools.cocoeval import COCOeval
|
251 |
|
252 |
imgIds = [int(Path(x).stem) for x in dataloader.dataset.img_files]
|
253 |
+
cocoAnno = COCO(glob.glob('../coco/annotations/instances_val*.json')[0]) # initialize COCO annotations api
|
254 |
+
cocoPred = cocoAnno.loadRes(str(file)) # initialize COCO pred api
|
255 |
+
cocoEval = COCOeval(cocoAnno, cocoPred, 'bbox')
|
256 |
cocoEval.params.imgIds = imgIds # image IDs to evaluate
|
257 |
cocoEval.evaluate()
|
258 |
cocoEval.accumulate()
|
tutorial.ipynb
CHANGED
@@ -605,7 +605,7 @@
|
|
605 |
"output_type": "stream",
|
606 |
"text": [
|
607 |
"Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', img_size=640, iou_thres=0.45, save_conf=False, save_dir='runs/detect', save_txt=False, source='data/images/', update=False, view_img=False, weights=['yolov5s.pt'])\n",
|
608 |
-
"Using CUDA
|
609 |
"\n",
|
610 |
"Fusing layers... \n",
|
611 |
"Model Summary: 140 layers, 7.45958e+06 parameters, 0 gradients\n",
|
@@ -735,7 +735,7 @@
|
|
735 |
"output_type": "stream",
|
736 |
"text": [
|
737 |
"Namespace(augment=False, batch_size=32, conf_thres=0.001, data='./data/coco.yaml', device='', img_size=640, iou_thres=0.65, save_conf=False, save_dir='runs/test', save_json=True, save_txt=False, single_cls=False, task='val', verbose=False, weights=['yolov5x.pt'])\n",
|
738 |
-
"Using CUDA
|
739 |
"\n",
|
740 |
"Downloading https://github.com/ultralytics/yolov5/releases/download/v3.1/yolov5x.pt to yolov5x.pt...\n",
|
741 |
"100% 170M/170M [00:05<00:00, 32.2MB/s]\n",
|
@@ -921,7 +921,7 @@
|
|
921 |
{
|
922 |
"output_type": "stream",
|
923 |
"text": [
|
924 |
-
"Using CUDA
|
925 |
"\n",
|
926 |
"Namespace(adam=False, batch_size=16, bucket='', cache_images=True, cfg='', data='./data/coco128.yaml', device='', epochs=3, evolve=False, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[640, 640], local_rank=-1, log_imgs=10, logdir='runs/', multi_scale=False, name='', noautoanchor=False, nosave=True, notest=False, rect=False, resume=False, single_cls=False, sync_bn=False, total_batch_size=16, weights='yolov5s.pt', workers=8, world_size=1)\n",
|
927 |
"Start Tensorboard with \"tensorboard --logdir runs/\", view at http://localhost:6006/\n",
|
@@ -1040,7 +1040,7 @@
|
|
1040 |
},
|
1041 |
"source": [
|
1042 |
"Image(filename='runs/train/exp0/train_batch0.jpg', width=800) # train batch 0 mosaics and labels\n",
|
1043 |
-
"Image(filename='runs/train/exp0/
|
1044 |
"Image(filename='runs/train/exp0/test_batch0_pred.jpg', width=800) # test batch 0 predictions"
|
1045 |
],
|
1046 |
"execution_count": null,
|
@@ -1056,7 +1056,7 @@
|
|
1056 |
"`train_batch0.jpg` train batch 0 mosaics and labels\n",
|
1057 |
"\n",
|
1058 |
"> <img src=\"https://user-images.githubusercontent.com/26833433/83667626-8c37fe00-a583-11ea-997b-0923fe59b29b.jpeg\" width=\"750\"> \n",
|
1059 |
-
"`
|
1060 |
"\n",
|
1061 |
"> <img src=\"https://user-images.githubusercontent.com/26833433/83667635-90641b80-a583-11ea-8075-606316cebb9c.jpeg\" width=\"750\"> \n",
|
1062 |
"`test_batch0_pred.jpg` shows test batch 0 _predictions_\n"
|
|
|
605 |
"output_type": "stream",
|
606 |
"text": [
|
607 |
"Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', img_size=640, iou_thres=0.45, save_conf=False, save_dir='runs/detect', save_txt=False, source='data/images/', update=False, view_img=False, weights=['yolov5s.pt'])\n",
|
608 |
+
"Using torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16130MB)\n",
|
609 |
"\n",
|
610 |
"Fusing layers... \n",
|
611 |
"Model Summary: 140 layers, 7.45958e+06 parameters, 0 gradients\n",
|
|
|
735 |
"output_type": "stream",
|
736 |
"text": [
|
737 |
"Namespace(augment=False, batch_size=32, conf_thres=0.001, data='./data/coco.yaml', device='', img_size=640, iou_thres=0.65, save_conf=False, save_dir='runs/test', save_json=True, save_txt=False, single_cls=False, task='val', verbose=False, weights=['yolov5x.pt'])\n",
|
738 |
+
"Using torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16130MB)\n",
|
739 |
"\n",
|
740 |
"Downloading https://github.com/ultralytics/yolov5/releases/download/v3.1/yolov5x.pt to yolov5x.pt...\n",
|
741 |
"100% 170M/170M [00:05<00:00, 32.2MB/s]\n",
|
|
|
921 |
{
|
922 |
"output_type": "stream",
|
923 |
"text": [
|
924 |
+
"Using torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16130MB)\n",
|
925 |
"\n",
|
926 |
"Namespace(adam=False, batch_size=16, bucket='', cache_images=True, cfg='', data='./data/coco128.yaml', device='', epochs=3, evolve=False, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[640, 640], local_rank=-1, log_imgs=10, logdir='runs/', multi_scale=False, name='', noautoanchor=False, nosave=True, notest=False, rect=False, resume=False, single_cls=False, sync_bn=False, total_batch_size=16, weights='yolov5s.pt', workers=8, world_size=1)\n",
|
927 |
"Start Tensorboard with \"tensorboard --logdir runs/\", view at http://localhost:6006/\n",
|
|
|
1040 |
},
|
1041 |
"source": [
|
1042 |
"Image(filename='runs/train/exp0/train_batch0.jpg', width=800) # train batch 0 mosaics and labels\n",
|
1043 |
+
"Image(filename='runs/train/exp0/test_batch0_labels.jpg', width=800) # test batch 0 labels\n",
|
1044 |
"Image(filename='runs/train/exp0/test_batch0_pred.jpg', width=800) # test batch 0 predictions"
|
1045 |
],
|
1046 |
"execution_count": null,
|
|
|
1056 |
"`train_batch0.jpg` train batch 0 mosaics and labels\n",
|
1057 |
"\n",
|
1058 |
"> <img src=\"https://user-images.githubusercontent.com/26833433/83667626-8c37fe00-a583-11ea-997b-0923fe59b29b.jpeg\" width=\"750\"> \n",
|
1059 |
+
"`test_batch0_labels.jpg` shows test batch 0 labels\n",
|
1060 |
"\n",
|
1061 |
"> <img src=\"https://user-images.githubusercontent.com/26833433/83667635-90641b80-a583-11ea-8075-606316cebb9c.jpeg\" width=\"750\"> \n",
|
1062 |
"`test_batch0_pred.jpg` shows test batch 0 _predictions_\n"
|
utils/general.py
CHANGED
@@ -275,10 +275,10 @@ def ap_per_class(tp, conf, pred_cls, target_cls, plot=False, fname='precision-re
|
|
275 |
ap, p, r = np.zeros(s), np.zeros(s), np.zeros(s)
|
276 |
for ci, c in enumerate(unique_classes):
|
277 |
i = pred_cls == c
|
278 |
-
|
279 |
-
n_p = i.sum() #
|
280 |
|
281 |
-
if n_p == 0 or
|
282 |
continue
|
283 |
else:
|
284 |
# Accumulate FPs and TPs
|
@@ -286,7 +286,7 @@ def ap_per_class(tp, conf, pred_cls, target_cls, plot=False, fname='precision-re
|
|
286 |
tpc = tp[i].cumsum(0)
|
287 |
|
288 |
# Recall
|
289 |
-
recall = tpc / (
|
290 |
r[ci] = np.interp(-pr_score, -conf[i], recall[:, 0]) # r at pr_score, negative x, xp because xp decreases
|
291 |
|
292 |
# Precision
|
@@ -1076,8 +1076,8 @@ def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max
|
|
1076 |
image_targets = targets[targets[:, 0] == i]
|
1077 |
boxes = xywh2xyxy(image_targets[:, 2:6]).T
|
1078 |
classes = image_targets[:, 1].astype('int')
|
1079 |
-
|
1080 |
-
conf = None if
|
1081 |
|
1082 |
boxes[[0, 2]] *= w
|
1083 |
boxes[[0, 2]] += block_x
|
@@ -1087,8 +1087,8 @@ def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max
|
|
1087 |
cls = int(classes[j])
|
1088 |
color = color_lut[cls % len(color_lut)]
|
1089 |
cls = names[cls] if names else cls
|
1090 |
-
if
|
1091 |
-
label = '%s' % cls if
|
1092 |
plot_one_box(box, mosaic, label=label, color=color, line_thickness=tl)
|
1093 |
|
1094 |
# Draw image filename labels
|
|
|
275 |
ap, p, r = np.zeros(s), np.zeros(s), np.zeros(s)
|
276 |
for ci, c in enumerate(unique_classes):
|
277 |
i = pred_cls == c
|
278 |
+
n_l = (target_cls == c).sum() # number of labels
|
279 |
+
n_p = i.sum() # number of predictions
|
280 |
|
281 |
+
if n_p == 0 or n_l == 0:
|
282 |
continue
|
283 |
else:
|
284 |
# Accumulate FPs and TPs
|
|
|
286 |
tpc = tp[i].cumsum(0)
|
287 |
|
288 |
# Recall
|
289 |
+
recall = tpc / (n_l + 1e-16) # recall curve
|
290 |
r[ci] = np.interp(-pr_score, -conf[i], recall[:, 0]) # r at pr_score, negative x, xp because xp decreases
|
291 |
|
292 |
# Precision
|
|
|
1076 |
image_targets = targets[targets[:, 0] == i]
|
1077 |
boxes = xywh2xyxy(image_targets[:, 2:6]).T
|
1078 |
classes = image_targets[:, 1].astype('int')
|
1079 |
+
labels = image_targets.shape[1] == 6 # labels if no conf column
|
1080 |
+
conf = None if labels else image_targets[:, 6] # check for confidence presence (label vs pred)
|
1081 |
|
1082 |
boxes[[0, 2]] *= w
|
1083 |
boxes[[0, 2]] += block_x
|
|
|
1087 |
cls = int(classes[j])
|
1088 |
color = color_lut[cls % len(color_lut)]
|
1089 |
cls = names[cls] if names else cls
|
1090 |
+
if labels or conf[j] > 0.3: # 0.3 conf thresh
|
1091 |
+
label = '%s' % cls if labels else '%s %.1f' % (cls, conf[j])
|
1092 |
plot_one_box(box, mosaic, label=label, color=color, line_thickness=tl)
|
1093 |
|
1094 |
# Draw image filename labels
|