重写代码,解决tensorflow2.x中的ValueError: Tried to convert ‘shape‘ to a tensor and failed. Error: None value

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
  • 7
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值