python-3.x - TypeError:传递给“Pack”操作的“值”的列表中的张量具有不完全匹配的类型 [string, float32]。CSV 教程中的错误
问题描述
我在 TensorFlow 中获得了用于训练等的自己的数据。我从 Colab 上的 TensorFlow 获得了加载 CSV 数据教程,并更改了一些变量的配置以匹配我的数据。当我运行程序时,我得到了这个错误:
/tensorflow-2.0.0/python3.6/tensorflow_core/python/autograph/impl/api.py in wrapper(*args, **kwargs)
235 except Exception as e: # pylint:disable=broad-except
236 if hasattr(e, 'ag_error_metadata'):
--> 237 raise e.ag_error_metadata.to_exception(e)
238 else:
239 raise
TypeError: in converted code:
<ipython-input-15-ed03747f8311>:2 pack *
return tf.stack(list(features.values()), axis=-1), label
/tensorflow-2.0.0/python3.6/tensorflow_core/python/util/dispatch.py:180 wrapper
return target(*args, **kwargs)
/tensorflow-2.0.0/python3.6/tensorflow_core/python/ops/array_ops.py:1165 stack
return gen_array_ops.pack(values, axis=axis, name=name)
/tensorflow-2.0.0/python3.6/tensorflow_core/python/ops/gen_array_ops.py:6304 pack
"Pack", values=values, axis=axis, name=name)
/tensorflow-2.0.0/python3.6/tensorflow_core/python/framework/op_def_library.py:499 _apply_op_helper
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'Pack' Op have types [string, float32] that don't all match.
块的整个输出可在 Pastebin 上找到。
本教程中运行的块是:
packed_dataset = temp_dataset.map(pack)
for features, labels in packed_dataset.take(1):
print(features.numpy())
print()
print(labels.numpy())
解决方案
我解决了我的问题。
我不小心忘记了我的第一列不是数字,所以我把它从列表中删除了。
# Before Stuff
After Stuff
# SELECT_COLUMNS = ['sid', 'dist', 'microtime']
SELECT_COLUMNS = ['dist', 'microtime']
# DEFAULTS = ['a_r_d_b_id', 0.0, 0.0]
DEFAULTS = [0.0, 0.0]
temp_dataset = get_dataset(train_file_path,
select_columns=SELECT_COLUMNS,
column_defaults = DEFAULTS)
show_batch(temp_dataset)
example_batch, labels_batch = next(iter(temp_dataset))
def pack(features, label):
return tf.stack(list(features.values()), axis=-1), label
packed_dataset = temp_dataset.map(pack)
for features, labels in packed_dataset.take(1):
print(features.numpy())
print()
print(labels.numpy())
推荐阅读
- sql - 从表 oracle 中删除重复记录
- momentjs - 时刻 startOf 一天轮到第二天
- python - 无法在屏幕上运行 .py 脚本
- python-3.x - 当我尝试获取方法时,为什么我得到''staticmethod' object is not callable'?
- java - 如何解决 Files.createDirectories 的 NoSuchFileException
- python - 在 Python 中调用 Fortran 子例程返回“NoneType”
- javascript - Ajax用响应替换html,但在加载css,js后加载内容
- runtime-error - 生成构建时出现错误,“在'@angular/forms'中找不到“导出'ɵba'(导入为'i10')
- xml - 用 Go 解析 XML 文件有一个奇怪的行为
- reactjs - Graphql 轮询 - 如何使用先前请求的结果?