deeplearning4j/deeplearning4j · error · IllegalArgumentException
Number of inputs specified do not match number of arrays…
Error message
Number of inputs specified do not match number of arrays specified.
What it means
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.
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
Example fix
// before
Map<String, INDArray> inputs = new LinkedHashMap<>();
inputs.put("input", x);
inputs.put("keep_prob", dropout); // model has only 1 input
INDArray out = runner.output(inputs);
// after
Map<String, INDArray> inputs = new LinkedHashMap<>();
inputs.put("input", x);
INDArray out = runner.output(inputs); // size matches inputOrder Defensive patterns
Strategy: validation
Validate before calling
if (!inputs.isEmpty() && runner.inputOrder() != null && inputs.size() != runner.inputOrder().size()) {
throw new IllegalArgumentException("inputs.size()=" + inputs.size() + " != inputOrder.size()=" + runner.inputOrder().size());
} Type guard
boolean inputsMatchOrder(GraphRunner r, Map<String, INDArray> in) {
return r.inputOrder() == null || in.isEmpty() || in.size() == r.inputOrder().size();
} Try / catch
try {
INDArray out = runner.output(inputs);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("Number of inputs")) {
log.error("Input count {} does not match inputOrder {}", inputs.size(), runner.inputOrder());
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Illegal output found
- ERROR: Unable to convert tensor
- ERROR: Unable to run session
- ERROR: Unable to set value configuration:
- GraphRunner not initialized.
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/dd2404b769140775.
Report an issue: GitHub.
Appendix: source
Thrown at nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java:258
}
return ret;
}
/**
* Run the graph definition with the given inputs
* in native tensorflow
* @param inputs the inputs to run
* @return the outputSchema from the native tensorflow wrapper
*/
public Map<String, TF_Tensor> runTfTensor(Map<String, TF_Tensor> inputs) {
if(graph == null) {
throw new IllegalStateException("Graph not initialized.");
}
if(!inputs.isEmpty() && inputOrder != null && inputs.size() != inputOrder.size()) {
throw new IllegalArgumentException("Number of inputs specified do not match number of arrays specified.");
}
if(inputDataTypes == null) {
inputDataTypes = new LinkedHashMap<>();
if(inputOrder != null)
for(int i = 0; i < inputOrder.size(); i++) {
inputDataTypes.put(inputOrder.get(i),TensorDataType.values()[TF_TensorType(inputs.get(inputOrder.get(i)))]);
}
}
for(Map.Entry<String, org.bytedeco.tensorflow.TF_Tensor> entry : inputs.entrySet()) {
Preconditions.checkNotNull(entry.getValue(),"Entry " + entry.getKey() + " was null!");
}
//recast for adapting input
inputs = recastInputs(inputs);
View on GitHub (pinned to 4c22ac5fe4)