|
|
@@ -670,7 +670,7 @@ def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, merge=False, |
|
|
|
return output |
|
|
|
|
|
|
|
|
|
|
|
def strip_optimizer(f='weights/best.pt', s=''): # from utils.utils import *; strip_optimizer() |
|
|
|
def strip_optimizer(f='weights/best.pt', s=''): # from utils.general import *; strip_optimizer() |
|
|
|
# Strip optimizer from 'f' to finalize training, optionally save as 's' |
|
|
|
x = torch.load(f, map_location=torch.device('cpu')) |
|
|
|
x['optimizer'] = None |
|
|
@@ -695,7 +695,7 @@ def coco_class_count(path='../coco/labels/train2014/'): |
|
|
|
print(i, len(files)) |
|
|
|
|
|
|
|
|
|
|
|
def coco_only_people(path='../coco/labels/train2017/'): # from utils.utils import *; coco_only_people() |
|
|
|
def coco_only_people(path='../coco/labels/train2017/'): # from utils.general import *; coco_only_people() |
|
|
|
# Find images with only people |
|
|
|
files = sorted(glob.glob('%s/*.*' % path)) |
|
|
|
for i, file in enumerate(files): |
|
|
@@ -704,7 +704,7 @@ def coco_only_people(path='../coco/labels/train2017/'): # from utils.utils impo |
|
|
|
print(labels.shape[0], file) |
|
|
|
|
|
|
|
|
|
|
|
def crop_images_random(path='../images/', scale=0.50): # from utils.utils import *; crop_images_random() |
|
|
|
def crop_images_random(path='../images/', scale=0.50): # from utils.general import *; crop_images_random() |
|
|
|
# crops images into random squares up to scale fraction |
|
|
|
# WARNING: overwrites images! |
|
|
|
for file in tqdm(sorted(glob.glob('%s/*.*' % path))): |
|
|
@@ -728,7 +728,7 @@ def crop_images_random(path='../images/', scale=0.50): # from utils.utils impor |
|
|
|
|
|
|
|
|
|
|
|
def coco_single_class_labels(path='../coco/labels/train2014/', label_class=43): |
|
|
|
# Makes single-class coco datasets. from utils.utils import *; coco_single_class_labels() |
|
|
|
# Makes single-class coco datasets. from utils.general import *; coco_single_class_labels() |
|
|
|
if os.path.exists('new/'): |
|
|
|
shutil.rmtree('new/') # delete output folder |
|
|
|
os.makedirs('new/') # make new output folder |
|
|
@@ -763,7 +763,7 @@ def kmean_anchors(path='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen=10 |
|
|
|
k: kmeans evolved anchors |
|
|
|
|
|
|
|
Usage: |
|
|
|
from utils.utils import *; _ = kmean_anchors() |
|
|
|
from utils.general import *; _ = kmean_anchors() |
|
|
|
""" |
|
|
|
thr = 1. / thr |
|
|
|
|
|
|
@@ -986,7 +986,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.utils import *; plot_wh_methods() |
|
|
|
def plot_wh_methods(): # from utils.general 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) |
|
|
@@ -1107,7 +1107,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.utils import *; plot_test() |
|
|
|
def plot_test_txt(): # from utils.general import *; plot_test() |
|
|
|
# Plot test.txt histograms |
|
|
|
x = np.loadtxt('test.txt', dtype=np.float32) |
|
|
|
box = xyxy2xywh(x[:, :4]) |
|
|
@@ -1124,7 +1124,7 @@ def plot_test_txt(): # from utils.utils import *; plot_test() |
|
|
|
plt.savefig('hist1d.png', dpi=200) |
|
|
|
|
|
|
|
|
|
|
|
def plot_targets_txt(): # from utils.utils import *; plot_targets_txt() |
|
|
|
def plot_targets_txt(): # from utils.general 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'] |
|
|
@@ -1137,7 +1137,7 @@ def plot_targets_txt(): # from utils.utils import *; plot_targets_txt() |
|
|
|
plt.savefig('targets.jpg', dpi=200) |
|
|
|
|
|
|
|
|
|
|
|
def plot_study_txt(f='study.txt', x=None): # from utils.utils import *; plot_study_txt() |
|
|
|
def plot_study_txt(f='study.txt', x=None): # from utils.general 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() |
|
|
@@ -1188,7 +1188,7 @@ def plot_labels(labels, save_dir=''): |
|
|
|
plt.close() |
|
|
|
|
|
|
|
|
|
|
|
def plot_evolution(yaml_file='runs/evolve/hyp_evolved.yaml'): # from utils.utils import *; plot_evolution() |
|
|
|
def plot_evolution(yaml_file='runs/evolve/hyp_evolved.yaml'): # from utils.general import *; plot_evolution() |
|
|
|
# Plot hyperparameter evolution results in evolve.txt |
|
|
|
with open(yaml_file) as f: |
|
|
|
hyp = yaml.load(f, Loader=yaml.FullLoader) |
|
|
@@ -1212,7 +1212,7 @@ def plot_evolution(yaml_file='runs/evolve/hyp_evolved.yaml'): # from utils.util |
|
|
|
print('\nPlot saved as evolve.png') |
|
|
|
|
|
|
|
|
|
|
|
def plot_results_overlay(start=0, stop=0): # from utils.utils import *; plot_results_overlay() |
|
|
|
def plot_results_overlay(start=0, stop=0): # from utils.general 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 = ['GIoU', 'Objectness', 'Classification', 'P-R', 'mAP-F1'] # titles |
|
|
@@ -1236,7 +1236,7 @@ def plot_results_overlay(start=0, stop=0): # from utils.utils import *; plot_re |
|
|
|
|
|
|
|
|
|
|
|
def plot_results(start=0, stop=0, bucket='', id=(), labels=(), |
|
|
|
save_dir=''): # from utils.utils import *; plot_results() |
|
|
|
save_dir=''): # from utils.general import *; plot_results() |
|
|
|
# Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov5#reproduce-our-training |
|
|
|
fig, ax = plt.subplots(2, 5, figsize=(12, 6)) |
|
|
|
ax = ax.ravel() |