python - Python Tensorflow tf.concat 在连接 2 个张量时引发奇怪的错误
问题描述
这是我想将 2 个张量(张量,array_tensor)连接到“new_tensor”中的代码,但是我返回了这个错误。
如果它有助于我在 Tensorflow 1.14.1-dev20190318 for gpu 上运行
tensor = None
array_tensor = None
dummy_tensor = tf.convert_to_tensor(0.0,dtype=tf.float32)
dummy_tensor_2 = tf.convert_to_tensor(0.0,dtype=tf.float32)
dataset = tf.data.Dataset.from_tensors(tensors=(dummy_tensor,dummy_tensor_2))
for row in float_validation:
print(row[0])
tensor = tf.convert_to_tensor(row[0], dtype=tf.float32)
array_tensor = tf.convert_to_tensor(row[1],dtype=tf.float32)
new_tensor = tf.concat([tensor,array_tensor],axis=2)
# dataset = dataset.concatenate(tf.data.Dataset.from_tensors(tensors=(tensor,array_tensor)))
dataset = dataset.concatenate(tf.data.Dataset.from_tensors(tensors=(new_tensor)))
File "D:\School\Last_Year\thesis_actual\thesis\thesis_prototype\test.py", line 126, in <module>
new_tensor = tf.concat([tensor,array_tensor],axis=2)
File "D:\School\Last_Year\thesis_actual\thesis\thesis_prototype\venv\lib\site-packages\tensorflow\python\util\dispatch.py", line 180, in wrapper
return target(*args, **kwargs)
File "D:\School\Last_Year\thesis_actual\thesis\thesis_prototype\venv\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1271, in concat
return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
File "D:\School\Last_Year\thesis_actual\thesis\thesis_prototype\venv\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 1378, in concat_v2
_six.raise_from(_core._status_to_exception(e.code, message), None)
File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: ConcatOp : Expected concatenating dimensions in the range [0, 0), but got 2 [Op:ConcatV2] name: concat```
解决方案
推荐阅读
- arduino - Arduino RFID (MFRC522) 问题 - 一段时间后停止读取标签
- mysql - 当我的查询在“IN”子句中有大量值时,MySQL 不使用我期望的索引
- c# - 如何避免在同一范围内多次重复输入相同的名称?
- python - 为什么pyheif在python导入时崩溃?
- python - Python svgwrite 绘图错误“不是 svg 元素中属性 'd' 的有效值
" - excel - 有没有办法可以在 Excel 列中的数字列表中获取差异?
- spring - 配置 Spring Security 以显示样式
- c - 关于C中内存分配的问题
- android - Facebook 登录:无法加载 URL 在 android studio 中使用 facebook-android-sdk 登录时,此 URL 的域不包含在应用程序的域中
- xcode - 在没有 Xcode 的 Mac 上安装 Git