glenn-jocher commited on
Commit
67bf9a9
Β·
unverified Β·
1 Parent(s): 1c8464e

Replace 'ground truth' with 'labels' (#1337)

Browse files

* Replace 'ground truth' with 'labels'

* Using torch... update

Files changed (4) hide show
  1. README.md +1 -1
  2. test.py +5 -5
  3. tutorial.ipynb +5 -5
  4. 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 device0 _CudaDeviceProperties(name='Tesla V100-SXM2-16GB', total_memory=16160MB)
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}_gt.jpg' # filename
208
- plot_images(img, targets, paths, str(f), names) # ground truth
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
- cocoGt = COCO(glob.glob('../coco/annotations/instances_val*.json')[0]) # initialize COCO ground truth api
254
- cocoDt = cocoGt.loadRes(str(file)) # initialize COCO pred api
255
- cocoEval = COCOeval(cocoGt, cocoDt, 'bbox')
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 device0 _CudaDeviceProperties(name='Tesla V100-SXM2-16GB', total_memory=16130MB)\n",
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 device0 _CudaDeviceProperties(name='Tesla V100-SXM2-16GB', total_memory=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,7 +921,7 @@
921
  {
922
  "output_type": "stream",
923
  "text": [
924
- "Using CUDA device0 _CudaDeviceProperties(name='Tesla V100-SXM2-16GB', total_memory=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,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/test_batch0_gt.jpg', width=800) # test batch 0 ground truth\n",
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
- "`test_batch0_gt.jpg` shows test batch 0 ground truth\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"
 
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
- n_gt = (target_cls == c).sum() # Number of ground truth objects
279
- n_p = i.sum() # Number of predicted objects
280
 
281
- if n_p == 0 or n_gt == 0:
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 / (n_gt + 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,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
- gt = image_targets.shape[1] == 6 # ground truth if no conf column
1080
- conf = None if gt else image_targets[:, 6] # check for confidence presence (gt vs pred)
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 gt or conf[j] > 0.3: # 0.3 conf thresh
1091
- label = '%s' % cls if gt 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
 
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