glenn-jocher commited on
Commit
c654d18
1 Parent(s): e6e7e7f

Update utils.py

Browse files
Files changed (1) hide show
  1. utils/utils.py +7 -7
utils/utils.py CHANGED
@@ -1034,7 +1034,7 @@ def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max
1034
  return mosaic
1035
 
1036
 
1037
- def plot_lr_scheduler(optimizer, scheduler, epochs=300, save_dir='./'):
1038
  # Plot LR simulating training for full epochs
1039
  optimizer, scheduler = copy(optimizer), copy(scheduler) # do not modify originals
1040
  y = []
@@ -1048,7 +1048,7 @@ def plot_lr_scheduler(optimizer, scheduler, epochs=300, save_dir='./'):
1048
  plt.xlim(0, epochs)
1049
  plt.ylim(0)
1050
  plt.tight_layout()
1051
- plt.savefig(os.path.join(save_dir, 'LR.png'), dpi=200)
1052
 
1053
 
1054
  def plot_test_txt(): # from utils.utils import *; plot_test()
@@ -1113,7 +1113,7 @@ def plot_study_txt(f='study.txt', x=None): # from utils.utils import *; plot_st
1113
  plt.savefig(f.replace('.txt', '.png'), dpi=200)
1114
 
1115
 
1116
- def plot_labels(labels, save_dir= '.'):
1117
  # plot dataset labels
1118
  c, b = labels[:, 0], labels[:, 1:].transpose() # classees, boxes
1119
 
@@ -1134,7 +1134,7 @@ def plot_labels(labels, save_dir= '.'):
1134
  ax[2].scatter(b[2], b[3], c=hist2d(b[2], b[3], 90), cmap='jet')
1135
  ax[2].set_xlabel('width')
1136
  ax[2].set_ylabel('height')
1137
- plt.savefig(os.path.join(save_dir,'labels.png'), dpi=200)
1138
  plt.close()
1139
 
1140
 
@@ -1180,7 +1180,7 @@ def plot_results_overlay(start=0, stop=0): # from utils.utils import *; plot_re
1180
  fig.savefig(f.replace('.txt', '.png'), dpi=200)
1181
 
1182
 
1183
- def plot_results(start=0, stop=0, bucket='', id=(), labels=(), save_dir= '.'): # from utils.utils import *; plot_results()
1184
  # Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov5#reproduce-our-training
1185
  fig, ax = plt.subplots(2, 5, figsize=(12, 6))
1186
  ax = ax.ravel()
@@ -1190,7 +1190,7 @@ def plot_results(start=0, stop=0, bucket='', id=(), labels=(), save_dir= '.'):
1190
  os.system('rm -rf storage.googleapis.com')
1191
  files = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id]
1192
  else:
1193
- files = glob.glob(os.path.join(save_dir,'results*.txt')) + glob.glob('../../Downloads/results*.txt')
1194
  for fi, f in enumerate(files):
1195
  try:
1196
  results = np.loadtxt(f, usecols=[2, 3, 4, 8, 9, 12, 13, 14, 10, 11], ndmin=2).T
@@ -1211,4 +1211,4 @@ def plot_results(start=0, stop=0, bucket='', id=(), labels=(), save_dir= '.'):
1211
 
1212
  fig.tight_layout()
1213
  ax[1].legend()
1214
- fig.savefig('results.png', dpi=200)
 
1034
  return mosaic
1035
 
1036
 
1037
+ def plot_lr_scheduler(optimizer, scheduler, epochs=300, save_dir=''):
1038
  # Plot LR simulating training for full epochs
1039
  optimizer, scheduler = copy(optimizer), copy(scheduler) # do not modify originals
1040
  y = []
 
1048
  plt.xlim(0, epochs)
1049
  plt.ylim(0)
1050
  plt.tight_layout()
1051
+ plt.savefig(Path(save_dir) / 'LR.png', dpi=200)
1052
 
1053
 
1054
  def plot_test_txt(): # from utils.utils import *; plot_test()
 
1113
  plt.savefig(f.replace('.txt', '.png'), dpi=200)
1114
 
1115
 
1116
+ def plot_labels(labels, save_dir= ''):
1117
  # plot dataset labels
1118
  c, b = labels[:, 0], labels[:, 1:].transpose() # classees, boxes
1119
 
 
1134
  ax[2].scatter(b[2], b[3], c=hist2d(b[2], b[3], 90), cmap='jet')
1135
  ax[2].set_xlabel('width')
1136
  ax[2].set_ylabel('height')
1137
+ plt.savefig(Path(save_dir) / 'labels.png', dpi=200)
1138
  plt.close()
1139
 
1140
 
 
1180
  fig.savefig(f.replace('.txt', '.png'), dpi=200)
1181
 
1182
 
1183
+ def plot_results(start=0, stop=0, bucket='', id=(), labels=(), save_dir= ''): # from utils.utils import *; plot_results()
1184
  # Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov5#reproduce-our-training
1185
  fig, ax = plt.subplots(2, 5, figsize=(12, 6))
1186
  ax = ax.ravel()
 
1190
  os.system('rm -rf storage.googleapis.com')
1191
  files = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id]
1192
  else:
1193
+ files = glob.glob(str(Path(save_dir) / 'results*.txt')) + glob.glob('../../Downloads/results*.txt')
1194
  for fi, f in enumerate(files):
1195
  try:
1196
  results = np.loadtxt(f, usecols=[2, 3, 4, 8, 9, 12, 13, 14, 10, 11], ndmin=2).T
 
1211
 
1212
  fig.tight_layout()
1213
  ax[1].legend()
1214
+ fig.savefig(Path(save_dir) / 'results.png', dpi=200)