Commit
·
9f482cb
1
Parent(s):
4949401
utils.general comment updates/bug fixes
Browse files- Dockerfile +1 -1
- detect.py +1 -1
- tutorial.ipynb +2 -2
- utils/general.py +12 -12
Dockerfile
CHANGED
@@ -43,7 +43,7 @@ COPY . /usr/src/app
|
|
43 |
# sudo docker commit 092b16b25c5b usr/resume && sudo docker run -it --gpus all --ipc=host -v "$(pwd)"/coco:/usr/src/coco --entrypoint=sh usr/resume
|
44 |
|
45 |
# Send weights to GCP
|
46 |
-
# python -c "from utils.
|
47 |
|
48 |
# Clean up
|
49 |
# docker system prune -a --volumes
|
|
|
43 |
# sudo docker commit 092b16b25c5b usr/resume && sudo docker run -it --gpus all --ipc=host -v "$(pwd)"/coco:/usr/src/coco --entrypoint=sh usr/resume
|
44 |
|
45 |
# Send weights to GCP
|
46 |
+
# python -c "from utils.general import *; strip_optimizer('runs/exp0_*/weights/last.pt', 'tmp.pt')" && gsutil cp tmp.pt gs://*
|
47 |
|
48 |
# Clean up
|
49 |
# docker system prune -a --volumes
|
detect.py
CHANGED
@@ -138,7 +138,7 @@ def detect(save_img=False):
|
|
138 |
|
139 |
if save_txt or save_img:
|
140 |
print('Results saved to %s' % Path(out))
|
141 |
-
if platform == '
|
142 |
os.system('open ' + save_path)
|
143 |
|
144 |
print('Done. (%.3fs)' % (time.time() - t0))
|
|
|
138 |
|
139 |
if save_txt or save_img:
|
140 |
print('Results saved to %s' % Path(out))
|
141 |
+
if platform.system() == 'Darwin' and not opt.update: # MacOS
|
142 |
os.system('open ' + save_path)
|
143 |
|
144 |
print('Done. (%.3fs)' % (time.time() - t0))
|
tutorial.ipynb
CHANGED
@@ -622,7 +622,7 @@
|
|
622 |
"colab_type": "text"
|
623 |
},
|
624 |
"source": [
|
625 |
-
"Training losses and performance metrics are saved to Tensorboard and also to a `runs/exp0/results.txt` logfile. `results.txt` is plotted as `results.png` after training completes. Partially completed `results.txt` files can be plotted with `from utils.
|
626 |
]
|
627 |
},
|
628 |
{
|
@@ -637,7 +637,7 @@
|
|
637 |
"outputId": "c1146425-643e-49ab-de25-73216f0dde23"
|
638 |
},
|
639 |
"source": [
|
640 |
-
"from utils.
|
641 |
],
|
642 |
"execution_count": null,
|
643 |
"outputs": [
|
|
|
622 |
"colab_type": "text"
|
623 |
},
|
624 |
"source": [
|
625 |
+
"Training losses and performance metrics are saved to Tensorboard and also to a `runs/exp0/results.txt` logfile. `results.txt` is plotted as `results.png` after training completes. Partially completed `results.txt` files can be plotted with `from utils.general import plot_results; plot_results()`. Here we show YOLOv5s trained on coco128 to 300 epochs, starting from scratch (blue), and from pretrained `yolov5s.pt` (orange)."
|
626 |
]
|
627 |
},
|
628 |
{
|
|
|
637 |
"outputId": "c1146425-643e-49ab-de25-73216f0dde23"
|
638 |
},
|
639 |
"source": [
|
640 |
+
"from utils.general import plot_results; plot_results() # plot results.txt files as results.png"
|
641 |
],
|
642 |
"execution_count": null,
|
643 |
"outputs": [
|
utils/general.py
CHANGED
@@ -670,7 +670,7 @@ def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, merge=False,
|
|
670 |
return output
|
671 |
|
672 |
|
673 |
-
def strip_optimizer(f='weights/best.pt', s=''): # from utils.
|
674 |
# Strip optimizer from 'f' to finalize training, optionally save as 's'
|
675 |
x = torch.load(f, map_location=torch.device('cpu'))
|
676 |
x['optimizer'] = None
|
@@ -695,7 +695,7 @@ def coco_class_count(path='../coco/labels/train2014/'):
|
|
695 |
print(i, len(files))
|
696 |
|
697 |
|
698 |
-
def coco_only_people(path='../coco/labels/train2017/'): # from utils.
|
699 |
# Find images with only people
|
700 |
files = sorted(glob.glob('%s/*.*' % path))
|
701 |
for i, file in enumerate(files):
|
@@ -704,7 +704,7 @@ def coco_only_people(path='../coco/labels/train2017/'): # from utils.utils impo
|
|
704 |
print(labels.shape[0], file)
|
705 |
|
706 |
|
707 |
-
def crop_images_random(path='../images/', scale=0.50): # from utils.
|
708 |
# crops images into random squares up to scale fraction
|
709 |
# WARNING: overwrites images!
|
710 |
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
|
|
728 |
|
729 |
|
730 |
def coco_single_class_labels(path='../coco/labels/train2014/', label_class=43):
|
731 |
-
# Makes single-class coco datasets. from utils.
|
732 |
if os.path.exists('new/'):
|
733 |
shutil.rmtree('new/') # delete output folder
|
734 |
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
|
|
763 |
k: kmeans evolved anchors
|
764 |
|
765 |
Usage:
|
766 |
-
from utils.
|
767 |
"""
|
768 |
thr = 1. / thr
|
769 |
|
@@ -986,7 +986,7 @@ def plot_one_box(x, img, color=None, label=None, line_thickness=None):
|
|
986 |
cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)
|
987 |
|
988 |
|
989 |
-
def plot_wh_methods(): # from utils.
|
990 |
# Compares the two methods for width-height anchor multiplication
|
991 |
# https://github.com/ultralytics/yolov3/issues/168
|
992 |
x = np.arange(-4.0, 4.0, .1)
|
@@ -1107,7 +1107,7 @@ def plot_lr_scheduler(optimizer, scheduler, epochs=300, save_dir=''):
|
|
1107 |
plt.savefig(Path(save_dir) / 'LR.png', dpi=200)
|
1108 |
|
1109 |
|
1110 |
-
def plot_test_txt(): # from utils.
|
1111 |
# Plot test.txt histograms
|
1112 |
x = np.loadtxt('test.txt', dtype=np.float32)
|
1113 |
box = xyxy2xywh(x[:, :4])
|
@@ -1124,7 +1124,7 @@ def plot_test_txt(): # from utils.utils import *; plot_test()
|
|
1124 |
plt.savefig('hist1d.png', dpi=200)
|
1125 |
|
1126 |
|
1127 |
-
def plot_targets_txt(): # from utils.
|
1128 |
# Plot targets.txt histograms
|
1129 |
x = np.loadtxt('targets.txt', dtype=np.float32).T
|
1130 |
s = ['x targets', 'y targets', 'width targets', 'height targets']
|
@@ -1137,7 +1137,7 @@ def plot_targets_txt(): # from utils.utils import *; plot_targets_txt()
|
|
1137 |
plt.savefig('targets.jpg', dpi=200)
|
1138 |
|
1139 |
|
1140 |
-
def plot_study_txt(f='study.txt', x=None): # from utils.
|
1141 |
# Plot study.txt generated by test.py
|
1142 |
fig, ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True)
|
1143 |
ax = ax.ravel()
|
@@ -1188,7 +1188,7 @@ def plot_labels(labels, save_dir=''):
|
|
1188 |
plt.close()
|
1189 |
|
1190 |
|
1191 |
-
def plot_evolution(yaml_file='runs/evolve/hyp_evolved.yaml'): # from utils.
|
1192 |
# Plot hyperparameter evolution results in evolve.txt
|
1193 |
with open(yaml_file) as f:
|
1194 |
hyp = yaml.load(f, Loader=yaml.FullLoader)
|
@@ -1212,7 +1212,7 @@ def plot_evolution(yaml_file='runs/evolve/hyp_evolved.yaml'): # from utils.util
|
|
1212 |
print('\nPlot saved as evolve.png')
|
1213 |
|
1214 |
|
1215 |
-
def plot_results_overlay(start=0, stop=0): # from utils.
|
1216 |
# Plot training 'results*.txt', overlaying train and val losses
|
1217 |
s = ['train', 'train', 'train', 'Precision', '[email protected]', 'val', 'val', 'val', 'Recall', '[email protected]:0.95'] # legends
|
1218 |
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
|
|
1236 |
|
1237 |
|
1238 |
def plot_results(start=0, stop=0, bucket='', id=(), labels=(),
|
1239 |
-
save_dir=''): # from utils.
|
1240 |
# Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov5#reproduce-our-training
|
1241 |
fig, ax = plt.subplots(2, 5, figsize=(12, 6))
|
1242 |
ax = ax.ravel()
|
|
|
670 |
return output
|
671 |
|
672 |
|
673 |
+
def strip_optimizer(f='weights/best.pt', s=''): # from utils.general import *; strip_optimizer()
|
674 |
# Strip optimizer from 'f' to finalize training, optionally save as 's'
|
675 |
x = torch.load(f, map_location=torch.device('cpu'))
|
676 |
x['optimizer'] = None
|
|
|
695 |
print(i, len(files))
|
696 |
|
697 |
|
698 |
+
def coco_only_people(path='../coco/labels/train2017/'): # from utils.general import *; coco_only_people()
|
699 |
# Find images with only people
|
700 |
files = sorted(glob.glob('%s/*.*' % path))
|
701 |
for i, file in enumerate(files):
|
|
|
704 |
print(labels.shape[0], file)
|
705 |
|
706 |
|
707 |
+
def crop_images_random(path='../images/', scale=0.50): # from utils.general import *; crop_images_random()
|
708 |
# crops images into random squares up to scale fraction
|
709 |
# WARNING: overwrites images!
|
710 |
for file in tqdm(sorted(glob.glob('%s/*.*' % path))):
|
|
|
728 |
|
729 |
|
730 |
def coco_single_class_labels(path='../coco/labels/train2014/', label_class=43):
|
731 |
+
# Makes single-class coco datasets. from utils.general import *; coco_single_class_labels()
|
732 |
if os.path.exists('new/'):
|
733 |
shutil.rmtree('new/') # delete output folder
|
734 |
os.makedirs('new/') # make new output folder
|
|
|
763 |
k: kmeans evolved anchors
|
764 |
|
765 |
Usage:
|
766 |
+
from utils.general import *; _ = kmean_anchors()
|
767 |
"""
|
768 |
thr = 1. / thr
|
769 |
|
|
|
986 |
cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)
|
987 |
|
988 |
|
989 |
+
def plot_wh_methods(): # from utils.general import *; plot_wh_methods()
|
990 |
# Compares the two methods for width-height anchor multiplication
|
991 |
# https://github.com/ultralytics/yolov3/issues/168
|
992 |
x = np.arange(-4.0, 4.0, .1)
|
|
|
1107 |
plt.savefig(Path(save_dir) / 'LR.png', dpi=200)
|
1108 |
|
1109 |
|
1110 |
+
def plot_test_txt(): # from utils.general import *; plot_test()
|
1111 |
# Plot test.txt histograms
|
1112 |
x = np.loadtxt('test.txt', dtype=np.float32)
|
1113 |
box = xyxy2xywh(x[:, :4])
|
|
|
1124 |
plt.savefig('hist1d.png', dpi=200)
|
1125 |
|
1126 |
|
1127 |
+
def plot_targets_txt(): # from utils.general import *; plot_targets_txt()
|
1128 |
# Plot targets.txt histograms
|
1129 |
x = np.loadtxt('targets.txt', dtype=np.float32).T
|
1130 |
s = ['x targets', 'y targets', 'width targets', 'height targets']
|
|
|
1137 |
plt.savefig('targets.jpg', dpi=200)
|
1138 |
|
1139 |
|
1140 |
+
def plot_study_txt(f='study.txt', x=None): # from utils.general import *; plot_study_txt()
|
1141 |
# Plot study.txt generated by test.py
|
1142 |
fig, ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True)
|
1143 |
ax = ax.ravel()
|
|
|
1188 |
plt.close()
|
1189 |
|
1190 |
|
1191 |
+
def plot_evolution(yaml_file='runs/evolve/hyp_evolved.yaml'): # from utils.general import *; plot_evolution()
|
1192 |
# Plot hyperparameter evolution results in evolve.txt
|
1193 |
with open(yaml_file) as f:
|
1194 |
hyp = yaml.load(f, Loader=yaml.FullLoader)
|
|
|
1212 |
print('\nPlot saved as evolve.png')
|
1213 |
|
1214 |
|
1215 |
+
def plot_results_overlay(start=0, stop=0): # from utils.general import *; plot_results_overlay()
|
1216 |
# Plot training 'results*.txt', overlaying train and val losses
|
1217 |
s = ['train', 'train', 'train', 'Precision', '[email protected]', 'val', 'val', 'val', 'Recall', '[email protected]:0.95'] # legends
|
1218 |
t = ['GIoU', 'Objectness', 'Classification', 'P-R', 'mAP-F1'] # titles
|
|
|
1236 |
|
1237 |
|
1238 |
def plot_results(start=0, stop=0, bucket='', id=(), labels=(),
|
1239 |
+
save_dir=''): # from utils.general import *; plot_results()
|
1240 |
# Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov5#reproduce-our-training
|
1241 |
fig, ax = plt.subplots(2, 5, figsize=(12, 6))
|
1242 |
ax = ax.ravel()
|