示例#1
0
def test_guided_backprop(vgg):
    # load the vgg into the deoxys model
    deo = Model(vgg)

    # load an real image
    img = load_image('tests/img/cat.jpg')

    layer_list = [layer.name for layer in vgg.layers[1:4]]

    for i, layer in enumerate(layer_list):
        outs = deprocess_image(deo.guided_backprop(layer, img, mode='mean')[0])
示例#2
0
    # fig, axes = plt.subplots(nrow, ncol)
    # for ax in axes.flatten():
    #     ax.axis('off')
    # for i, layer in enumerate(layer_list):
    #     outs = deprocess_image(deo.deconv(layer, img)[0])
    #     axes[i//5, i % 5].imshow(outs)
    #     axes[i//5, i % 5].set_title(layer)
    # plt.suptitle('Deconvnet Map')
    # plt.show()
    # input('Press ENTER to continue...')

    fig, axes = plt.subplots(nrow, ncol)
    for ax in axes.flatten():
        ax.axis('off')
    for i, layer in enumerate(layer_list):
        outs = deprocess_image(deo.guided_backprop(layer, img)[0])
        axes[i // 5, i % 5].imshow(outs)
        axes[i // 5, i % 5].set_title(layer)
    plt.suptitle('Guided Backprop Map')
    plt.show()
    input('Press ENTER to continue...')

    # fig, axes = plt.subplots(nrow, ncol)
    # for ax in axes.flatten():
    #     ax.axis('off')
    # for i, layer in enumerate(layer_list):
    #     outs = deprocess_image(deo.gradient_map(
    #         layer, epochs=5, step_size=2)[0])
    #     axes[i//5, i % 5].imshow(outs)
    #     axes[i//5, i % 5].set_title(layer)
    # plt.suptitle('Gradients Map')