deeplearning4j/deeplearning4j · error · InvalidKerasConfigurationException
Parameter does not exist in weights
Error message
Parameter {} does not exist in weights What it means
KerasLocallyConnected1D.setWeights() builds the DL4J layer weights map from the Keras H5 weights map. If the map has no entry under the Keras kernel parameter name (conf.getKERAS_PARAM_NAME_W(), typically 'kernel' or 'W' depending on Keras version), it throws InvalidKerasConfigurationException. This means the loaded weight map does not match what this layer expects, usually because the Keras model file was saved with a different Keras version or the weight names were mismatched during import.
Solutions
- Check the keys of the weights map (weights.keySet()) and confirm one matches conf.getKERAS_PARAM_NAME_W() before calling setWeights.
- Ensure the Keras major version used to save the model matches the one configured in the importer (KerasModelImport / conf), since parameter names differ ('W'/'b' in Keras 1, 'kernel'/'bias' in Keras 2).
- Rename the key in the map to the expected parameter name before calling setWeights.
- Re-save the Keras model (model.save) with a compatible Keras version and re-export the weights.
Example fix
// before
kerasLayer.setWeights(weights); // map may lack 'kernel'
// after
if (!weights.containsKey("kernel")) {
Map<String, INDArray> fixed = new HashMap<>(weights);
fixed.put("kernel", weights.get("W")); // rename legacy key
kerasLayer.setWeights(fixed);
} else {
kerasLayer.setWeights(weights);
} Defensive patterns
Strategy: validation
Validate before calling
if (weights == null || !weights.containsKey(kerasConf.getKERAS_PARAM_NAME_W())) {
throw new IllegalArgumentException("weights map missing kernel param " + kerasConf.getKERAS_PARAM_NAME_W()
+ "; available keys: " + (weights == null ? "null" : weights.keySet()));
}
kerasLayer.setWeights(weights); Try / catch
try {
kerasLayer.setWeights(weights);
} catch (InvalidKerasConfigurationException e) {
LOG.error("Missing kernel weight for layer {}: keys={}", layerName, weights.keySet(), e);
throw new IllegalStateException("Weight import failed: align Keras version or rename weight keys", e);
} Prevention
- Log weights.keySet() before import and diff against expected Keras parameter names.
- Match the importer's Keras major version (1 vs 2) to the saved model's version.
- Prefer KerasModelImport on the full H5 file over hand-assembled weight maps.
- Write an integration test that imports each production Keras model once.
When it happens
Trigger: Calling setWeights(Map<String, INDArray>) on a KerasLocallyConnected1D layer with a weights map that lacks the key returned by conf.getKERAS_PARAM_NAME_W() — e.g. importing an H5 file whose kernel tensor is named differently ('W' vs 'kernel') than the mapping config expects.
Common situations: Importing Keras 1 model weights into the DL4J importer configured for Keras 2 naming (or vice versa); manually renaming keys in the weights map; loading a subset of weights from a multi-layer H5 file; missing 'kernel' tensor because the layer was saved without trained weights.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- Parameter does not exist in weights
- Could not determine Keras model class
- Keras Activation layer accepts only one input (received
- Keras Activation layer accepts only one input (received
- Keras Activation layer accepts only one input (received
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/c0cde1baa19d642a.
Report an issue: GitHub.
Appendix: source
Thrown at deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/layers/local/KerasLocallyConnected1D.java:168
if (preprocessor != null) {
return this.getLocallyConnected1DLayer().getOutputType(-1, preprocessor.getOutputType(inputType[0]));
}
return this.getLocallyConnected1DLayer().getOutputType(-1, inputType[0]);
}
/**
* Set weights for 1D locally connected layer.
*
* @param weights Map from parameter name to INDArray.
*/
@Override
public void setWeights(Map<String, INDArray> weights) throws InvalidKerasConfigurationException {
this.weights = new HashMap<>();
if (weights.containsKey(conf.getKERAS_PARAM_NAME_W())) {
INDArray kerasParamValue = weights.get(conf.getKERAS_PARAM_NAME_W());
this.weights.put(ConvolutionParamInitializer.WEIGHT_KEY, kerasParamValue);
} else
throw new InvalidKerasConfigurationException(
"Parameter " + conf.getKERAS_PARAM_NAME_W() + " does not exist in weights");
if (hasBias) {
if (weights.containsKey(conf.getKERAS_PARAM_NAME_B()))
this.weights.put(ConvolutionParamInitializer.BIAS_KEY, weights.get(conf.getKERAS_PARAM_NAME_B()));
else
throw new InvalidKerasConfigurationException(
"Parameter " + conf.getKERAS_PARAM_NAME_B() + " does not exist in weights");
}
KerasLayerUtils.removeDefaultWeights(weights, conf);
}
}
View on GitHub (pinned to 4c22ac5fe4)