{"record":{"id":"d09f4494efe926a0","repo":"deeplearning4j/deeplearning4j","slug":"layer-of-type-is-set-as-network-output-bu","errorCode":null,"errorMessage":"Layer \"{}\" of type {} is set as network output (but isn't an IOutputLayer). Only IOutputLayer layers can be fit via backprop with a labels array. ","messagePattern":"Layer \"(.+?)\" of type (.+?) is set as network output \\(but isn't an IOutputLayer\\)\\. Only IOutputLayer layers can be fit via backprop with a labels array\\. ","errorType":"exception","errorClass":"DL4JException","httpStatus":null,"severity":"error","filePath":"deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/graph/ComputationGraph.java","lineNumber":2692,"sourceCode":"                if (current.isOutputVertex()) {\n                    //Two reasons for a vertex to be an output vertex:\n                    //(a) it's an output layer (i.e., instanceof IOutputLayer), or\n                    //(b) it's a normal layer, but it has been marked as an output layer for use in external errors - for reinforcement learning, for example\n\n                    int thisOutputNumber = configuration.getNetworkOutputs().indexOf(current.getVertexName());\n                    Layer currentLayer = current.getLayer();\n                    if (currentLayer instanceof FrozenLayerWithBackprop) {\n                        currentLayer = ((FrozenLayerWithBackprop) currentLayer).getInsideLayer();\n                    }\n                    if (currentLayer instanceof IOutputLayer) {\n                        IOutputLayer outputLayer = (IOutputLayer) currentLayer;\n\n                        INDArray currLabels = labels[thisOutputNumber];\n                        outputLayer.setLabels(currLabels);\n                    } else {\n                        if ((externalEpsilons == null || externalEpsilons.length == 0)\n                                && labels[thisOutputNumber] != null) {\n                            throw new DL4JException(\"Layer \\\"\" + current.getVertexName() + \"\\\" of type \"\n                                    + current.getLayer().getClass().getSimpleName()\n                                    + \" is set as network output \"\n                                    + \"(but isn't an IOutputLayer). Only IOutputLayer layers can be fit via backprop with\"\n                                    + \" a labels array. \");\n                        }\n                        current.setEpsilon(externalEpsilons[thisOutputNumber]);\n                        setVertexEpsilon[topologicalOrder[i]] = true;\n                    }\n                }\n\n                //Actually execute backprop for the specified vertex\n                //First: Open the relevant workspace for the activations.\n                //Note that this will be closed only once the current vertex's activations have been consumed\n                MemoryWorkspace wsActivationGrads = workspaceMgr.notifyScopeEntered(ArrayType.ACTIVATION_GRAD);\n                openActivationsWorkspaces.put(wsActivationGrads, workspaceMgr);\n\n                //Note that because we're opening activation gradient workspaces not in any defined order (i.e., workspace\n                // use isn't simply nested), we'll manually override the previous workspace setting. Otherwise, when we","sourceCodeStart":2674,"sourceCodeEnd":2710,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/graph/ComputationGraph.java#L2674-L2710","documentation":"During backprop, if a vertex is marked as a network output, its layer is not an IOutputLayer, and labels were provided (with no external epsilons), DL4J throws DL4JException: only IOutputLayer subclasses know how to turn labels into gradients. A non-output layer marked as network output cannot consume labels, so fitting with labels is invalid for this graph.","triggerScenarios":"Calling fit(DataSet/MultiDataSet/INDArray labels...) on a ComputationGraph whose setOutputs(...) names a vertex whose layer is not an IOutputLayer (e.g. DenseLayer, LSTM marked as output) while supplying labels and no external epsilons.","commonSituations":"Forgetting to use OutputLayer/RnnOutputLayer/LossLayer as the final layer; changing the last layer's type during model edits but leaving setOutputs pointing at it; copying a config where the output layer was replaced by a plain activation layer for transfer learning.","solutions":["Make the output vertex an IOutputLayer: use OutputLayer.Builder(...), RnnOutputLayer, or LossLayer with a loss function","Remove the labels argument and use backpropGradient with external epsilons if you intend a non-output layer as terminal","Check configuration.setOutputs(...) points at the intended IOutputLayer vertex name"],"exampleFix":"// before\n.layer(2, new DenseLayer.Builder().nOut(numClasses).activation(Activation.SOFTMAX).build())\n.setOutputs(\"layer2\")\n// after\n.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)\n        .nOut(numClasses).activation(Activation.SOFTMAX).build())\n.setOutputs(\"layer2\")","handlingStrategy":"validation","validationCode":"for (String name : graph.getConfiguration().getNetworkOutputs()) {\n    GraphVertex v = graph.getVertex(name);\n    if (!(v instanceof LayerVertex) || !(((LayerVertex) v).getLayer() instanceof IOutputLayer))\n        throw new IllegalArgumentException(\"output vertex '\" + name + \"' is not an IOutputLayer; cannot fit with labels\");\n}","typeGuard":"static boolean outputIsIOutputLayer(ComputationGraph g, String name) {\n    GraphVertex v = g.getVertex(name);\n    return v instanceof LayerVertex && ((LayerVertex) v).getLayer() instanceof IOutputLayer;\n}","tryCatchPattern":"try { graph.fit(data); }\ncatch (DL4JException e) { log.error(\"output vertex is not an IOutputLayer: {}\", e.getMessage()); throw e; }","preventionTips":["End label-based networks with OutputLayer/RnnOutputLayer/LossLayer","After editing layer types, re-verify setOutputs(...) targets","During transfer learning, replace removed output layers with an IOutputLayer"],"tags":["deeplearning4j","computation-graph","output-layer","labels","config"],"backgroundTag":"invalid-config-value","analyzedSha":"4c22ac5fe4a8350d05d224e7f4499429f7f69c93","analyzedAt":"2026-09-07T05:27:04.714Z","contentChangedAt":"2026-09-07T05:27:04.714Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}