{"record":{"id":"422f3be7973a2ba3","repo":"deeplearning4j/deeplearning4j","slug":"cannot-merge-evaluationbinary-instances-with-diffe","errorCode":null,"errorMessage":"Cannot merge EvaluationBinary instances with different sizes. This ","messagePattern":"Cannot merge EvaluationBinary instances with different sizes\\. This ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationBinary.java","lineNumber":267,"sourceCode":"     * @param other EvaluationBinary object to merge into this one.\n     */\n    @Override\n    public void merge(EvaluationBinary other) {\n        if (other.countTruePositive == null) {\n            //Other is empty - no op\n            return;\n        }\n\n        if (countTruePositive == null) {\n            //This evaluation is empty -> take results from other\n            this.countTruePositive = other.countTruePositive;\n            this.countFalsePositive = other.countFalsePositive;\n            this.countTrueNegative = other.countTrueNegative;\n            this.countFalseNegative = other.countFalseNegative;\n            this.rocBinary = other.rocBinary;\n        } else {\n            if (this.countTruePositive.length != other.countTruePositive.length) {\n                throw new IllegalStateException(\"Cannot merge EvaluationBinary instances with different sizes. This \"\n                                + \"size: \" + this.countTruePositive.length + \", other size: \"\n                                + other.countTruePositive.length);\n            }\n\n            //Both have stats\n            addInPlace(this.countTruePositive, other.countTruePositive);\n            addInPlace(this.countTrueNegative, other.countTrueNegative);\n            addInPlace(this.countFalsePositive, other.countFalsePositive);\n            addInPlace(this.countFalseNegative, other.countFalseNegative);\n\n            if (this.rocBinary != null) {\n                this.rocBinary.merge(other.rocBinary);\n            }\n        }\n    }\n\n    @Override\n    public void reset() {","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationBinary.java#L249-L285","documentation":"EvaluationBinary.merge throws IllegalStateException when the two evaluators have different numbers of outputs (countTruePositive lengths differ). Per-output counts and the internal ROCBinary cannot be combined when the sizes disagree, as checked at line 267.","triggerScenarios":"Calling this.merge(other) with an EvaluationBinary built from a model with a different number of outputs — e.g. merging partial results from parallel evaluation of differently sized networks.","commonSituations":"Distributed/parallel evaluation where different workers ran different model versions; merging evaluator results loaded from old serialized stats with a new output count.","solutions":["Ensure all EvaluationBinary instances to merge come from the same model/output configuration","Re-run evaluation for mismatched instances with the correct model","Keep separate merged results per output size instead of merging across sizes"],"exampleFix":"// before\nevalMain.merge(evalFromOldModel); // different output sizes\n// after\nif (evalFromOldModel.getNumOutputs() == evalMain.getNumOutputs()) {\n    evalMain.merge(evalFromOldModel);\n} else {\n    evalFromOldModel = reEvaluateWithCurrentModel();\n    evalMain.merge(evalFromOldModel);\n}","handlingStrategy":"validation","validationCode":"if (thisEval.getStoredSize() != otherEval.getStoredSize()) {\n    throw new IllegalStateException(\"cannot merge: different output sizes\");\n}\nthisEval.merge(otherEval);","typeGuard":null,"tryCatchPattern":"try {\n    main.merge(other);\n} catch (IllegalStateException e) {\n    log.error(\"Cannot merge evaluators of different output sizes; keeping results separate\");\n}","preventionTips":["Only merge evaluators created from the same model version","Tag evaluators with the model/output size when distributing evaluation","Re-run evaluation rather than merging incompatible serialized stats"],"tags":["nd4j","shape-mismatch","merge"],"backgroundTag":"shape-mismatch","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"}