Search code examples
python-3.xtensorflowkerasdeep-learningobject-detection

FailedPreconditionError: Resource localhost/_AnonymousVar404/N10tensorflow3VarE does not exist


I'm a beginner in deep learning and python, I tried to run keras R-FCN I google colab and i got an error like this

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]

I think function crop_to_bounding_box has a something that uninitialized and this is the code that called 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)

I'm using tensorflow-GPU v2.1.0 and Keras 2.3.1

UPDATED: probably because I add K.variable inside loop, if I tried comment K.variable the code work perfectly, but I need to change K.variable based on channel_step.

how to update K.variable so i can defined K.variable outside loop, and update value inside the loop based on channel_step ?


Solution

  • I found the solution for this problem, I just need to downgrade Keras and TensorFlow version. Now I'm using tensorflow-GPU 1.15.0 and Keras 2.2.4. Apparently, this code does not support TensorFlow 2 and later.