首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >FailedPreconditionError:资源本地主机/_匿名变量404/N10tensorflow3VarE不存在

FailedPreconditionError:资源本地主机/_匿名变量404/N10tensorflow3VarE不存在
EN

Stack Overflow用户
提问于 2020-04-16 20:51:49
回答 2查看 2K关注 0票数 2

我是深度学习和python的初学者,我试着运行keras R-FCN我google colab,我得到了一个像这样的错误

代码语言:javascript
运行
复制
tensorflow.python.framework.errors_impl.FailedPreconditionError: 2 root error(s) found.
  (0) Failed precondition:  Error while reading resource variable _AnonymousVar404 from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/_AnonymousVar404/N10tensorflow3VarE does not exist.
     [[node regr_vote/crop_to_bounding_box_7/stack/ReadVariableOp_1 (defined at usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3009) ]]
  (1) Cancelled:  Function was cancelled before it was started
0 successful operations.
0 derived errors ignored. [Op:__inference_keras_scratch_graph_16906]

我认为crop_to_bounding_box函数有一个未初始化的东西,这是名为crop_to_bounding_box的代码

代码语言:javascript
运行
复制
# position-sensitive ROI pooling + classify
        score_map_bins = []
        for channel_step in range(self.k*self.k):
            bin_x = K.variable(int(channel_step % self.k) *
                               self.pool_shape, dtype='int32')
            print(bin_x)
            bin_y = K.variable(int(channel_step / self.k) *
                               self.pool_shape, dtype='int32')
            channel_indices = K.variable(list(range(
                channel_step*self.channel_num, (channel_step+1)*self.channel_num)), dtype='int32')
            croped = tf.image.crop_to_bounding_box(
                tf.gather(pooled, indices=channel_indices, axis=-1), bin_y, bin_x, self.pool_shape, self.pool_shape)
            # [pool_shape, pool_shape, channel_num] ==> [1,1,channel_num] ==> [1, channel_num]
            croped_mean = K.pool2d(croped, (self.pool_shape, self.pool_shape), strides=(
                1, 1), padding='valid', data_format="channels_last", pool_mode='avg')
            # [batch * num_rois, 1,1,channel_num] ==> [batch * num_rois, 1, channel_num]
            croped_mean = K.squeeze(croped_mean, axis=1)
            score_map_bins.append(croped_mean)

我使用的是tensorflow-GPU v2.1.0和Keras 2.3.1

更新:可能是因为我在循环中添加了K.variable,如果我尝试注释K.variable,代码可以很好地工作,但我需要根据channel_step更改K.variable。

如何更新K.variable,以便在循环外定义K.variable,并基于channel_step更新循环内的值?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-26 10:31:31

我找到了这个问题的解决方案,我只需要降级Keras和TensorFlow版本。现在我使用的是tensorflow-GPU 1.15.0和Keras 2.2.4。显然,此代码不支持TensorFlow 2及更高版本。

票数 0
EN

Stack Overflow用户

发布于 2021-04-13 05:05:03

我已经通过更改load函数修复了这个问题。如果要从.h5.pb加载模型

将其更改为:

代码语言:javascript
运行
复制
model = tf.saved_model.load(self.filename, [tf.saved_model.SERVING])

要这样做:

代码语言:javascript
运行
复制
from tensorflow.python.keras.models import load_model
model = load_model(self.filename)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61250699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档