tensorflow1.x和2.x之间差别很大,本人在用rensorflow2.1.0-GPU 运行RCNN-Masked时候出现ValueError: Tried to convert ‘shape’ to a tensor and failed. Error: None values not supported.这个错误。 通过在tensorflow base_layer.py 中修改部分源码或许能帮助解决这个问题。
from tensorflow.python.keras.utils.generic_utils import to_snake_case # pylint: disable=unused-import
from tensorflow.python.keras.utils.tf_utils import is_tensor_or_tensor_list # pylint: disable=unused-import
from tensorflow.python.module import module
######################################################## 在这个位置修改
from tensorflow.python.ops import control_flow_ops #添加这个库
########################################################
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import resource_variable_ops
if not hasattr(self.build, '_is_default'):
# Any setup work performed only once should happen in an `init_scope`
# to avoid creating symbolic Tensors that will later pollute any eager
# operations.
with tf_utils.maybe_init_scope(self):
##################################################在这个位置修改,下面的代码二选一即可
#删除原来位置的代码,将原来的代码修改为下面的其中之一
self.build(tuple(input_list)) #将该处的代码修改
self.build(control_flow_ops.tuple(tuple(input_list))) #或者将该处的代码修改
####################################################################################
# We must set self.built since user defined build functions are not
# constrained to set self.built.
self.built = True
# Optionally load weight values specified at layer instantiation.
if getattr(self, '_initial_weights', None) is not None:
self.set_weights(self._initial_weights)
self._initial_weights = None