Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Use draw_ from inference
  • Loading branch information
Valeriy Mukhtarulin authored Feb 24, 2020
1 parent 1661d2b commit d4caf64
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions Computer Vision/imports/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,13 @@
from cycler import cycler
from .model import *
from .metrics import *


from .inference import *


def get_cmap(N):
color_norm = mcolors.Normalize(vmin=0, vmax=N-1)
return cmx.ScalarMappable(norm=color_norm, cmap='Set3').to_rgba

def draw_outline(o, lw):
o.set_path_effects([patheffects.Stroke(
linewidth=lw, foreground='black'), patheffects.Normal()])

def draw_rect(ax, b, color='white'):
patch = ax.add_patch(patches.Rectangle(b[:2], *b[-2:], fill=False, edgecolor=color, lw=2))
draw_outline(patch, 4)

def draw_text(ax, xy, txt, sz=14, color='white'):
text = ax.text(*xy, txt,
verticalalignment='top', color=color, fontsize=sz, weight='bold')
draw_outline(text, 1)

def activ_to_bbox(acts, anchors, flatten=True):
"Extrapolate bounding boxes on anchors from the model activations."
if flatten:
Expand Down Expand Up @@ -73,5 +59,4 @@ def show_boxes(boxes):
for i, bbox in enumerate(boxes):
bb = bbox.numpy()
rect = [bb[1]-bb[3]/2, bb[0]-bb[2]/2, bb[3], bb[2]]
draw_rect(ax, rect, color=color_list[i%num_color])
draw_text(ax, [bb[1]-bb[3]/2,bb[0]-bb[2]/2], str(i), color=color_list[i%num_color])
draw_rect(ax, rect, text=f'{txt} {scr:.2f}', color=color_list[i%num_color])

0 comments on commit d4caf64

Please sign in to comment.