Skip to content
Snippets Groups Projects
tfhelpers.py 414 B
Newer Older
Nikolai.Hartmann's avatar
Nikolai.Hartmann committed
"Helper functions using keras or tensorflow"

def get_single_neuron_function(K, model, layer, neuron, scaler=None):

    f = K.function([model.input]+[K.learning_phase()], [model.layers[layer].output[:,neuron]])

    def eval_single_neuron(x):
        if scaler is not None:
            x_eval = scaler.transform(x)
        else:
            x_eval = x
        return f([x_eval])[0]

    return eval_single_neuron