disp.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:hart 作者: akosiorek 项目源码 文件源码
def _tile_horizontal(imgs, glimpses, boxes, n_objects, fig_size, img_size, colors, n_rows):
    nt = imgs.shape[0]
    size = n_rows, nt // n_rows + int(nt % n_rows != 0)
    n_rows = 1 + n_objects
    yy, xx = size[0] * n_rows, size[1]
    fig_y, fig_x = fig_size
    img_y, img_x = img_size

    sy, sx = size[0] * (n_objects + img_y), xx * img_x
    gs = gridspec.GridSpec(sy, sx)
    fig = plt.figure(figsize=(sx * fig_x, sy * fig_y))

    axes = np.empty((yy, xx), dtype=object)

    ii = 0
    for i in xrange(yy):
        if i % n_rows == 0:
            for j in xrange(xx):
                axes[i, j] = plt.subplot(gs[ii:ii + img_y, j * img_x:(j + 1) * img_x])
            ii += img_y
        else:
            for j in xrange(xx):
                axes[i, j] = plt.subplot(gs[ii, j * img_x + img_x // 2])
            ii += 1

    for r in xrange(0, yy, n_rows):
        for c in xrange(xx):
            idx = (r // n_rows) * xx + c
            if idx < nt:
                axes[r, c].imshow(imgs[idx], 'gray')

                for n in xrange(n_objects):
                    for (k, v), color in izip(boxes.iteritems(), colors):
                        y, x, h, w = boxes[k]
                        bbox = Rectangle((x[idx, n], y[idx, n]), w[idx, n], h[idx, n],
                                         edgecolor=color, facecolor='none', label=k)
                        axes[r, c].add_patch(bbox)

                    axes[r + 1 + n, c].imshow(glimpses[idx, n], 'gray')

    len_bbox = len(boxes)
    if len_bbox > 1:
        x_offset = .25 * len_bbox
        axes[-2, axes.shape[1] // 2].legend(bbox_to_anchor=(x_offset, -(img_y + 1)),
                                            ncol=len_bbox, loc='lower center')

    return fig, axes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号