def display_anchors(fmap_w, fmap_h, s): d2l.set_figsize() # The values from the first two dimensions will not affect the output fmap = np.zeros((1, 10, fmap_h, fmap_w)) anchors = multibox_prior(fmap, sizes=s, ratios=[1, 2, 0.5]) print(anchors.shape) bbox_scale = np.array((w, h, w, h)) d2l.show_bboxes( d2l.plt.imshow(img.asnumpy()).axes, anchors[0] * bbox_scale)
color = colors[i % len(colors)] rect = d2l.bbox_to_rect(bbox.asnumpy(), color) axes.add_patch(rect) if labels and len(labels) > i: text_color = 'k' if color == 'w' else 'w' axes.text(rect.xy[0], rect.xy[1], labels[i], va='center', ha='center', fontsize=9, color=text_color, bbox=dict(facecolor=color, lw=0)) d2l.set_figsize() bbox_scale = np.array((w, h, w, h)) fig = d2l.plt.imshow(img) show_bboxes(fig.axes, boxes[250, 250, :, :] * bbox_scale, [ 's=0.75, r=1', 's=0.5, r=1', 's=0.25, r=1', 's=0.75, r=2', 's=0.75, r=0.5' ]) # d2l.plt.show() print(boxes[250, 250, :, :] * bbox_scale, "djai") def box_iou(boxes1, boxes2): print(boxes1) print(boxes2) """Compute IOU between two sets of boxes of shape (N,4) and (M,4).""" # Compute box areas box_area = lambda boxes: ((boxes[:, 2] - boxes[:, 0]) *
from d2l import mxnet as d2l from mxnet import np, npx npx.set_np() fair_probs = [1.0 / 6] * 6 counts = np.random.multinomial(10, fair_probs, size=500) cum_counts = counts.astype(np.float32).cumsum() estimates = cum_counts / cum_counts.sum(axis=1, keepdims=True) d2l.set_figsize((6, 4.5)) for i in range(6): d2l.plt.plot(estimates[:, i].asnumpy(), label=("P(die=" + str(i + 1) + ")")) d2l.plt.axhline(y=0.167, color='black', linestyle='dashed') d2l.plt.gca().set_xlabel('Groups of experiments') d2l.plt.gca().set_ylabel('Estimated probability') d2l.plt.legend()