Tensorflow:没有为标准操作注册形状函数:ExtractGlimpse。我在哪里添加形状函数的代码?

时间:2015-12-18 14:03:55

标签: python tensorflow

我正在尝试使用tf.image.extract_glimpse构建张量流图。

不幸的是,我认为API本身存在一个错误。我收到错误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文件中应该调用此函数,以及如何使用该调用?

提前致谢

1 个答案:

答案 0 :(得分:4)

这看起来像是TensorFlow中的一个错误:形状函数在正确的位置定义,但attention_ops.py中的代码永远不会被执行,因此形状函数永远不会被注册。

我会在上游修复它,但在此期间你可以通过在你的程序中添加以下行来修复它:

from tensorflow.python.ops import attention_ops