Loading model from json object Keras











up vote
0
down vote

favorite












My script to load Keras CNN model from saved json object is as follows:



import keras
from keras.models import model_from_json
json_file = open('k_model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)


model_from_json is throwing the following error :



TypeError: __init__() takes at least 4 arguments (3 given)


Has anyone faced similar issue?



Note: In Python3 it works fine, even in Python2.7 it was working fine earlier.



Complete stack trace as follows :



Using TensorFlow backend.
Traceback (most recent call last):
File "test.py", line 63, in <module>
loaded_model = model_from_json(loaded_model_json)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 197, in model_from_json
return layer_from_config(config, custom_objects=custom_objects)
File "/usr/local/lib/python2.7/dist-packages/keras/utils/layer_utils.py", line 36, in layer_from_config
return layer_class.from_config(config['config'])
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 1019, in from_config
layer = get_or_create_layer(first_layer)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 1003, in get_or_create_layer
layer = layer_from_config(layer_data)
File "/usr/local/lib/python2.7/dist-packages/keras/utils/layer_utils.py", line 36, in layer_from_config
return layer_class.from_config(config['config'])
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 929, in from_config
return cls(**config)
TypeError: __init__() takes at least 4 arguments (3 given)
Failed with exit code: 1









share|improve this question
























  • It's very hard to know where this error is coming from. Can you put the entire stack trace?
    – Daniel Möller
    Nov 18 at 22:53










  • @DanielMöller - Edited the post with complete stack trace
    – iprof0214
    Nov 19 at 7:11










  • Hmmm, hard to tell, but it seems there is some kind of bug or version incompatibility there.
    – Daniel Möller
    Nov 20 at 1:04















up vote
0
down vote

favorite












My script to load Keras CNN model from saved json object is as follows:



import keras
from keras.models import model_from_json
json_file = open('k_model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)


model_from_json is throwing the following error :



TypeError: __init__() takes at least 4 arguments (3 given)


Has anyone faced similar issue?



Note: In Python3 it works fine, even in Python2.7 it was working fine earlier.



Complete stack trace as follows :



Using TensorFlow backend.
Traceback (most recent call last):
File "test.py", line 63, in <module>
loaded_model = model_from_json(loaded_model_json)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 197, in model_from_json
return layer_from_config(config, custom_objects=custom_objects)
File "/usr/local/lib/python2.7/dist-packages/keras/utils/layer_utils.py", line 36, in layer_from_config
return layer_class.from_config(config['config'])
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 1019, in from_config
layer = get_or_create_layer(first_layer)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 1003, in get_or_create_layer
layer = layer_from_config(layer_data)
File "/usr/local/lib/python2.7/dist-packages/keras/utils/layer_utils.py", line 36, in layer_from_config
return layer_class.from_config(config['config'])
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 929, in from_config
return cls(**config)
TypeError: __init__() takes at least 4 arguments (3 given)
Failed with exit code: 1









share|improve this question
























  • It's very hard to know where this error is coming from. Can you put the entire stack trace?
    – Daniel Möller
    Nov 18 at 22:53










  • @DanielMöller - Edited the post with complete stack trace
    – iprof0214
    Nov 19 at 7:11










  • Hmmm, hard to tell, but it seems there is some kind of bug or version incompatibility there.
    – Daniel Möller
    Nov 20 at 1:04













up vote
0
down vote

favorite









up vote
0
down vote

favorite











My script to load Keras CNN model from saved json object is as follows:



import keras
from keras.models import model_from_json
json_file = open('k_model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)


model_from_json is throwing the following error :



TypeError: __init__() takes at least 4 arguments (3 given)


Has anyone faced similar issue?



Note: In Python3 it works fine, even in Python2.7 it was working fine earlier.



Complete stack trace as follows :



Using TensorFlow backend.
Traceback (most recent call last):
File "test.py", line 63, in <module>
loaded_model = model_from_json(loaded_model_json)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 197, in model_from_json
return layer_from_config(config, custom_objects=custom_objects)
File "/usr/local/lib/python2.7/dist-packages/keras/utils/layer_utils.py", line 36, in layer_from_config
return layer_class.from_config(config['config'])
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 1019, in from_config
layer = get_or_create_layer(first_layer)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 1003, in get_or_create_layer
layer = layer_from_config(layer_data)
File "/usr/local/lib/python2.7/dist-packages/keras/utils/layer_utils.py", line 36, in layer_from_config
return layer_class.from_config(config['config'])
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 929, in from_config
return cls(**config)
TypeError: __init__() takes at least 4 arguments (3 given)
Failed with exit code: 1









share|improve this question















My script to load Keras CNN model from saved json object is as follows:



import keras
from keras.models import model_from_json
json_file = open('k_model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)


model_from_json is throwing the following error :



TypeError: __init__() takes at least 4 arguments (3 given)


Has anyone faced similar issue?



Note: In Python3 it works fine, even in Python2.7 it was working fine earlier.



Complete stack trace as follows :



Using TensorFlow backend.
Traceback (most recent call last):
File "test.py", line 63, in <module>
loaded_model = model_from_json(loaded_model_json)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 197, in model_from_json
return layer_from_config(config, custom_objects=custom_objects)
File "/usr/local/lib/python2.7/dist-packages/keras/utils/layer_utils.py", line 36, in layer_from_config
return layer_class.from_config(config['config'])
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 1019, in from_config
layer = get_or_create_layer(first_layer)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 1003, in get_or_create_layer
layer = layer_from_config(layer_data)
File "/usr/local/lib/python2.7/dist-packages/keras/utils/layer_utils.py", line 36, in layer_from_config
return layer_class.from_config(config['config'])
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 929, in from_config
return cls(**config)
TypeError: __init__() takes at least 4 arguments (3 given)
Failed with exit code: 1






python keras neural-network conv-neural-network data-science






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 7:11

























asked Nov 18 at 21:07









iprof0214

7210




7210












  • It's very hard to know where this error is coming from. Can you put the entire stack trace?
    – Daniel Möller
    Nov 18 at 22:53










  • @DanielMöller - Edited the post with complete stack trace
    – iprof0214
    Nov 19 at 7:11










  • Hmmm, hard to tell, but it seems there is some kind of bug or version incompatibility there.
    – Daniel Möller
    Nov 20 at 1:04


















  • It's very hard to know where this error is coming from. Can you put the entire stack trace?
    – Daniel Möller
    Nov 18 at 22:53










  • @DanielMöller - Edited the post with complete stack trace
    – iprof0214
    Nov 19 at 7:11










  • Hmmm, hard to tell, but it seems there is some kind of bug or version incompatibility there.
    – Daniel Möller
    Nov 20 at 1:04
















It's very hard to know where this error is coming from. Can you put the entire stack trace?
– Daniel Möller
Nov 18 at 22:53




It's very hard to know where this error is coming from. Can you put the entire stack trace?
– Daniel Möller
Nov 18 at 22:53












@DanielMöller - Edited the post with complete stack trace
– iprof0214
Nov 19 at 7:11




@DanielMöller - Edited the post with complete stack trace
– iprof0214
Nov 19 at 7:11












Hmmm, hard to tell, but it seems there is some kind of bug or version incompatibility there.
– Daniel Möller
Nov 20 at 1:04




Hmmm, hard to tell, but it seems there is some kind of bug or version incompatibility there.
– Daniel Möller
Nov 20 at 1:04

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365464%2floading-model-from-json-object-keras%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365464%2floading-model-from-json-object-keras%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]