updates
This commit is contained in:
parent
d8cbf9b7a7
commit
2ca4c9aaec
|
@ -72,20 +72,6 @@ def coco80_to_coco91_class(): # converts 80-index (val2014) to 91-index (paper)
|
||||||
return x
|
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):
|
def weights_init_normal(m):
|
||||||
classname = m.__class__.__name__
|
classname = m.__class__.__name__
|
||||||
if classname.find('Conv') != -1:
|
if classname.find('Conv') != -1:
|
||||||
|
@ -467,6 +453,22 @@ def coco_only_people(path='../coco/labels/val2014/'):
|
||||||
print(labels.shape[0], file)
|
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()
|
def plot_wh_methods(): # from utils.utils 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
|
||||||
|
@ -484,7 +486,7 @@ def plot_wh_methods(): # from utils.utils import *; plot_wh_methods()
|
||||||
plt.ylabel('output')
|
plt.ylabel('output')
|
||||||
plt.legend()
|
plt.legend()
|
||||||
fig.tight_layout()
|
fig.tight_layout()
|
||||||
fig.savefig('comparison.jpg', dpi=fig.dpi)
|
fig.savefig('comparison.png', dpi=300)
|
||||||
|
|
||||||
|
|
||||||
def plot_images(imgs, targets, fname='images.jpg'):
|
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.plot(boxes[[0, 2, 2, 0, 0]], boxes[[1, 1, 3, 3, 1]], '.-')
|
||||||
plt.axis('off')
|
plt.axis('off')
|
||||||
fig.tight_layout()
|
fig.tight_layout()
|
||||||
fig.savefig(fname, dpi=fig.dpi)
|
fig.savefig(fname, dpi=300)
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
|
|
||||||
|
@ -524,4 +526,4 @@ def plot_results(start=0, stop=0): # from utils.utils import *; plot_results()
|
||||||
if i == 0:
|
if i == 0:
|
||||||
plt.legend()
|
plt.legend()
|
||||||
fig.tight_layout()
|
fig.tight_layout()
|
||||||
fig.savefig('results.jpg', dpi=fig.dpi)
|
fig.savefig('results.png', dpi=300)
|
||||||
|
|
Loading…
Reference in New Issue