我是深度学习和python的初学者,我试着运行keras R-FCN我google 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更新循环内的值?
发布于 2020-04-26 10:31:31
我找到了这个问题的解决方案,我只需要降级Keras和TensorFlow版本。现在我使用的是tensorflow-GPU 1.15.0和Keras 2.2.4。显然,此代码不支持TensorFlow 2及更高版本。
发布于 2021-04-13 05:05:03
我已经通过更改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)
https://stackoverflow.com/questions/61250699
复制相似问题