-
Notifications
You must be signed in to change notification settings - Fork 26
/
viz.py
32 lines (22 loc) · 786 Bytes
/
viz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from PIL import Image
def pil_loader(path):
with open(path, 'rb') as f:
with Image.open(f) as img:
return img.convert('RGB')
def plot_cam(attr, xi, cmap='jet', alpha=0.5):
attr -= attr.min()
attr /= (attr.max() + 1e-20)
plt.imshow(xi)
plt.imshow(attr, alpha=alpha, cmap=cmap)
def plot_bbox(bboxes, xi, linewidth=1):
ax = plt.gca()
ax.imshow(xi)
if not isinstance(bboxes[0], list):
bboxes = [bboxes]
for bbox in bboxes:
rect = patches.Rectangle((bbox[0], bbox[1]), bbox[2] - bbox[0], bbox[3] - bbox[1],
linewidth=linewidth, edgecolor='r', facecolor='none')
ax.add_patch(rect)
ax.axis('off')