deeplearning4j/deeplearning4j · error · IllegalStateException
Cannot merge EvaluationBinary instances with different…
Error message
Cannot merge EvaluationBinary instances with different sizes. This
What it means
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.
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
Example fix
// before
evalMain.merge(evalFromOldModel); // different output sizes
// after
if (evalFromOldModel.getNumOutputs() == evalMain.getNumOutputs()) {
evalMain.merge(evalFromOldModel);
} else {
evalFromOldModel = reEvaluateWithCurrentModel();
evalMain.merge(evalFromOldModel);
} Defensive patterns
Strategy: validation
Validate before calling
if (thisEval.getStoredSize() != otherEval.getStoredSize()) {
throw new IllegalStateException("cannot merge: different output sizes");
}
thisEval.merge(otherEval); Try / catch
try {
main.merge(other);
} catch (IllegalStateException e) {
log.error("Cannot merge evaluators of different output sizes; keeping results separate");
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Distributed/parallel evaluation where different workers ran different model versions; merging evaluator results loaded from old serialized stats with a new output count.
Related errors
- Cannot merge MultiDataSets with different number of input…
- Cannot merge MultiDataSets with different number of output…
- Array shapes are not broadcastable: [X] vs. [Y]
- Both arrays must have the same length
- C does not match outRows or outCols
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/422f3be7973a2ba3.
Report an issue: GitHub.
Appendix: source
Thrown at nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationBinary.java:267
* @param other EvaluationBinary object to merge into this one.
*/
@Override
public void merge(EvaluationBinary other) {
if (other.countTruePositive == null) {
//Other is empty - no op
return;
}
if (countTruePositive == null) {
//This evaluation is empty -> take results from other
this.countTruePositive = other.countTruePositive;
this.countFalsePositive = other.countFalsePositive;
this.countTrueNegative = other.countTrueNegative;
this.countFalseNegative = other.countFalseNegative;
this.rocBinary = other.rocBinary;
} else {
if (this.countTruePositive.length != other.countTruePositive.length) {
throw new IllegalStateException("Cannot merge EvaluationBinary instances with different sizes. This "
+ "size: " + this.countTruePositive.length + ", other size: "
+ other.countTruePositive.length);
}
//Both have stats
addInPlace(this.countTruePositive, other.countTruePositive);
addInPlace(this.countTrueNegative, other.countTrueNegative);
addInPlace(this.countFalsePositive, other.countFalsePositive);
addInPlace(this.countFalseNegative, other.countFalseNegative);
if (this.rocBinary != null) {
this.rocBinary.merge(other.rocBinary);
}
}
}
@Override
public void reset() {View on GitHub (pinned to 4c22ac5fe4)