Tensorflow:没有为标准op:extractGleese注册的形状函数。在哪里添加形状函数的代码?

2024-04-24 19:49:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用tf.image.extract_glimpse建立一个张量流图。在

不幸的是,我认为API本身有一个bug。我收到错误No shape function registered for standard op: ExtractGlimpse

实际上,/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/attentions_ops.py中有以下代码:

@ops.RegisterShape("ExtractGlimpse")
def _ExtractGlimpseShape(op):
  """Shape function for ExtractGlimpse op."""
  input_shape = op.inputs[0].get_shape().with_rank(4)
  unused_size_shape = op.inputs[1].get_shape().merge_with(
      tensor_shape.vector(2))
  offsets_shape = op.inputs[2].get_shape().merge_with(
      input_shape[:1].concatenate([2]))
  offsets_shape = offsets_shape
  size_value = tensor_util.ConstantValue(op.inputs[1])
  if size_value is not None:
    height = size_value[0]
    width = size_value[1]
  else:
    height = None
    width = None
  return [tensor_shape.TensorShape(
      [input_shape[0], height, width, input_shape[3]])]

由于某些原因,这个函数没有被正确地使用,但是从documentation调用这个函数的确切位置还不完全清楚。在

这个函数应该在哪个python文件中调用,该调用需要如何使用?在

提前谢谢


Tags: noneinputsizegetvaluewithwidthops
1条回答
网友
1楼 · 发布于 2024-04-24 19:49:50

这看起来像是TensorFlow中的一个bug:shape函数定义在正确的位置,但是attention_ops.py中的代码从未执行,因此shape函数从未注册。在

我将在上游修复它,但同时您可以通过在程序中添加以下行来修复它:

from tensorflow.python.ops import attention_ops

相关问题 更多 >