东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 4186|回复: 0
打印 上一主题 下一主题

[课堂笔记] "Tensor %s is not an element of this graph." % obj) Tensor shape=

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14429
QQ
跳转到指定楼层
楼主
发表于 2020-3-13 12:22:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("activation_25/truediv:0", shape=(?, ?, 1, 84), dtype=float32) is not an element of this graph.

以上报错,是在keras模型部署到python的flask服务器 遇到  估计django也会出现

从提示看:不是图的一个元素  说明图已经变了

为了保持图的唯一的默认图:

# 定义一个全局的图变量
import tensorflow as tf
global graph

# 赋值
graph = tf.get_default_graph()

# 使用模型预测时 加上
with graph.as_default():
   y_pred = 你的model.predict(X)



注意:每个py文件中 只要出现了模型预测的地方 都需要加上面的代码





让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-4-20 19:19 , Processed in 0.187174 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表