Tensorflow cond的行为与sou不同

2021-10-17 18:47:53 发布

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

我从源头上建立了tensorflow。我正在使用tf.条件在加载数据时选择要加载的图像。看起来是这样的:

reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
    serialized_example,
    features={
        'label': tf.FixedLenFeature([], tf.float32),
        'right': tf.VarLenFeature(tf.string),
        'center': tf.VarLenFeature(tf.string),
        'left': tf.VarLenFeature(tf.string)
    })
label = features['label']
image, label = tf.cond(rand < -0.7, lambda: (features['right'],label + 0.08), lambda: (features['center'], label))
image, label = tf.cond(rand > 0.7, lambda: (features['left'], label - 0.08), lambda: (image,label))

对于从源代码构建的版本(大约0.11rc1),这可以很好地工作,但是在其他安装了0.11rc2(和rc1)和pip的机器上,我会遇到以下错误:

File "./example_reader.py", line 29, in read_and_decode_single_example
    image, label = tf.cond(rand < -0.7, lambda: (features['right'],label + 0.08), lambda: (features['center'], label))
  File "./local/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1710, in cond
    orig_res, res_t = context_t.BuildCondBranch(fn1)
  File "./local/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1626, in BuildCondBranch
    elif v.name not in self._values:
AttributeError: 'SparseTensor' object has no attribute 'name'

我不知道这里有什么问题。。。希望你能帮助我。你知道吗