Example usage for org.deeplearning4j.nn.multilayer MultiLayerNetwork feedForwardToLayer

List of usage examples for org.deeplearning4j.nn.multilayer MultiLayerNetwork feedForwardToLayer

Introduction

In this page you can find the example usage for org.deeplearning4j.nn.multilayer MultiLayerNetwork feedForwardToLayer.

Prototype

public List<INDArray> feedForwardToLayer(int layerNum, INDArray input, boolean train) 

Source Link

Document

Compute the activations from the input to the specified layer.
To compute activations for all layers, use feedForward(...) methods
Note: output list includes the original input.

Usage

From source file:org.knime.ext.dl4j.base.nodes.predict.AbstractDLPredictorNodeModel.java

License:Open Source License

/**
 * Activates the specified layer in the specified network with the specified input. The input array should contain
 * one example per row.// w ww .  ja  v a  2 s .co m
 *
 * @param mln the network to use
 * @param layerNum the layer to activate
 * @param input the inputs to use
 * @return the activations of the layer for the input
 */
protected INDArray activate(final MultiLayerNetwork mln, final int layerNum, final INDArray input) {
    /* The MultiLayerNetwork.feedForwardToLayer(int layerNum, INDArray input, boolean train) method is not wrapped
     * into workspaces by DL4J (see MultiLayerNetwork.output(INDArray input, boolean train) method). Therefore, we
     * need to do the same thing here. */
    MemoryWorkspace workspace = Nd4j.getWorkspaceManager()
            .getWorkspaceForCurrentThread(workspaceConfigurationExternal, workspaceExternal);
    try (MemoryWorkspace wsE = workspace.notifyScopeEntered()) {
        final List<INDArray> output = new ArrayList<INDArray>();
        for (int i = 0; i < input.rows(); i++) {
            List<INDArray> activations = mln.feedForwardToLayer(layerNum, input.getRow(i), false);
            output.add(activations.get(activations.size() - 1).detach());
        }
        return Nd4j.hstack(output);
    }
}