glenn-jocher commited on
Commit
4f44aaf
1 Parent(s): f129cdd
Files changed (1) hide show
  1. utils/utils.py +22 -7
utils/utils.py CHANGED
@@ -471,6 +471,7 @@ def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, multi_label=T
471
  # Settings
472
  merge = True # merge for best mAP
473
  min_wh, max_wh = 2, 4096 # (pixels) minimum and maximum box width and height
 
474
  time_limit = 10.0 # seconds to quit after
475
 
476
  t = time.time()
@@ -520,6 +521,8 @@ def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, multi_label=T
520
  c = x[:, 5] * 0 if agnostic else x[:, 5] # classes
521
  boxes, scores = x[:, :4].clone() + c.view(-1, 1) * max_wh, x[:, 4] # boxes (offset by class), scores
522
  i = torchvision.ops.boxes.nms(boxes, scores, iou_thres)
 
 
523
  if merge and (1 < n < 3E3): # Merge NMS (boxes merged using weighted mean)
524
  try: # update boxes as boxes(i,4) = weights(i,n) * boxes(n,4)
525
  iou = box_iou(boxes[i], boxes) > iou_thres # iou matrix
@@ -975,15 +978,27 @@ def plot_targets_txt(): # from utils.utils import *; plot_targets_txt()
975
 
976
  def plot_study_txt(f='study.txt', x=None): # from utils.utils import *; plot_study_txt()
977
  # Plot study.txt generated by test.py
978
- y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T
979
- x = np.arange(y.shape[1]) if x is None else np.array(x)
980
- s = ['P', 'R', '[email protected]', '[email protected]:.95', 't_inference (ms/img)', 't_NMS (ms/img)', 't_total (ms/img)']
981
  fig, ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True)
982
  ax = ax.ravel()
983
- for i in range(7):
984
- ax[i].plot(x, y[i], '.-', linewidth=2, markersize=8)
985
- ax[i].set_title(s[i])
986
- plt.savefig(f.replace('.txt','.png'), dpi=200)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
987
 
988
 
989
  def plot_labels(labels):
 
471
  # Settings
472
  merge = True # merge for best mAP
473
  min_wh, max_wh = 2, 4096 # (pixels) minimum and maximum box width and height
474
+ max_det = 300 # maximum number of detections per image
475
  time_limit = 10.0 # seconds to quit after
476
 
477
  t = time.time()
 
521
  c = x[:, 5] * 0 if agnostic else x[:, 5] # classes
522
  boxes, scores = x[:, :4].clone() + c.view(-1, 1) * max_wh, x[:, 4] # boxes (offset by class), scores
523
  i = torchvision.ops.boxes.nms(boxes, scores, iou_thres)
524
+ if i.shape[0] > max_det: # limit detections
525
+ i = i[:max_det]
526
  if merge and (1 < n < 3E3): # Merge NMS (boxes merged using weighted mean)
527
  try: # update boxes as boxes(i,4) = weights(i,n) * boxes(n,4)
528
  iou = box_iou(boxes[i], boxes) > iou_thres # iou matrix
 
978
 
979
  def plot_study_txt(f='study.txt', x=None): # from utils.utils import *; plot_study_txt()
980
  # Plot study.txt generated by test.py
 
 
 
981
  fig, ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True)
982
  ax = ax.ravel()
983
+
984
+ for f in glob.glob('study*.txt'):
985
+ y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T
986
+ x = np.arange(y.shape[1]) if x is None else np.array(x)
987
+ s = ['P', 'R', '[email protected]', '[email protected]:.95', 't_inference (ms/img)', 't_NMS (ms/img)', 't_total (ms/img)']
988
+ for i in range(7):
989
+ ax[i].plot(x, y[i], '.-', linewidth=2, markersize=8)
990
+ ax[i].set_title(s[i])
991
+
992
+ j = y[3].argmax() + 1
993
+ ax[7].plot(y[6, :j], y[3, :j] * 1E2, '.-', linewidth=2, markersize=8, label=Path(f).stem)
994
+ ax[7].plot(1E3 / np.array([209, 140, 97, 58, 35, 18]), [33.5, 39.1, 42.5, 45.9, 49., 50.5],
995
+ '.-', linewidth=2, markersize=8, label='EfficientDet')
996
+ ax[7].set_xlabel('Latency (ms)')
997
+ ax[7].set_ylabel('COCO AP val')
998
+
999
+ ax[7].legend()
1000
+ ax[7].set_xlim(0)
1001
+ plt.savefig(f.replace('.txt', '.png'), dpi=200)
1002
 
1003
 
1004
  def plot_labels(labels):