|
|
@@ -65,7 +65,7 @@ def plot_one_box(x, img, color=None, label=None, line_thickness=None): |
|
|
|
cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA) |
|
|
|
|
|
|
|
|
|
|
|
def plot_wh_methods(): # from utils.general import *; plot_wh_methods() |
|
|
|
def plot_wh_methods(): # from utils.plots import *; plot_wh_methods() |
|
|
|
# Compares the two methods for width-height anchor multiplication |
|
|
|
# https://github.com/ultralytics/yolov3/issues/168 |
|
|
|
x = np.arange(-4.0, 4.0, .1) |
|
|
@@ -200,7 +200,7 @@ def plot_lr_scheduler(optimizer, scheduler, epochs=300, save_dir=''): |
|
|
|
plt.savefig(Path(save_dir) / 'LR.png', dpi=200) |
|
|
|
|
|
|
|
|
|
|
|
def plot_test_txt(): # from utils.general import *; plot_test() |
|
|
|
def plot_test_txt(): # from utils.plots import *; plot_test() |
|
|
|
# Plot test.txt histograms |
|
|
|
x = np.loadtxt('test.txt', dtype=np.float32) |
|
|
|
box = xyxy2xywh(x[:, :4]) |
|
|
@@ -217,7 +217,7 @@ def plot_test_txt(): # from utils.general import *; plot_test() |
|
|
|
plt.savefig('hist1d.png', dpi=200) |
|
|
|
|
|
|
|
|
|
|
|
def plot_targets_txt(): # from utils.general import *; plot_targets_txt() |
|
|
|
def plot_targets_txt(): # from utils.plots import *; plot_targets_txt() |
|
|
|
# Plot targets.txt histograms |
|
|
|
x = np.loadtxt('targets.txt', dtype=np.float32).T |
|
|
|
s = ['x targets', 'y targets', 'width targets', 'height targets'] |
|
|
@@ -230,7 +230,7 @@ def plot_targets_txt(): # from utils.general import *; plot_targets_txt() |
|
|
|
plt.savefig('targets.jpg', dpi=200) |
|
|
|
|
|
|
|
|
|
|
|
def plot_study_txt(f='study.txt', x=None): # from utils.general import *; plot_study_txt() |
|
|
|
def plot_study_txt(f='study.txt', x=None): # from utils.plots import *; plot_study_txt() |
|
|
|
# Plot study.txt generated by test.py |
|
|
|
fig, ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True) |
|
|
|
ax = ax.ravel() |
|
|
@@ -294,7 +294,7 @@ def plot_labels(labels, save_dir=''): |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.general import *; plot_evolution() |
|
|
|
def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.plots import *; plot_evolution() |
|
|
|
# Plot hyperparameter evolution results in evolve.txt |
|
|
|
with open(yaml_file) as f: |
|
|
|
hyp = yaml.load(f, Loader=yaml.FullLoader) |
|
|
@@ -318,7 +318,7 @@ def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.general im |
|
|
|
print('\nPlot saved as evolve.png') |
|
|
|
|
|
|
|
|
|
|
|
def plot_results_overlay(start=0, stop=0): # from utils.general import *; plot_results_overlay() |
|
|
|
def plot_results_overlay(start=0, stop=0): # from utils.plots import *; plot_results_overlay() |
|
|
|
# Plot training 'results*.txt', overlaying train and val losses |
|
|
|
s = ['train', 'train', 'train', 'Precision', 'mAP@0.5', 'val', 'val', 'val', 'Recall', 'mAP@0.5:0.95'] # legends |
|
|
|
t = ['Box', 'Objectness', 'Classification', 'P-R', 'mAP-F1'] # titles |
|
|
@@ -342,20 +342,18 @@ def plot_results_overlay(start=0, stop=0): # from utils.general import *; plot_ |
|
|
|
|
|
|
|
|
|
|
|
def plot_results(start=0, stop=0, bucket='', id=(), labels=(), save_dir=''): |
|
|
|
# from utils.general import *; plot_results(save_dir='runs/train/exp0') |
|
|
|
# Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov5#reproduce-our-training |
|
|
|
# Plot training 'results*.txt'. from utils.plots import *; plot_results(save_dir='runs/train/exp') |
|
|
|
fig, ax = plt.subplots(2, 5, figsize=(12, 6)) |
|
|
|
ax = ax.ravel() |
|
|
|
s = ['Box', 'Objectness', 'Classification', 'Precision', 'Recall', |
|
|
|
'val Box', 'val Objectness', 'val Classification', 'mAP@0.5', 'mAP@0.5:0.95'] |
|
|
|
if bucket: |
|
|
|
# os.system('rm -rf storage.googleapis.com') |
|
|
|
# files = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id] |
|
|
|
files = ['results%g.txt' % x for x in id] |
|
|
|
c = ('gsutil cp ' + '%s ' * len(files) + '.') % tuple('gs://%s/results%g.txt' % (bucket, x) for x in id) |
|
|
|
os.system(c) |
|
|
|
else: |
|
|
|
files = glob.glob(str(Path(save_dir) / 'results*.txt')) + glob.glob('../../Downloads/results*.txt') |
|
|
|
files = list(Path(save_dir).glob('results*.txt')) |
|
|
|
assert len(files), 'No results.txt files found in %s, nothing to plot.' % os.path.abspath(save_dir) |
|
|
|
for fi, f in enumerate(files): |
|
|
|
try: |
|
|
@@ -367,7 +365,7 @@ def plot_results(start=0, stop=0, bucket='', id=(), labels=(), save_dir=''): |
|
|
|
if i in [0, 1, 2, 5, 6, 7]: |
|
|
|
y[y == 0] = np.nan # don't show zero loss values |
|
|
|
# y /= y[0] # normalize |
|
|
|
label = labels[fi] if len(labels) else Path(f).stem |
|
|
|
label = labels[fi] if len(labels) else f.stem |
|
|
|
ax[i].plot(x, y, marker='.', label=label, linewidth=1, markersize=6) |
|
|
|
ax[i].set_title(s[i]) |
|
|
|
# if i in [5, 6, 7]: # share train and val loss y axes |