gpt4 book ai didi

tensorflow 连接错误 : a cryptic string formatting issue

转载 作者:行者123 更新时间:2023-12-05 01:36:00 24 4
gpt4 key购买 nike

我正在尝试在偏差 + 权重上实现 L1 范数。为此,我尝试将它们连接在一起并取平均值。

也就是说,我有一个偏差 b1(形状:[1,1])和权重 W1(形状:[ 1, xlen]).所以我天真地尝试沿着第一维连接:

    self.W1 = tf.Variable(tf.truncated_normal([1, self.xlen], stddev=0.1), name="weight")
self.b1 = tf.Variable(tf.constant(0.1, shape=[1, 1]), name="bias")
...
l1_penalty = tf.reduce_mean(tf.abs(tf.concat(1, (self.W1,self.b1) ) ))

但是我得到:

---> 53         l1_penalty = tf.reduce_mean(tf.abs(tf.concat(1, (self.W1,self.b1) ) ))
54
55 tot_loss = l2_loss + self.ALPHA * l1_penalty

/usr/local/lib/python3.4/dist-packages/tensorflow/python/ops/array_ops.py in concat(concat_dim, values, name)
304 # TODO(mrry): Change to return values?
305 if len(values) == 1: # Degenerate case of one tensor.
--> 306 return identity(values[0], name=name)
307 return gen_array_ops._concat(concat_dim=concat_dim,
308 values=values,

/usr/local/lib/python3.4/dist-packages/tensorflow/python/ops/gen_array_ops.py in identity(input, name)
313 A `Tensor`. Has the same type as `input`.
314 """
--> 315 return _op_def_lib.apply_op("Identity", input=input, name=name)
316
317

/usr/local/lib/python3.4/dist-packages/tensorflow/python/ops/op_def_library.py in apply_op(self, op_type_name, g, name, **keywords)
419 values = ops.convert_to_tensor(
420 values, name=input_arg.name, dtype=dtype,
--> 421 as_ref=input_arg.is_ref)
422 except ValueError:
423 # What type does convert_to_tensor think it has?

/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/ops.py in convert_to_tensor(value, dtype, name, as_ref)
522 for base_type, conversion_func in funcs_at_priority:
523 if isinstance(value, base_type):
--> 524 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
525 if not isinstance(ret, Tensor):
526 raise RuntimeError(

/usr/local/lib/python3.4/dist-packages/tensorflow/python/ops/constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref)
176 as_ref=False):
177 _ = as_ref
--> 178 return constant(v, dtype=dtype, name=name)
179
180

/usr/local/lib/python3.4/dist-packages/tensorflow/python/ops/constant_op.py in constant(value, dtype, shape, name)
159 tensor_value = attr_value_pb2.AttrValue()
160 tensor_value.tensor.CopyFrom(
--> 161 tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape))
162 dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)
163 const_tensor = g.create_op(

/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape)
382 if numpy_dtype == dtypes.string and not isinstance(values, np.ndarray):
383 proto_values = _FlattenToStrings(values)
--> 384 tensor_proto.string_val.extend([compat.as_bytes(x) for x in proto_values])
385 return tensor_proto
386

/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_util.py in <listcomp>(.0)
382 if numpy_dtype == dtypes.string and not isinstance(values, np.ndarray):
383 proto_values = _FlattenToStrings(values)
--> 384 tensor_proto.string_val.extend([compat.as_bytes(x) for x in proto_values])
385 return tensor_proto
386

/usr/local/lib/python3.4/dist-packages/tensorflow/python/util/compat.py in as_bytes(bytes_or_text)
41 return bytes_or_text
42 else:
---> 43 raise TypeError('Expected binary or unicode string, got %r' % bytes_or_text)
44
45

TypeError: not all arguments converted during string formatting

添加名称参数没有帮助。

作为替代方案,tf.reduce_sum 与我一起工作,但是 tf.concat 有什么问题?

最佳答案

这个问题似乎是由 this line of the tf.concat() implementation 上的错误引起的.目前——与大多数其他可变 TensorFlow 运算符不同——tf.concat() 仅接受张量的列表,并且不能正确处理元组。如果您将代码更改为以下内容,它应该可以工作:

 l1_penalty = tf.reduce_mean(tf.abs(tf.concat(1, [self.W1, self.b1]))) 

同时,我会修复这个bug并提交到上游,以便在下一个版本中处理。

关于 tensorflow 连接错误 : a cryptic string formatting issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34533424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com