From 2ca4c9aaecf49b4411a654990762e220962777e6 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 9 Apr 2019 13:39:17 +0200 Subject: [PATCH] updates --- utils/utils.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/utils/utils.py b/utils/utils.py index be5f8f99..e501442b 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -72,20 +72,6 @@ def coco80_to_coco91_class(): # converts 80-index (val2014) to 91-index (paper) return x -def plot_one_box(x, img, color=None, label=None, line_thickness=None): - # Plots one bounding box on image img - tl = line_thickness or round(0.002 * max(img.shape[0:2])) + 1 # line thickness - color = color or [random.randint(0, 255) for _ in range(3)] - c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3])) - cv2.rectangle(img, c1, c2, color, thickness=tl) - if label: - tf = max(tl - 1, 1) # font thickness - t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0] - c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3 - cv2.rectangle(img, c1, c2, color, -1) # filled - cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA) - - def weights_init_normal(m): classname = m.__class__.__name__ if classname.find('Conv') != -1: @@ -467,6 +453,22 @@ def coco_only_people(path='../coco/labels/val2014/'): print(labels.shape[0], file) +# Plotting functions --------------------------------------------------------------------------------------------------- + +def plot_one_box(x, img, color=None, label=None, line_thickness=None): + # Plots one bounding box on image img + tl = line_thickness or round(0.002 * max(img.shape[0:2])) + 1 # line thickness + color = color or [random.randint(0, 255) for _ in range(3)] + c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3])) + cv2.rectangle(img, c1, c2, color, thickness=tl) + if label: + tf = max(tl - 1, 1) # font thickness + t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0] + c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3 + cv2.rectangle(img, c1, c2, color, -1) # filled + 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() # Compares the two methods for width-height anchor multiplication # https://github.com/ultralytics/yolov3/issues/168 @@ -484,7 +486,7 @@ def plot_wh_methods(): # from utils.utils import *; plot_wh_methods() plt.ylabel('output') plt.legend() fig.tight_layout() - fig.savefig('comparison.jpg', dpi=fig.dpi) + fig.savefig('comparison.png', dpi=300) def plot_images(imgs, targets, fname='images.jpg'): @@ -503,7 +505,7 @@ def plot_images(imgs, targets, fname='images.jpg'): plt.plot(boxes[[0, 2, 2, 0, 0]], boxes[[1, 1, 3, 3, 1]], '.-') plt.axis('off') fig.tight_layout() - fig.savefig(fname, dpi=fig.dpi) + fig.savefig(fname, dpi=300) plt.close() @@ -524,4 +526,4 @@ def plot_results(start=0, stop=0): # from utils.utils import *; plot_results() if i == 0: plt.legend() fig.tight_layout() - fig.savefig('results.jpg', dpi=fig.dpi) + fig.savefig('results.png', dpi=300)