- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在偏差 + 权重上实现 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/
我正在尝试创建一个从 std::map 或 std::unordered_map 获取键的函数。我可以使用简单的重载,但首先我想知道这段代码有什么问题。 template class TContain
我正在尝试在偏差 + 权重上实现 L1 范数。为此,我尝试将它们连接在一起并取平均值。 也就是说,我有一个偏差 b1(形状:[1,1])和权重 W1(形状:[ 1, xlen]).所以我天真地尝试沿着
我目前正在单声道 (Mac OSX) 中运行一个程序,该程序读取一个非常大的数据文件并在聚合后创建摘要统计信息。 奇怪的是,我在程序的某个时刻收到以下错误消息: 垃圾收集器无法为主要堆部分分配 163
我正在尝试使用 fopen() 将一个长字符串(>700.000 个字符)保存到服务器上的一个文件中。 $file = fopen($filename, 'w+'); fwrite($file, $c
我想在 MacOS X 服务器上启动 Tomcat,所以我编写了以下 plist 并将其放入 /Library/LaunchDaemons: Disabled
所以我正在阅读这本很棒的书,“暴力 Python”。在第 2 章中有一个 Python 脚本,它使用私钥对 Debian 机器或任何运行 SSH 服务器的机器进行身份验证,该服务器上有用户但没有强私钥
我有一个脚本可以检测我网站上的 Javascript 错误并将它们发送到我的后端进行报告。它报告遇到的第一个错误、假定的行号和时间。 编辑以包含文档类型: ... // -1){
我最近将我的 lambda Node.js 运行时从 8.x 更新到了 12.x。我升级了许多依赖项并优化了与 webpack 的捆绑和部署过程。 但是,我开始注意到 Cloudwatch 中的零星错
在 windows server 2016 上,安装了 docker,并尝试使用 nodejs 运行 docker 镜像。 docker 运行 stefanscherer/node-windows "
我正在尝试使用 maven-jaxb2-plugin 编译位于 http://www.aptatcip.com/APTA-TCIP-S-01%204.0_files/Schema%20Set.zip
我是一名优秀的程序员,十分优秀!