Keras load_from_json JsonError
See original GitHub issueI’m loading a net architecture from a json, here is the json: ` { “backend”:“tensorflow”, “keras_version”:“2.0.3”, “config”:[ { “config”:{ “batch_input_shape”:[ null, 6, 6, 9 ], “kernel_constraint”:null, “name”:“dense_1”, “dtype”:“float32”, “units”:24, “bias_constraint”:null, “kernel_initializer”:{ “config”:{ “scale”:1.0, “distribution”:“uniform”, “mode”:“fan_avg”, “seed”:null }, “class_name”:“VarianceScaling” }, “use_bias”:true, “kernel_regularizer”:null, “bias_regularizer”:null, “activation”:“relu”, “trainable”:true, “bias_initializer”:{ “config”:{
},
"class_name":"Zeros"
},
"activity_regularizer":null
},
"class_name":"Dense"
},
{
"config":{
"rate":0.25,
"name":"dropout_1",
"trainable":true
},
"class_name":"Dropout"
},
{
"config":{
"kernel_constraint":null,
"name":"dense_2",
"units":24,
"bias_constraint":null,
"kernel_initializer":{
"config":{
"scale":1.0,
"distribution":"uniform",
"mode":"fan_avg",
"seed":null
},
"class_name":"VarianceScaling"
},
"use_bias":true,
"kernel_regularizer":null,
"bias_regularizer":null,
"activation":"relu",
"trainable":true,
"bias_initializer":{
"config":{
},
"class_name":"Zeros"
},
"activity_regularizer":null
},
"class_name":"Dense"
},
{
"config":{
"rate":0.5,
"name":"dropout_2",
"trainable":true
},
"class_name":"Dropout"
},
{
"config":{
"name":"flatten_1",
"trainable":true
},
"class_name":"Flatten"
},
{
"config":{
"kernel_constraint":null,
"name":"dense_3",
"units":1,
"bias_constraint":null,
"kernel_initializer":{
"config":{
"scale":1.0,
"distribution":"uniform",
"mode":"fan_avg",
"seed":null
},
"class_name":"VarianceScaling"
},
"use_bias":true,
"kernel_regularizer":null,
"bias_regularizer":null,
"activation":"sigmoid",
"trainable":true,
"bias_initializer":{
"config":{
},
"class_name":"Zeros"
},
"activity_regularizer":null
},
"class_name":"Dense"
}
], “class_name”:“Sequential” } `
and this is the error: Traceback (most recent call last): File “D:\workspace2\NN\src\ModelLoader.py”, line 19, in <module> model2 = model_from_json(‘ModelNoComp2Dense24Nueuroni.json’) File “C:\Users\emanuele\python3.5\lib\site-packages\keras-2.0.3-py3.5.egg\keras\models.py”, line 332, in model_from_json config = json.loads(json_string.encode().decode()) File “C:\Users\emanuele\python3.5\lib\json_init_.py”, line 319, in loads return _default_decoder.decode(s) File “C:\Users\emanuele\python3.5\lib\json\decoder.py”, line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File “C:\Users\emanuele\python3.5\lib\json\decoder.py”, line 357, in raw_decode raise JSONDecodeError(“Expecting value”, s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
i’m loading the model with:
model2 = model_from_json(‘ModelNoComp2Dense24Nueuroni.json’)
Issue Analytics
- State:
- Created 6 years ago
- Comments:8
For anyone who ends up here due to the
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
issue (as I did): Themodel_from_json()
method expects a JSON string as its first parameter, not the name of a JSON file. So the following worked for me:I had the same issue and came up with the following workaround: