2

我正在使用tf.data.Dataset.map(process_fn)指令,映射函数由纯粹的 tensorflow 图函数组成,但 Autograph 似乎仍在尝试对其进行转换。我该如何预防?

如何强制 tensorflow 按原样使用我的代码(定义图形)?

def process_fn(item):
    assert 'image' in item
    # this should be executed right not every time graph is executed
    image = tf.image.convert_image_dtype(item.pop('image'), tf.float32)
    image = tf.multiply(tf.subtract(image, 0.5), 2)
    return image

出于某种原因,tensorflow 想要转换这个函数并报告一个警告它是不可能的,它将被原样使用。问题是,为什么首先尝试使用 Autograph?

W0119 14:55:15.113813 140297917577024 ag_logging.py:146] Entity 
<function geospatial_input.<locals>.process_fn at 0x7f991b5fe280> could 
not be transformed and will be executed as-is. Please report this to 
the AutoGraph team. When filing the bug, set the verbosity to 10 (on 
Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
4

1 回答 1

3

对于 v2.2(以及回到 v1.15),您可以使用tf.autograph.experimental.do_not_convert

@tf.autograph.experimental.do_not_convert
def process_fn(item):
    ...
于 2020-06-30T18:25:28.717 回答