Example #1
0
def save_sensitivity(filename, maps):
    maps = maps.cpu().numpy()
    scale = max(maps[maps > 0].max(), -maps[maps <= 0].min())
    maps = maps / scale * 0.5
    maps += 0.5
    maps = cm.bwr_r(maps)[..., :3]
    maps = np.uint8(maps * 255.0)
    maps = cv2.resize(maps, (224, 224), interpolation=cv2.INTER_NEAREST)
    cv2.imwrite(filename, maps)
def save_sensitivity(filename, maps):
    maps = maps.cpu().numpy()
    scale = max(maps[maps > 0].max(), -maps[maps <= 0].min())
    maps = maps / scale * 0.5
    maps += 0.5
    maps = cm.bwr_r(maps)[..., :3]
    maps = np.uint8(maps * 255.0)
    maps = cv2.resize(maps, (224, 224), interpolation=cv2.INTER_NEAREST)
    cv2.imwrite(filename, maps)
Example #3
0
def drawMarg(alphacolor, q, i, j, marg, J, hi, hj, score, margax, Cax, Jax):
    graytext = lambda x: {
        'text': "{:.2f}".format(x),
        'color': cm.gray_r(fnorm(x))
    }
    bwrtext = lambda x: {'text': "{:.2f}".format(x), 'color': cm.bwr(fnorm(x))}
    rwbtext = lambda x: {
        'text': "{:.2f}".format(x),
        'color': cm.bwr_r(fnorm(x))
    }
    mapi = alphacolor[i]
    mapj = alphacolor[j]

    for ax in (margax, Cax, Jax):
        ax.set_axis_off()
        ax.set_xlim(0, 6 + q)
        ax.set_ylim(0, 1 * (q + 5))

    fnorm = Normalize(0, 0.1, clip=True)
    drawGrid(margax,
             3,
             1,
             1,
             q,
             q, [[graytext(x) for x in r] for r in marg],
             mapi,
             mapj,
             '({}, {})   Bimarg'.format(i, j),
             list(map(graytext, sum(marg, axis=1))),
             list(map(graytext, sum(marg, axis=0))),
             labeltext=alphatext)

    fnorm = Normalize(-1, 1.0, clip=True)
    C = marg - outer(sum(marg, axis=1), sum(marg, axis=0))
    Cmax = np.max(np.abs(C))
    drawGrid(Cax,
             3,
             1,
             1,
             q,
             q, [[rwbtext(x) for x in r] for r in C / Cmax],
             mapi,
             mapj,
             '({}, {})   C * {}'.format(i, j, str(Cmax)),
             None,
             None,
             labeltext=alphatext)

    fnorm = Normalize(-1, 1.0, clip=True)
    drawGrid(Jax,
             3,
             1,
             1,
             q,
             q, [[bwrtext(x) for x in r] for r in J],
             mapi,
             mapj,
             '({}, {})   J score={:.2f}'.format(i, j, score),
             list(map(bwrtext, hi)),
             list(map(bwrtext, hj)),
             labeltext=alphatext)