Skip to content

Instantly share code, notes, and snippets.

@pietz
Created September 28, 2018 08:52
Show Gist options
  • Save pietz/59be226fe2d6db8abd1acd8b07e8fcae to your computer and use it in GitHub Desktop.
Save pietz/59be226fe2d6db8abd1acd8b07e8fcae to your computer and use it in GitHub Desktop.
Take a YOLO style detection mask, convert it to a pixel mask and visualize it.
def draw_det(det, size=256):
g = float(len(det))
msk = np.zeros((size,size))
for col in range(det.shape[0]):
for row in range(det.shape[1]):
p,x,y,w,h = det[col,row]
if p > 0.5:
l = int(size*(col/g+x/g-w/2))
r = int(size*(col/g+x/g+w/2))
t = int(size*(row/g+y/g-h/2))
b = int(size*(row/g+y/g+h/2))
msk[l:r,t:b] = 1
plt.imshow(msk)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment