XLA Compile error: Operation has no attr named '_XlaCompile'

XLA Compile error: Operation has no attr named '_XlaCompile'

我是运行下面的代码。我收到如下所述的 XLA 编译器错误。我有 Tensorflow GPU 1.8 版本,但我确实尝试使用 CPU 版本,但出现错误。但是当我将 Tensorflow (CPU) 降级到 1.3 时,我没有收到任何错误。已使用 Pip 虚拟环境安装 Tensorflow。

请有人帮我解决这个问题。

代码:

import tensorflow as tf
input_tensor = tf.placeholder(dtype=tf.float32, shape=[None, 16, 16, 3])
print(input_tensor.shape)

conv_filter = tf.get_variable('conv_filter', shape=[2, 2, 3, 6], dtype=tf.float32)
conv1 = tf.nn.conv2d(input_tensor, conv_filter, strides=[1, 2, 2, 1], padding='SAME')
print(conv1.shape)

deconv_filter = tf.get_variable('deconv_filter', shape=[2, 2, 6, 3], dtype=tf.float32)

deconv = tf.nn.conv2d_transpose(input_tensor, filter=deconv_filter,
    output_shape=tf.shape(input_tensor),
    strides=[1, 2, 2, 1],
    padding='SAME')
print(deconv.shape)

t = tf.reduce_mean(deconv)
g = tf.train.AdamOptimizer(0.01).minimize(t)

错误日志:

(?, 16, 16, 3)
(?, 8, 8, 6)
(?, 16, 16, 3)     # <<<<< This should have printed (?, ?, ?, ?)

Traceback (most recent call last):
  File "/my/path/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2327, in get_attr
    c_api.TF_OperationGetAttrValueProto(self._c_op, name, buf)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Operation 'conv2d_transpose' has no attr named '_XlaCompile'.

Traceback (most recent call last):
  File "/my/path/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 380, in _MaybeCompile
    xla_compile = op.get_attr("_XlaCompile")
  File "/my/path/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2331, in get_attr
    raise ValueError(str(e))
ValueError: Operation 'conv2d_transpose' has no attr named '_XlaCompile'.

错误出现在行 g = tf.train.AdamOptimizer(0.01).minimize(t)

问题的发生是因为过滤器的形状和与之相关的步长不匹配,以产生具有 V​​ALID 填充的所需输出形状。我应该将反卷积滤波器形状设置为 [1, 1, 3, 3] 并且步幅为 [1, 1, 1, 1]。

所需代码:

deconv_filter = tf.get_variable('deconv_filter', shape=[1, 1, 6, 3], dtype=tf.float32)

deconv = tf.nn.conv2d_transpose(input_tensor, filter=deconv_filter,
    output_shape=tf.shape(input_tensor),
    strides=[1, 1, 1, 1],
    padding='VALID')