如何将Keras 1.1.0的model.json适配至TensorFlow 2.3.1?
Fixing Keras 1.x Model JSON Compatibility with TensorFlow 2.3.1
The error you're hitting stems from outdated parameter names in your Keras 1.1.0-saved model JSON—these conventions changed significantly in modern TensorFlow/Keras (TF2.x). Here's exactly how to update your model.json to load successfully:
Critical Parameter Replacements
Keras 1.x used different naming for core layer arguments that TF2.x no longer recognizes. For every Dense layer in your JSON:
- Replace
output_dimwithunits(this is the direct cause of yourmissing 'units' argumenterror) - Swap
initforkernel_initializer - Rename
W_regularizertokernel_regularizer - Change
b_regularizertobias_regularizer - Update
W_constrainttokernel_constraint - Replace
b_constraintwithbias_constraint - Switch
biastouse_bias(another TF2.x naming update)
For Dropout layers:
- Replace
p(dropout rate) withrateto align with TF2.x syntax
Updated Model JSON
Here's the fully revised version of your model.json that will load correctly in TF2.3.1:
{ "class_name":"Sequential", "keras_version":"2.3.1", "config":[ { "class_name":"Dense", "config":{ "kernel_constraint":null, "bias_constraint":null, "name":"dense_1", "units":512, "activity_regularizer":null, "trainable":true, "kernel_initializer":"glorot_normal", "use_bias":true, "input_dtype":"float32", "input_dim":4096, "bias_regularizer":null, "kernel_regularizer":{ "l2":0.0010000000474974513, "name":"WeightRegularizer", "l1":0.0 }, "activation":"relu", "batch_input_shape":[null,4096] } }, { "class_name":"Dropout", "config":{ "rate":0.6, "trainable":true, "name":"dropout_1" } }, { "class_name":"Dense", "config":{ "kernel_constraint":null, "bias_constraint":null, "name":"dense_2", "activity_regularizer":null, "trainable":true, "kernel_initializer":"glorot_normal", "use_bias":true, "input_dim":null, "bias_regularizer":null, "kernel_regularizer":{ "l2":0.0010000000474974513, "name":"WeightRegularizer", "l1":0.0 }, "activation":"linear", "units":32 } }, { "class_name":"Dropout", "config":{ "rate":0.6, "trainable":true, "name":"dropout_2" } }, { "class_name":"Dense", "config":{ "kernel_constraint":null, "bias_constraint":null, "name":"dense_3", "activity_regularizer":null, "trainable":true, "kernel_initializer":"glorot_normal", "use_bias":true, "input_dim":null, "bias_regularizer":null, "kernel_regularizer":{ "l2":0.0010000000474974513, "name":"WeightRegularizer", "l1":0.0 }, "activation":"sigmoid", "units":1 } } ] }
Quick Extra Notes
- I updated the
keras_versionfield to match your TF2.3.1 environment (Keras bundled with TF2.3.1 is version 2.3.1) - All original regularization values and layer configurations are preserved—only the parameter names are adjusted
Save this revised JSON, and you should be able to load it using tensorflow.keras.models.model_from_json() without any type errors.
内容的提问来源于stack exchange,提问作者WurmD
相关产品推荐
相关产品推荐

