东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

[课堂笔记] FailedPreconditionError: Error while reading resource variable was uninitialized

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14435
QQ
跳转到指定楼层
楼主
发表于 2020-3-13 13:32:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
问题变了:
tensorflow.python.framework.errors_impl.FailedPreconditionError: Error while reading resource variable batch_normalization_2/moving_mean from Container: localhost.
This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/batch_normalization_2/moving_mean)
         [[{{node batch_normalization_2/cond/FusedBatchNormV3/ReadVariableOp}}]]




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


从提示看:读资源变量出错  变量没有初始化等   这里意思是session已经变了


为了保持只使用一个session:


# 定义一个全局的sess变量
global sess
sess = tf.Session(graph=graph)  这个不行了
用这个 即可:sess = keras.backend.get_session()



结合前面的报错:
http://www.ai111.vip/thread-993-1-1.html


总体解决方案:
import tensorflow as tf
import keras


global graph, sess


graph = tf.get_default_graph()
sess = keras.backend.get_session()


预测处:
    with sess.as_default():
        with graph.as_default():

              y_pred = 你的model.predict(X)




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

到此为止,问题全部解决,如果你还遇到问题,请联系我的微信:dfy_88888






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

使用道具 举报

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14435
QQ
沙发
 楼主| 发表于 2020-3-13 14:03:12 | 只看该作者
tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 21:10 , Processed in 0.172458 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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