{"record":{"id":"12fe20a0bebab018","repo":"deeplearning4j/deeplearning4j","slug":"invalid-confidence-threshold-must-be-in-range-0","errorCode":null,"errorMessage":"Invalid confidence threshold: must be in range [0,1]. Got: ","messagePattern":"Invalid confidence threshold: must be in range \\[0,1\\]\\. Got: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/layers/objdetect/YoloUtils.java","lineNumber":185,"sourceCode":"     * (before getting to the Yolo2OutputLayer) we have 13x13 grid cells (each corresponding to 32 pixels in the input\n     * image). Thus, a centerX of 5.5 would be xPixels=5.5x32 = 176 pixels from left. Widths and heights are similar:\n     * in this example, a with of 13 would be the entire image (416 pixels), and a height of 6.5 would be 6.5/13 = 0.5\n     * of the image (208 pixels).\n     *\n     * @param boundingBoxPriors as given to Yolo2OutputLayer\n     * @param networkOutput 4d activations out of the network\n     * @param confThreshold Detection threshold, in range 0.0 (least strict) to 1.0 (most strict). Objects are returned\n     *                     where predicted confidence is >= confThreshold\n     * @param nmsThreshold  passed to {@link #nms(List, double)} (0 == disabled) as the threshold for intersection over union (IOU)\n     * @return List of detected objects\n     */\n    public static List<DetectedObject> getPredictedObjects(INDArray boundingBoxPriors, INDArray networkOutput, double confThreshold, double nmsThreshold){\n        if(networkOutput.rank() != 4){\n            throw new IllegalStateException(\"Invalid network output activations array: should be rank 4. Got array \"\n                    + \"with shape \" + Arrays.toString(networkOutput.shape()));\n        }\n        if(confThreshold < 0.0 || confThreshold > 1.0){\n            throw new IllegalStateException(\"Invalid confidence threshold: must be in range [0,1]. Got: \" + confThreshold);\n        }\n\n        //Activations format: [mb, 5b+c, h, w]\n        long mb = networkOutput.size(0);\n        long h = networkOutput.size(2);\n        long w = networkOutput.size(3);\n        long b = boundingBoxPriors.size(0);\n        long c = (networkOutput.size(1)/b)-5;  //input.size(1) == b * (5 + C) -> C = (input.size(1)/b) - 5\n\n        //Reshape from [minibatch, B*(5+C), H, W] to [minibatch, B, 5+C, H, W] to [minibatch, B, 5, H, W]\n        INDArray output5 = networkOutput.dup('c').reshape(mb, b, 5+c, h, w);\n        INDArray predictedConfidence = output5.get(all(), all(), point(4), all(), all());    //Shape: [mb, B, H, W]\n        INDArray softmax = output5.get(all(), all(), interval(5, 5+c), all(), all());\n\n        List<DetectedObject> out = new ArrayList<>();\n        for( int i=0; i<mb; i++ ){\n            for( int x=0; x<w; x++ ){\n                for( int y=0; y<h; y++ ){","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/layers/objdetect/YoloUtils.java#L167-L203","documentation":"YoloUtils.getPredictedObjects() validates the confidence threshold used to filter YOLO detections. Deeplearning4j throws this IllegalStateException because a threshold outside [0,1] would make the confidence filtering meaningless (confidences are probabilities in [0,1]). It fails fast instead of returning empty or bogus detections.","triggerScenarios":"Calling YoloUtils.getPredictedObjects(boundingBoxPriors, networkOutput, confThreshold, nmsThreshold) with a confThreshold < 0.0 or > 1.0, e.g. 50 or -0.1.","commonSituations":"Passing a threshold expressed as a percentage (0-100) instead of a fraction; loading a threshold from config in the wrong scale; sign errors when tuning thresholds.","solutions":["Pass the threshold as a fraction in [0,1], e.g. 0.5 for 50%","Divide a percentage-style config value by 100 before calling","Clamp the value with Math.min(1.0, Math.max(0.0, conf)) before the call"],"exampleFix":"// before\nList<DetectedObject> objs = YoloUtils.getPredictedObjects(priors, output, 50, 0.45);\n// after\nList<DetectedObject> objs = YoloUtils.getPredictedObjects(priors, output, 0.5, 0.45);","handlingStrategy":"validation","validationCode":"if (confThreshold < 0.0 || confThreshold > 1.0) throw new IllegalArgumentException(\"confThreshold must be in [0,1], got \" + confThreshold);","typeGuard":"boolean validThreshold(double t) { return !Double.isNaN(t) && t >= 0.0 && t <= 1.0; }","tryCatchPattern":"try {\n    objs = YoloUtils.getPredictedObjects(priors, output, conf, nms);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"confidence threshold\")) {\n        objs = YoloUtils.getPredictedObjects(priors, output, Math.min(1.0, Math.max(0.0, conf)), nms);\n    } else throw e;\n}","preventionTips":["Store thresholds as fractions (0-1) in config, never percentages","Clamp thresholds at the config-loading boundary","Unit-test threshold parsing from config files"],"tags":["yolo","object-detection","validation","deeplearning4j"],"backgroundTag":"value-out-of-range","analyzedSha":"4c22ac5fe4a8350d05d224e7f4499429f7f69c93","analyzedAt":"2026-09-07T05:27:04.714Z","contentChangedAt":"2026-09-07T05:27:04.714Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}