Skip to content

Commit f0845f6

Browse files
committed
update demo_quant
1 parent 432165e commit f0845f6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

demo_quant.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,26 @@
44
import numpy as np
55
import matplotlib.pyplot as plt
66
from tinysam import sam_model_registry, SamPredictor
7-
from demo import show_mask, show_points, show_box
7+
8+
def show_mask(mask, ax, random_color=False):
9+
if random_color:
10+
color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0)
11+
else:
12+
color = np.array([30/255, 144/255, 255/255, 0.6])
13+
h, w = mask.shape[-2:]
14+
mask_image = mask.reshape(h, w, 1) * color.reshape(1, 1, -1)
15+
ax.imshow(mask_image)
16+
17+
def show_points(coords, labels, ax, marker_size=375):
18+
pos_points = coords[labels==1]
19+
neg_points = coords[labels==0]
20+
ax.scatter(pos_points[:, 0], pos_points[:, 1], color='green', marker='*', s=marker_size, edgecolor='white', linewidth=1.25)
21+
ax.scatter(neg_points[:, 0], neg_points[:, 1], color='red', marker='*', s=marker_size, edgecolor='white', linewidth=1.25)
22+
23+
def show_box(box, ax):
24+
x0, y0 = box[0], box[1]
25+
w, h = box[2] - box[0], box[3] - box[1]
26+
ax.add_patch(plt.Rectangle((x0, y0), w, h, edgecolor='green', facecolor=(0,0,0,0), lw=2))
827

928
sys.path.append("./tinysam")
1029

0 commit comments

Comments
 (0)