glenn-jocher commited on
Commit
27a4736
1 Parent(s): 3beb871

Fix val.py study plot (#4831)

Browse files

* Fix val.py study plot

* call plot_val_study

* Rename plot_study_txt to plot_val_study

Files changed (2) hide show
  1. utils/plots.py +7 -4
  2. val.py +2 -2
utils/plots.py CHANGED
@@ -247,15 +247,16 @@ def plot_targets_txt(): # from utils.plots import *; plot_targets_txt()
247
  plt.savefig('targets.jpg', dpi=200)
248
 
249
 
250
- def plot_study_txt(path='', x=None): # from utils.plots import *; plot_study_txt()
251
- # Plot study.txt generated by val.py
 
252
  plot2 = False # plot additional results
253
  if plot2:
254
  ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True)[1].ravel()
255
 
256
  fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True)
257
  # for f in [Path(path) / f'study_coco_{x}.txt' for x in ['yolov5s6', 'yolov5m6', 'yolov5l6', 'yolov5x6']]:
258
- for f in sorted(Path(path).glob('study*.txt')):
259
  y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T
260
  x = np.arange(y.shape[1]) if x is None else np.array(x)
261
  if plot2:
@@ -278,7 +279,9 @@ def plot_study_txt(path='', x=None): # from utils.plots import *; plot_study_tx
278
  ax2.set_xlabel('GPU Speed (ms/img)')
279
  ax2.set_ylabel('COCO AP val')
280
  ax2.legend(loc='lower right')
281
- plt.savefig(str(Path(path).name) + '.png', dpi=300)
 
 
282
 
283
 
284
  def plot_labels(labels, names=(), save_dir=Path('')):
 
247
  plt.savefig('targets.jpg', dpi=200)
248
 
249
 
250
+ def plot_val_study(file='', dir='', x=None): # from utils.plots import *; plot_val_study()
251
+ # Plot file=study.txt generated by val.py (or plot all study*.txt in dir)
252
+ save_dir = Path(file).parent if file else Path(dir)
253
  plot2 = False # plot additional results
254
  if plot2:
255
  ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True)[1].ravel()
256
 
257
  fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True)
258
  # for f in [Path(path) / f'study_coco_{x}.txt' for x in ['yolov5s6', 'yolov5m6', 'yolov5l6', 'yolov5x6']]:
259
+ for f in sorted(save_dir.glob('study*.txt')):
260
  y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T
261
  x = np.arange(y.shape[1]) if x is None else np.array(x)
262
  if plot2:
 
279
  ax2.set_xlabel('GPU Speed (ms/img)')
280
  ax2.set_ylabel('COCO AP val')
281
  ax2.legend(loc='lower right')
282
+ f = save_dir / 'study.png'
283
+ print(f'Saving {f}...')
284
+ plt.savefig(f, dpi=300)
285
 
286
 
287
  def plot_labels(labels, names=(), save_dir=Path('')):
val.py CHANGED
@@ -26,7 +26,7 @@ from utils.general import coco80_to_coco91_class, check_dataset, check_img_size,
26
  check_suffix, check_yaml, box_iou, non_max_suppression, scale_coords, xyxy2xywh, xywh2xyxy, set_logging, \
27
  increment_path, colorstr
28
  from utils.metrics import ap_per_class, ConfusionMatrix
29
- from utils.plots import plot_images, output_to_target, plot_study_txt
30
  from utils.torch_utils import select_device, time_sync
31
  from utils.callbacks import Callbacks
32
 
@@ -348,7 +348,7 @@ def main(opt):
348
  y.append(r + t) # results and times
349
  np.savetxt(f, y, fmt='%10.4g') # save
350
  os.system('zip -r study.zip study_*.txt')
351
- plot_study_txt(x=x) # plot
352
 
353
 
354
  if __name__ == "__main__":
 
26
  check_suffix, check_yaml, box_iou, non_max_suppression, scale_coords, xyxy2xywh, xywh2xyxy, set_logging, \
27
  increment_path, colorstr
28
  from utils.metrics import ap_per_class, ConfusionMatrix
29
+ from utils.plots import output_to_target, plot_images, plot_val_study
30
  from utils.torch_utils import select_device, time_sync
31
  from utils.callbacks import Callbacks
32
 
 
348
  y.append(r + t) # results and times
349
  np.savetxt(f, y, fmt='%10.4g') # save
350
  os.system('zip -r study.zip study_*.txt')
351
+ plot_val_study(x=x) # plot
352
 
353
 
354
  if __name__ == "__main__":