# Inspection: top-50 proposals before NMS on a blank canvas
anchors_all = gen(feat_maps, (800, 800))
all_deltas_flat = torch.cat([
b.permute(0, 2, 3, 1).reshape(-1, 4) for b in bbox_preds_list
]).detach()
all_scores_1d = torch.tensor(all_scores_flat)
top50_idx = all_scores_1d.argsort(descending=True)[:50]
top50_props = decode_boxes(anchors_all[top50_idx], all_deltas_flat[top50_idx])
top50_props = top50_props.clamp(0, 800)
fig, ax = plt.subplots(figsize=(8, 8))
ax.set_xlim(0, 800); ax.set_ylim(800, 0)
ax.set_facecolor('#1a1a2e')
ax.set_title('Top-50 proposals (before NMS, random weights)')
for box in top50_props.tolist():
x1, y1, x2, y2 = box
rect = patches.Rectangle((x1, y1), x2 - x1, y2 - y1,
linewidth=1, edgecolor='cyan', facecolor='none', alpha=0.5)
ax.add_patch(rect)
plt.tight_layout()
plt.savefig('images/top50_proposals.png', dpi=100, bbox_inches='tight')
plt.show()