Example #1
0
def _test_outputs_gradients(model):
    x, y, _ = make_data(K.int_shape(model.input), model.layers[2].units)
    name = model.layers[1].name
    grads_all = get_gradients(model, name, x, y, mode='outputs')
    grads_last = get_gradients(model, 2, x, y, mode='outputs')

    kwargs1 = dict(n_rows=None,
                   show_xy_ticks=[0, 0],
                   show_borders=True,
                   max_timesteps=50,
                   title_mode='grads')
    kwargs2 = dict(n_rows=2,
                   show_xy_ticks=[1, 1],
                   show_borders=False,
                   max_timesteps=None)

    features_1D(grads_all[0], **kwargs1)
    features_1D(grads_all[:1], **kwargs1)
    features_1D(grads_all, **kwargs2)
    features_2D(grads_all[0], norm=(-.01, .01), show_colorbar=True, **kwargs1)
    features_2D(grads_all, norm=None, reflect_half=True, **kwargs2)
    features_0D(grads_last, marker='o', color=None, title_mode='grads')
    features_0D(grads_last, marker='x', color='blue', ylims=(-.1, .1))
    features_hist(grads_all, bins=100, xlims=(-.01, .01), title="Outs hists")
    features_hist(grads_all, bins=100, n_rows=4)
    print('\n')  # improve separation
Example #2
0
def _test_weights_gradients(model):
    x, y, _ = make_data(K.int_shape(model.input), model.layers[2].units)
    name = model.layers[1].name

    with tempdir() as dirpath:
        kws = dict(input_data=x, labels=y, mode='grads')
        if hasattr(model.layers[1], 'backward_layer'):
            kws['savepath'] = dirpath

        rnn_histogram(model, name, bins=100, **kws)
        rnn_heatmap(model, name, **kws)
Example #3
0
def _test_outputs(model):
    x, *_ = make_data(K.int_shape(model.input), model.layers[2].units)
    outs = get_outputs(model, 1, x)
    features_1D(outs[:1], show_y_zero=True)
    features_1D(outs[0])
    features_2D(outs)