{"record":{"id":"dd2404b769140775","repo":"deeplearning4j/deeplearning4j","slug":"number-of-inputs-specified-do-not-match-number-of","errorCode":null,"errorMessage":"Number of inputs specified do not match number of arrays specified.","messagePattern":"Number of inputs specified do not match number of arrays specified\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java","lineNumber":258,"sourceCode":"            }\n\n        return ret;\n    }\n\n    /**\n     * Run the graph definition with the given inputs\n     * in native tensorflow\n     * @param inputs the inputs to run\n     * @return the outputSchema from the native tensorflow wrapper\n     */\n    public Map<String, TF_Tensor> runTfTensor(Map<String, TF_Tensor> inputs) {\n        if(graph == null) {\n            throw new IllegalStateException(\"Graph not initialized.\");\n        }\n\n\n        if(!inputs.isEmpty() && inputOrder != null && inputs.size() != inputOrder.size()) {\n            throw new IllegalArgumentException(\"Number of inputs specified do not match number of arrays specified.\");\n        }\n\n        if(inputDataTypes == null) {\n            inputDataTypes = new LinkedHashMap<>();\n            if(inputOrder != null)\n                for(int i = 0; i < inputOrder.size(); i++) {\n                    inputDataTypes.put(inputOrder.get(i),TensorDataType.values()[TF_TensorType(inputs.get(inputOrder.get(i)))]);\n                }\n        }\n\n        for(Map.Entry<String, org.bytedeco.tensorflow.TF_Tensor> entry : inputs.entrySet()) {\n            Preconditions.checkNotNull(entry.getValue(),\"Entry \" + entry.getKey() + \" was null!\");\n        }\n\n        //recast for adapting input\n        inputs = recastInputs(inputs);\n\n","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java#L240-L276","documentation":"GraphRunner validates that the number of input tensors passed to runTfTensor matches the size of the configured inputOrder list (when both are non-empty/non-null). This IllegalArgumentException is thrown because TensorFlow sessions require each named placeholder in inputOrder to be fed exactly one array; a mismatch means inputs cannot be mapped onto graph placeholders.","triggerScenarios":"Calling GraphRunner.output(...) or outputTensors(...) with a map of inputs whose size differs from inputOrder (e.g. passing 2 arrays when inputOrder has 3 names, or vice versa), or passing inputs while inputOrder is set to a list loaded from SavedModel config that describes different placeholders.","commonSituations":"Renaming or adding model inputs after exporting a SavedModel without updating the runner's inputOrder; reusing one GraphRunner for two models with different input counts; accidentally including an extra key (e.g. a constant or is_training flag) in the inputs map.","solutions":["Align the keys/values of the inputs map with the runner's inputOrder list — same count and names, e.g. runner.inputOrder() to inspect it","Remove stale/extra entries from the inputs map that no longer exist as graph placeholders","Regenerate or update inputOrder (or the SavedModel's saved_model config) after changing the model's input signature","Use a SavedModelBundle-independent check: print graph operation names to confirm which placeholders actually exist before calling output"],"exampleFix":"// before\nMap<String, INDArray> inputs = new LinkedHashMap<>();\ninputs.put(\"input\", x);\ninputs.put(\"keep_prob\", dropout); // model has only 1 input\nINDArray out = runner.output(inputs);\n// after\nMap<String, INDArray> inputs = new LinkedHashMap<>();\ninputs.put(\"input\", x);\nINDArray out = runner.output(inputs); // size matches inputOrder","handlingStrategy":"validation","validationCode":"if (!inputs.isEmpty() && runner.inputOrder() != null && inputs.size() != runner.inputOrder().size()) {\n    throw new IllegalArgumentException(\"inputs.size()=\" + inputs.size() + \" != inputOrder.size()=\" + runner.inputOrder().size());\n}","typeGuard":"boolean inputsMatchOrder(GraphRunner r, Map<String, INDArray> in) {\n    return r.inputOrder() == null || in.isEmpty() || in.size() == r.inputOrder().size();\n}","tryCatchPattern":"try {\n    INDArray out = runner.output(inputs);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Number of inputs\")) {\n        log.error(\"Input count {} does not match inputOrder {}\", inputs.size(), runner.inputOrder());\n    }\n    throw e;\n}","preventionTips":["Log inputOrder and the input map keys at startup and assert they match before every run","Keep inputOrder in the same config file/registry as the model export so they change together","Write a unit test that calls output() with sample data for every model artifact you ship","Avoid ad-hoc additions to the inputs map; build it from inputOrder itself"],"tags":["java","nd4j","tensorflow","input-validation","graphrunner"],"backgroundTag":"missing-required-argument","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"}