I have a model with me named "model.json" and I want to use that trained model in my python code so so you tell me how to convert the code or how can I load the "model.json" file in python to use that for any use.
Asked
Active
Viewed 933 times
0
-
Please look at this https://stackoverflow.com/questions/45791891/reading-and-writing-json-through-python/45791955 – Timothy Dalton Jul 17 '20 at 13:49
-
Thank you so much but I want to use my json file tho train model in cnn and its not helping . – SAHASRANSU KAR Jul 17 '20 at 13:58
1 Answers
0
you must of course also save the model weights in h5 format. If you want to load the model from json do this
json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
#load weights into new model
loaded_model.load_weights("model.h5")
From your code i read you upload a dict so try this:
from keras.models import model_from_config
model = model_from_config(model_dict)
the model dict is the json.
For the placeholder problem try:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
Let me know if you've solved it

Zrufy
- 423
- 9
- 22
-
Thank you, I have tried that but I get "AttributeError: module 'tensorflow' has no attribute 'placeholder' " Error when I use it – SAHASRANSU KAR Jul 17 '20 at 14:27
-
Its not working getting this Error now for key, item in cls_config.items(): AttributeError: 'list' object has no attribute 'items' – SAHASRANSU KAR Jul 17 '20 at 14:58
-
Can share your code?Because this error is not from tensorflow but from other. – Zrufy Jul 17 '20 at 15:17
-
It is the link to the code it has the model named model.json & tring to run Demo_GPU.py – SAHASRANSU KAR Jul 17 '20 at 16:09
-