模型预测报错:is not an element of this graph(已解决)

原代码:

……
model = ResNet50(weights='imagenet')
……
def main():
x = model.predict(x)

 

改为:

……
import tensorflow as tf
from tensorflow.python.keras.backend import set_session
from tensorflow.python.keras.models import load_model
tf_config = tf.ConfigProto()
sess = tf.Session(config=tf_config)
graph = tf.get_default_graph()

set_session(sess)
model = ResNet50(weights='imagenet')
……
def main():
global sess
global graph
with graph.as_default():
set_session(sess)
x = model.predict(x)

 

posted @ 2022-03-03 15:49  牛郎  阅读(166)  评论(0编辑  收藏  举报