码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-04-26 23:30:29      阅读:2298      评论:0      收藏:0      [点我收藏+]

标签:error   err   code   bsp   ict   ISE   erro   django   obj   

用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)问题

标签:error   err   code   bsp   ict   ISE   erro   django   obj   

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

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!