|
|
|
|
|
|
|
|
cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA) |
|
|
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 |
|
|
# Compares the two methods for width-height anchor multiplication |
|
|
# https://github.com/ultralytics/yolov3/issues/168 |
|
|
# https://github.com/ultralytics/yolov3/issues/168 |
|
|
x = np.arange(-4.0, 4.0, .1) |
|
|
x = np.arange(-4.0, 4.0, .1) |
|
|
|
|
|
|
|
|
plt.savefig(Path(save_dir) / 'LR.png', dpi=200) |
|
|
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 |
|
|
# Plot test.txt histograms |
|
|
x = np.loadtxt('test.txt', dtype=np.float32) |
|
|
x = np.loadtxt('test.txt', dtype=np.float32) |
|
|
box = xyxy2xywh(x[:, :4]) |
|
|
box = xyxy2xywh(x[:, :4]) |
|
|
|
|
|
|
|
|
plt.savefig('hist1d.png', dpi=200) |
|
|
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 |
|
|
# Plot targets.txt histograms |
|
|
x = np.loadtxt('targets.txt', dtype=np.float32).T |
|
|
x = np.loadtxt('targets.txt', dtype=np.float32).T |
|
|
s = ['x targets', 'y targets', 'width targets', 'height targets'] |
|
|
s = ['x targets', 'y targets', 'width targets', 'height targets'] |
|
|
|
|
|
|
|
|
plt.savefig('targets.jpg', dpi=200) |
|
|
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 |
|
|
# Plot study.txt generated by test.py |
|
|
fig, ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True) |
|
|
fig, ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True) |
|
|
ax = ax.ravel() |
|
|
ax = ax.ravel() |
|
|
|
|
|
|
|
|
pass |
|
|
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 |
|
|
# Plot hyperparameter evolution results in evolve.txt |
|
|
with open(yaml_file) as f: |
|
|
with open(yaml_file) as f: |
|
|
hyp = yaml.load(f, Loader=yaml.FullLoader) |
|
|
hyp = yaml.load(f, Loader=yaml.FullLoader) |
|
|
|
|
|
|
|
|
print('\nPlot saved as evolve.png') |
|
|
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 |
|
|
# 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 |
|
|
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 |
|
|
t = ['Box', 'Objectness', 'Classification', 'P-R', 'mAP-F1'] # titles |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def plot_results(start=0, stop=0, bucket='', id=(), labels=(), save_dir=''): |
|
|
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)) |
|
|
fig, ax = plt.subplots(2, 5, figsize=(12, 6)) |
|
|
ax = ax.ravel() |
|
|
ax = ax.ravel() |
|
|
s = ['Box', 'Objectness', 'Classification', 'Precision', 'Recall', |
|
|
s = ['Box', 'Objectness', 'Classification', 'Precision', 'Recall', |
|
|
'val Box', 'val Objectness', 'val Classification', 'mAP@0.5', 'mAP@0.5:0.95'] |
|
|
'val Box', 'val Objectness', 'val Classification', 'mAP@0.5', 'mAP@0.5:0.95'] |
|
|
if bucket: |
|
|
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 = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id] |
|
|
files = ['results%g.txt' % 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) |
|
|
c = ('gsutil cp ' + '%s ' * len(files) + '.') % tuple('gs://%s/results%g.txt' % (bucket, x) for x in id) |
|
|
os.system(c) |
|
|
os.system(c) |
|
|
else: |
|
|
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) |
|
|
assert len(files), 'No results.txt files found in %s, nothing to plot.' % os.path.abspath(save_dir) |
|
|
for fi, f in enumerate(files): |
|
|
for fi, f in enumerate(files): |
|
|
try: |
|
|
try: |
|
|
|
|
|
|
|
|
if i in [0, 1, 2, 5, 6, 7]: |
|
|
if i in [0, 1, 2, 5, 6, 7]: |
|
|
y[y == 0] = np.nan # don't show zero loss values |
|
|
y[y == 0] = np.nan # don't show zero loss values |
|
|
# y /= y[0] # normalize |
|
|
# 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].plot(x, y, marker='.', label=label, linewidth=1, markersize=6) |
|
|
ax[i].set_title(s[i]) |
|
|
ax[i].set_title(s[i]) |
|
|
# if i in [5, 6, 7]: # share train and val loss y axes |
|
|
# if i in [5, 6, 7]: # share train and val loss y axes |