您的位置:首页 > 产品设计 > UI/UE

解决在django中应用keras模型时出现的ValueError("Tensor %s is not an element of this graph." % obj)问题

2018-04-26 21:03 661 查看

用keras训练好模型,再在django初始化加载模型,这个过程没有问题,但是在调用到模型执行model.predict()的时候就报错:

raise ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("dense_2/Softmax:0", shape=(?, 2), dtype=float32) is not an element of this graph.

解决方法:

在django中加载模型后,先执行一次model.predict()操作,之后的调用就不会出问题了

model = load_model(filepath=model_path)
y = model.predict(x)

 

参考:https://zhuanlan.zhihu.com/p/27101000

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐