{"record":{"id":"c0cde1baa19d642a","repo":"deeplearning4j/deeplearning4j","slug":"parameter-does-not-exist-in-weights-c0cde1","errorCode":null,"errorMessage":"Parameter {} does not exist in weights","messagePattern":"Parameter (.+?) does not exist in weights","errorType":"exception","errorClass":"InvalidKerasConfigurationException","httpStatus":null,"severity":"error","filePath":"deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/layers/local/KerasLocallyConnected1D.java","lineNumber":168,"sourceCode":"        if (preprocessor != null) {\n            return this.getLocallyConnected1DLayer().getOutputType(-1, preprocessor.getOutputType(inputType[0]));\n        }\n        return this.getLocallyConnected1DLayer().getOutputType(-1, inputType[0]);\n    }\n\n    /**\n     * Set weights for 1D locally connected layer.\n     *\n     * @param weights Map from parameter name to INDArray.\n     */\n    @Override\n    public void setWeights(Map<String, INDArray> weights) throws InvalidKerasConfigurationException {\n        this.weights = new HashMap<>();\n        if (weights.containsKey(conf.getKERAS_PARAM_NAME_W())) {\n            INDArray kerasParamValue = weights.get(conf.getKERAS_PARAM_NAME_W());\n            this.weights.put(ConvolutionParamInitializer.WEIGHT_KEY, kerasParamValue);\n        } else\n            throw new InvalidKerasConfigurationException(\n                    \"Parameter \" + conf.getKERAS_PARAM_NAME_W() + \" does not exist in weights\");\n\n        if (hasBias) {\n            if (weights.containsKey(conf.getKERAS_PARAM_NAME_B()))\n                this.weights.put(ConvolutionParamInitializer.BIAS_KEY, weights.get(conf.getKERAS_PARAM_NAME_B()));\n            else\n                throw new InvalidKerasConfigurationException(\n                        \"Parameter \" + conf.getKERAS_PARAM_NAME_B() + \" does not exist in weights\");\n        }\n        KerasLayerUtils.removeDefaultWeights(weights, conf);\n    }\n\n}\n","sourceCodeStart":150,"sourceCodeEnd":182,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/layers/local/KerasLocallyConnected1D.java#L150-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nkerasLayer.setWeights(weights); // map may lack 'kernel'\n// after\nif (!weights.containsKey(\"kernel\")) {\n    Map<String, INDArray> fixed = new HashMap<>(weights);\n    fixed.put(\"kernel\", weights.get(\"W\")); // rename legacy key\n    kerasLayer.setWeights(fixed);\n} else {\n    kerasLayer.setWeights(weights);\n}","handlingStrategy":"validation","validationCode":"if (weights == null || !weights.containsKey(kerasConf.getKERAS_PARAM_NAME_W())) {\n    throw new IllegalArgumentException(\"weights map missing kernel param \" + kerasConf.getKERAS_PARAM_NAME_W()\n            + \"; available keys: \" + (weights == null ? \"null\" : weights.keySet()));\n}\nkerasLayer.setWeights(weights);","typeGuard":null,"tryCatchPattern":"try {\n    kerasLayer.setWeights(weights);\n} catch (InvalidKerasConfigurationException e) {\n    LOG.error(\"Missing kernel weight for layer {}: keys={}\", layerName, weights.keySet(), e);\n    throw new IllegalStateException(\"Weight import failed: align Keras version or rename weight keys\", e);\n}","preventionTips":["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."],"tags":["keras","model-import","missing-weight-parameter","configuration"],"backgroundTag":"missing-required-config-field","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"}