{"record":{"id":"d766153e3b563cb9","repo":"deeplearning4j/deeplearning4j","slug":"cannot-calculate-score-vertex-is-not-an-outp","errorCode":null,"errorMessage":"Cannot calculate score: vertex \"{}\" is not an output layer","messagePattern":"Cannot calculate score: vertex \"(.+?)\" is not an output layer","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/graph/ComputationGraph.java","lineNumber":3158,"sourceCode":"        setInputs(dataSet.getFeatures());\n\n        //Need to feed forward, but not the output layers\n        //TODO maybe optimize? We only need *some* of the activations in the WS...\n        //mgr.keepOpen(ArrayType.values());\n        ffToLayerActivationsInWS(false, vertices.length - 1, getOutputLayerIndices(), FwdPassType.STANDARD, false,\n                dataSet.getFeatures(), dataSet.getFeaturesMaskArrays(), dataSet.getLabelsMaskArrays(), false);\n\n        INDArray[] labels = dataSet.getLabels();\n        setLabels(labels);\n\n\n        double r = (addRegularizationTerms ? calcRegularizationScore(true) : 0.0);\n        int i = 0;\n        for (String s : configuration.getNetworkOutputs()) {\n            GraphVertex gv = verticesMap.get(s);\n            Layer outLayer = gv.getLayer();\n            if (outLayer == null || !(outLayer instanceof IOutputLayer)) {\n                throw new UnsupportedOperationException(\n                        \"Cannot calculate score: vertex \\\"\" + s + \"\\\" is not an output layer\");\n            }\n\n            IOutputLayer ol = (IOutputLayer) outLayer;\n            ol.setLabels(labels[i++]);\n\n            INDArray scoreCurrLayer;;\n\n            scoreCurrLayer =((LayerVertex) gv).computeScoreForExamples(r, mgr);\n\n            if (out == null)\n                out = scoreCurrLayer.detach();\n            else\n                out.addi(scoreCurrLayer);\n\n            //Only want to add l1/l2 once...\n            r = 0.0;\n        }","sourceCodeStart":3140,"sourceCodeEnd":3176,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/graph/ComputationGraph.java#L3140-L3176","documentation":"ComputationGraph.score() computes the loss by iterating over every vertex listed in the network's output configuration. Each such vertex must hold a Layer implementing IOutputLayer (e.g. LossLayer, OutputLayer) so labels can be set. If any configured output vertex is not an IOutputLayer, score calculation is impossible and this UnsupportedOperationException is thrown.","triggerScenarios":"Calling score() (or fit paths that compute a score) on a ComputationGraph whose Configuration.getNetworkOutputs() names a vertex whose layer is null or does not implement IOutputLayer — e.g. the output vertex is a regular feed-forward layer, a verticesToOutput marked wrong vertex, or the graph was built without an OutputLayer/LossLayer at that vertex.","commonSituations":"Configuring .setOutputs(\"someHiddenVertex\") by mistake instead of a dedicated OutputLayer vertex; building an autoencoder-style graph where the output vertex is a plain DenseLayer; adding vertices programmatically and forgetting to make the final one an output layer; using setInputs/setLabelArrays then score() on a validation-only graph.","solutions":["Ensure every vertex name in .setOutputs(...) corresponds to a vertex holding an OutputLayer or LossLayer (an IOutputLayer).","In ComputationGraphConfiguration.Builder use .addLayer(name, new OutputLayer.Builder(...)....build()) for each listed output vertex.","Verify with graph.getConfiguration().getNetworkOutputs() and cross-check graph.getVertex(name).getLayer() instanceof IOutputLayer before calling score().","If you only want activations, call feedForward()/output() instead of score()."],"exampleFix":"// before\n.setOutputs(\"dense2\") // dense2 is a plain DenseLayer, not IOutputLayer\n// after\n.addLayer(\"out\", new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)\n        .nIn(64).nOut(10).activation(Activation.SOFTMAX).build(), \"dense2\")\n.setOutputs(\"out\")","handlingStrategy":"validation","validationCode":"boolean ok = graph.getConfiguration().getNetworkOutputs().stream()\n    .allMatch(s -> {\n        Layer l = graph.getVertex(s).getLayer();\n        return l != null && l instanceof IOutputLayer;\n    });\nif (!ok) throw new IllegalStateException(\"Every output vertex must be an IOutputLayer\");","typeGuard":"boolean isOutputVertex(String s) {\n    Layer l = graph.getVertex(s).getLayer();\n    return l instanceof IOutputLayer;\n}","tryCatchPattern":"try {\n    double score = graph.score();\n} catch (UnsupportedOperationException e) {\n    // graph output vertices are not IOutputLayers; fix configuration\n}","preventionTips":["Always add an explicit OutputLayer/LossLayer for each name in setOutputs(...)","Validate the configuration with .validateBackWays()/build() before instantiating","Check getVertex(name).getLayer() instanceof IOutputLayer in tests"],"tags":["deeplearning4j","computation-graph","unsupported-operation","output-layer"],"backgroundTag":"unsupported-operation","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"}