【问题标题】:FailedPreconditionError: Resource localhost/_AnonymousVar404/N10tensorflow3VarE does not existFailedPreconditionError: 资源 localhost/_AnonymousVar404/N10tensorflow3VarE 不存在
【发布时间】:2020-07-29 17:16:13
【问题描述】:

我是深度学习和 python 的初学者, 我尝试运行 keras R-FCN 我在谷歌 colab 上遇到了这样的错误

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的代码

# 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 在循环内更新值?

【问题讨论】:

    标签: python-3.x tensorflow keras deep-learning object-detection


    【解决方案1】:

    我已通过更改 load 函数解决了这个问题。如果您从 .h5.pb 加载模型

    从这里改变它:

    model = tf.saved_model.load(self.filename, [tf.saved_model.SERVING])
    

    到这里:

    from tensorflow.python.keras.models import load_model
    model = load_model(self.filename)
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2020-06-02
        • 1970-01-01
        • 2021-06-02
        • 2020-08-25
        • 2015-07-11
        • 1970-01-01
        • 1970-01-01
        • 2015-03-22
        • 2016-05-01
        相关资源
        最近更新 更多