deeplearning4j/deeplearning4j · error · UnsupportedKerasConfigurationException
Could not determine number of input channels fordepthwise…
Error message
Could not determine number of input channels fordepthwise convolution.
What it means
Thrown by KerasLayer.getNInFromConfig when the importer cannot figure out the number of input channels for a depthwise (separable) convolution layer. It walks the inbound layers graph to find an upstream layer that can supply an input size; if every candidate fails to yield one, it gives up with an UnsupportedKerasConfigurationException. Note the code path itself is buggy: the catch clause retries the same get(0) call that already failed.
Solutions
- Inspect the model JSON/H5 inbound node list feeding the depthwise conv; ensure it connects to a supported layer (Conv2D, Input, pooling, etc.)
- Rebuild the Keras model inserting an explicit Input/known layer before the depthwise conv so nIn can be inferred
- Explicitly set the layer's input channel count in the Keras config if the serialization supports it
- Import a newer/older export of the model that preserves a traversable inbound graph
- Use a custom KerasLayer subclass overriding getNInFromConfig for this graph shape
Example fix
// before: DepthwiseConv2D fed by unsupported Lambda layer -> nIn undeterminable x = Lambda(f)(x); y = DepthwiseConv2D(3)(x) // after: feed conv from a known layer or explicit Input x = Conv2D(16, 3)(inputs); y = DepthwiseConv2D(3)(x)
Defensive patterns
Strategy: validation
Validate before calling
Set<String> inbound = kerasLayer.getInboundLayerNames();
if (inbound == null || inbound.isEmpty())
throw new IllegalStateException("Depthwise conv layer '" + name + "' has no inbound layer; add an Input/known layer upstream"); Type guard
null
Try / catch
try {
long nIn = kerasLayer.getNInFromConfig(inboundLayers);
} catch (UnsupportedKerasConfigurationException e) {
throw new IllegalStateException("Cannot infer input channels for depthwise conv; ensure upstream layer is supported: " + e.getMessage(), e);
} Prevention
- Keep depthwise conv layers directly downstream of supported layers (Conv2D, Input, pooling)
- Avoid Lambda/custom layers immediately before depthwise convs in imported models
- Export Keras graphs with a fully connected inbound-node structure (avoid disconnected inputs)
When it happens
Trigger: Importing a DepthwiseConv2D/separable conv layer whose inbound layer list is empty, whose first inbound layer is not a known inbound layer, or whose first inbound layer itself cannot report nIn.
Common situations: Functional Keras models where the depthwise conv hangs off an unsupported layer type (e.g. a Lambda or unknown layer) in the graph; model graphs saved with disconnected inputs; very old or very new Keras graph serialization the importer cannot traverse.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot add vertex to MultiLayerConfiguration
- Cannot determine output type for Keras layer of type
- Could not find layer configurations
- <e.getMessage()> Tried to set weights for layer with name
- For RNN type input data, permutation dims have to be" +…
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/8bed0c86d0482db4.
Report an issue: GitHub.
Appendix: source
Thrown at deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/KerasLayer.java:445
int count = 0;
long nIn;
String inboundLayerName = inboundLayerNames.get(0);
while (count <= size) {
if (previousLayers.containsKey(inboundLayerName)) {
KerasLayer inbound = previousLayers.get(inboundLayerName);
try {
FeedForwardLayer ffLayer = (FeedForwardLayer) inbound.getLayer();
nIn = ffLayer.getNOut();
if (nIn > 0)
return nIn;
count++;
inboundLayerName = inbound.getInboundLayerNames().get(0);
} catch (Exception e) {
inboundLayerName = inbound.getInboundLayerNames().get(0);
}
}
}
throw new UnsupportedKerasConfigurationException("Could not determine number of input channels for" +
"depthwise convolution.");
}
/**
* Gets appropriate DL4J InputPreProcessor for given InputTypes.
*
* @param inputType Array of InputTypes
* @return DL4J InputPreProcessor
* @throws InvalidKerasConfigurationException Invalid Keras configuration
* @see org.deeplearning4j.nn.conf.InputPreProcessor
*/
public InputPreProcessor getInputPreprocessor(InputType... inputType) throws InvalidKerasConfigurationException {
InputPreProcessor preprocessor = null;
if (this.layer != null) {
if (inputType.length > 1) {
InputType toUse = null;
for(int i = 0; i < inputType.length; i++) {View on GitHub (pinned to 4c22ac5fe4)