From 9f482cbcb885c7b37df47285afd3e3bbaaaa780d Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 11 Aug 2020 20:11:44 -0700 Subject: [PATCH] utils.general comment updates/bug fixes --- Dockerfile | 2 +- detect.py | 2 +- tutorial.ipynb | 4 ++-- utils/general.py | 24 ++++++++++++------------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index d24039d32..caf63e6b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 # 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 # docker system prune -a --volumes diff --git a/detect.py b/detect.py index cfb1ad50f..6f2fd58a0 100644 --- a/detect.py +++ b/detect.py @@ -138,7 +138,7 @@ def detect(save_img=False): if save_txt or save_img: 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) print('Done. (%.3fs)' % (time.time() - t0)) diff --git a/tutorial.ipynb b/tutorial.ipynb index d3418ccf8..d398de417 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -622,7 +622,7 @@ "colab_type": "text" }, "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" }, "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, "outputs": [ diff --git a/utils/general.py b/utils/general.py index c6497d105..239683d02 100755 --- a/utils/general.py +++ b/utils/general.py @@ -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()