首页 > 其他 > 详细

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

时间:2018-04-26 22:57:40      阅读:2879      评论:0      收藏:0      [点我收藏+]

用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

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

原文:https://www.cnblogs.com/bymo/p/8955009.html

(0)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!