deeplearning4j/deeplearning4j · error · IllegalStateException
Classifier evaluation using ${classifierEval.getSimpleName()
Error message
Classifier evaluation using ${classifierEval.getSimpleName()} class cannot be applied for object detection evaluation using Yolo2OutputLayer: ${classifierEval.getSimpleName()} class is for classifier evaluation only. What it means
Deeplearning4j throws this IllegalStateException when a classifier-style evaluation class (e.g. Evaluation, ROCMultiClass) is passed to evaluation APIs while the network's output layer is a Yolo2OutputLayer. YOLO2 is an object-detection model whose output (bounding boxes, IoU, class probabilities per anchor) is fundamentally different from classification output, so classifier metrics are meaningless and validation is rejected up front. This check runs inside OutputLayerUtil.validateOutputLayerForClassifierEvaluation before evaluation begins.
Source
Thrown at deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/util/OutputLayerUtil.java:174
//However, we might miss a few invalid configs like dense(relu) -> loss(identity)
return false;
}
return true;
}
return false;
}
/**
* Validates if the output layer configuration is valid for classifier evaluation.
* This is used to try and catch invalid evaluation - i.e., trying to use classifier evaluation on a regression model.
* This method won't catch all possible invalid cases, but should catch some common problems.
*
* @param outputLayer Output layer
* @param classifierEval Class for the classifier evaluation
*/
public static void validateOutputLayerForClassifierEvaluation(Layer outputLayer, Class<? extends IEvaluation> classifierEval){
if(outputLayer instanceof Yolo2OutputLayer){
throw new IllegalStateException("Classifier evaluation using " + classifierEval.getSimpleName() + " class cannot be applied for object" +
" detection evaluation using Yolo2OutputLayer: " + classifierEval.getSimpleName() + " class is for classifier evaluation only.");
}
//Check that the activation function provides probabilities. This can't catch everything, but should catch a few
// of the common mistakes users make
if(outputLayer instanceof BaseLayer){
BaseLayer bl = (BaseLayer)outputLayer;
boolean isOutputLayer = outputLayer instanceof OutputLayer || outputLayer instanceof RnnOutputLayer || outputLayer instanceof CenterLossOutputLayer;
if(activationExceedsZeroOneRange(bl.getActivationFn(), !isOutputLayer)){
throw new IllegalStateException("Classifier evaluation using " + classifierEval.getSimpleName() + " class cannot be applied to output" +
" layers with activation functions that are not probabilities (in range 0 to 1). Output layer type: " +
outputLayer.getClass().getSimpleName() + " has activation function " + bl.getActivationFn().getClass().getSimpleName() +
". This check can be disabled using MultiLayerNetwork.getLayerWiseConfigurations().setValidateOutputLayerConfig(false)" +
" or ComputationGraph.getConfiguration().setValidateOutputLayerConfig(false)");
}
}
}View on GitHub (pinned to 4c22ac5fe4)
Solutions
- Use object-detection evaluation instead: run inference with Yolo2OutputLayer.applyPostProcessing / use the Yolo2 evaluation utilities (e.g. evaluate predictions with ODIA/Yolo post-processing and IoU-based detection metrics) rather than Evaluation/ROCMultiClass.
- If you actually intended classification, replace the output layer with a classifier-appropriate layer (OutputLayer with softmax/loss MCXENT) and rebuild the model.
- If you are sure and want to skip validation for experimentation, disable it via getLayerWiseConfigurations().setValidateOutputLayerConfig(false) (MLN) or getConfiguration().setValidateOutputLayerConfig(false) (ComputationGraph).
- Check that you loaded/trained the correct model; YOLO2 checkpoints cannot be evaluated with classifier metrics.
Example fix
// before Evaluation eval = new Evaluation(numClasses); ComputationGraph model = ...; // output layer: Yolo2OutputLayer model.evaluate(dataIter, eval); // throws // after: use YOLO post-processing + detection metrics INDArray[] out = model.output(features); // feed out through Yolo2OutputLayer post-processing (nms, confidence threshold) // and evaluate detections with IoU-based object-detection metrics
Defensive patterns
Strategy: validation
Validate before calling
if (net.getOutputLayer() instanceof Yolo2OutputLayer && evalClass == org.deeplearning4j.evaluation.Evaluation.class) {
throw new IllegalArgumentException("Use object-detection evaluation for Yolo2OutputLayer, not classifier Evaluation");
} Type guard
boolean isObjectDetection = net.getOutputType() instanceof org.deeplearning4j.nn.conf.layers.OutputLayer Util; // simpler: boolean isYolo = java.util.stream.Stream.of(net.getLayers()).anyMatch(l -> l instanceof org.deeplearning4j.nn.layers.objdetect.Yolo2OutputLayer);
Prevention
- Check the output layer type (Yolo2OutputLayer vs OutputLayer) before choosing an evaluation class.
- Use YOLO-specific post-processing and detection metrics instead of Evaluation/ROCMultiClass for detection models.
- Do not copy classifier evaluation snippets into object-detection pipelines.
- Avoid disabling validateOutputLayerConfig unless intentionally bypassing checks.
When it happens
Trigger: Calling Evaluation on a ComputationGraph/MultiLayerNetwork whose output layer is Yolo2OutputLayer, e.g. evaluation via model.evaluate(iterator), ComputationGraph.evaluate(DataSetIterator, Evaluation.class / ROCMultiClass.class), or training listeners that validate output layers with classifier evaluation classes.
Common situations: Building a YOLO2 object-detection network and using the standard classifier evaluation helpers copied from classification examples; switching a network's output layer to Yolo2OutputLayer while keeping old classification evaluation code; confusion because Yolo2OutputLayer extends BaseOutputLayer and looks like a normal output layer.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- Invalid confidence threshold: must be in range [0,1]. Got:
- Unknown enum state: ${this}
- Unknown: ${this}
- Not yet implemented
- Not supported
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/f6b95cb3edbf43a4.
Report an issue: GitHub.