utils.general comment updates/bug fixes
This commit is contained in:
1 parent
4949401a94
commit
9f482cbcb8
4 files changed
+16
-16
No files matched your search
+1
-1
@@ -43,7 +43,7 @@ COPY . /usr/src/app
|
|||||||
# sudo docker commit 092b16b25c5b usr/resume && sudo docker run -it --gpus all --ipc=host -v "$(pwd)"/coco:/usr/src/coco --entrypoint=sh usr/resume
|
# sudo docker commit 092b16b25c5b usr/resume && sudo docker run -it --gpus all --ipc=host -v "$(pwd)"/coco:/usr/src/coco --entrypoint=sh usr/resume
|
||||||
|
|
||||||
# Send weights to GCP
|
# Send weights to GCP
|
||||||
# python -c "from utils.utils import *; strip_optimizer('runs/exp0/weights/last.pt', 'temp.pt')" && gsutil cp temp.pt gs://*
|
# python -c "from utils.general import *; strip_optimizer('runs/exp0_*/weights/last.pt', 'tmp.pt')" && gsutil cp tmp.pt gs://*
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
# docker system prune -a --volumes
|
# docker system prune -a --volumes
|
||||||
@@ -138,7 +138,7 @@ def detect(save_img=False):
|
|||||||
|
|
||||||
if save_txt or save_img:
|
if save_txt or save_img:
|
||||||
print('Results saved to %s' % Path(out))
|
print('Results saved to %s' % Path(out))
|
||||||
if platform == 'darwin' and not opt.update: # MacOS
|
if platform.system() == 'Darwin' and not opt.update: # MacOS
|
||||||
os.system('open ' + save_path)
|
os.system('open ' + save_path)
|
||||||
|
|
||||||
print('Done. (%.3fs)' % (time.time() - t0))
|
print('Done. (%.3fs)' % (time.time() - t0))
|
||||||
|
|||||||
Vendored
+2
-2
@@ -622,7 +622,7 @@
|
|||||||
"colab_type": "text"
|
"colab_type": "text"
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"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.utils 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)."
|
"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)."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -637,7 +637,7 @@
|
|||||||
"outputId": "c1146425-643e-49ab-de25-73216f0dde23"
|
"outputId": "c1146425-643e-49ab-de25-73216f0dde23"
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"from utils.utils import plot_results; plot_results() # plot results.txt files as results.png"
|
"from utils.general import plot_results; plot_results() # plot results.txt files as results.png"
|
||||||
],
|
],
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"outputs": [
|
"outputs": [
|
||||||
|
|||||||
+12
-12
@@ -670,7 +670,7 @@ def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, merge=False,
|
|||||||
return output
|
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'
|
# Strip optimizer from 'f' to finalize training, optionally save as 's'
|
||||||
x = torch.load(f, map_location=torch.device('cpu'))
|
x = torch.load(f, map_location=torch.device('cpu'))
|
||||||
x['optimizer'] = None
|
x['optimizer'] = None
|
||||||
@@ -695,7 +695,7 @@ def coco_class_count(path='../coco/labels/train2014/'):
|
|||||||
print(i, len(files))
|
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
|
# Find images with only people
|
||||||
files = sorted(glob.glob('%s/*.*' % path))
|
files = sorted(glob.glob('%s/*.*' % path))
|
||||||
for i, file in enumerate(files):
|
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)
|
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
|
# crops images into random squares up to scale fraction
|
||||||
# WARNING: overwrites images!
|
# WARNING: overwrites images!
|
||||||
for file in tqdm(sorted(glob.glob('%s/*.*' % path))):
|
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):
|
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/'):
|
if os.path.exists('new/'):
|
||||||
shutil.rmtree('new/') # delete output folder
|
shutil.rmtree('new/') # delete output folder
|
||||||
os.makedirs('new/') # make new 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
|
k: kmeans evolved anchors
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
from utils.utils import *; _ = kmean_anchors()
|
from utils.general import *; _ = kmean_anchors()
|
||||||
"""
|
"""
|
||||||
thr = 1. / thr
|
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)
|
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
|
# 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)
|
||||||
@@ -1107,7 +1107,7 @@ def plot_lr_scheduler(optimizer, scheduler, epochs=300, save_dir=''):
|
|||||||
plt.savefig(Path(save_dir) / 'LR.png', dpi=200)
|
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
|
# 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])
|
||||||
@@ -1124,7 +1124,7 @@ def plot_test_txt(): # from utils.utils import *; plot_test()
|
|||||||
plt.savefig('hist1d.png', dpi=200)
|
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
|
# 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']
|
||||||
@@ -1137,7 +1137,7 @@ def plot_targets_txt(): # from utils.utils import *; plot_targets_txt()
|
|||||||
plt.savefig('targets.jpg', dpi=200)
|
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
|
# 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()
|
||||||
@@ -1188,7 +1188,7 @@ def plot_labels(labels, save_dir=''):
|
|||||||
plt.close()
|
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
|
# 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)
|
||||||
@@ -1212,7 +1212,7 @@ def plot_evolution(yaml_file='runs/evolve/hyp_evolved.yaml'): # from utils.util
|
|||||||
print('\nPlot saved as evolve.png')
|
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
|
# 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 = ['GIoU', 'Objectness', 'Classification', 'P-R', 'mAP-F1'] # titles
|
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=(),
|
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
|
# Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov5#reproduce-our-training
|
||||||
fig, ax = plt.subplots(2, 5, figsize=(12, 6))
|
fig, ax = plt.subplots(2, 5, figsize=(12, 6))
|
||||||
ax = ax.ravel()
|
ax = ax.ravel()
|
||||||
|
|||||||
Reference in new issue
Block a user