Tensorflow One 热编码 - 找不到节点的有效设备
Tensorflow One Hot Encoding - Could not find valid device for node
在我的功能工程中出现了以下错误。我的功能列表有 21 个子列表,每个 8537 个值要么是 0 要么是 1。当尝试 运行 通过 tensorflow 的 One Hot Encoding 时,它显示错误 Could not find valid device for node
有人可以快速修复该错误吗?
for feature in featurelist[1:]:
df = tensorflow.convert_to_tensor(feature, dtype=tensorflow.float32)
print(df)
df_enc = tensorflow.one_hot(df, 2, on_value=None, off_value=None, axis=None, dtype=None, name=None)
print(df_enc)
2020-05-29 15:08:41.969878: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fdefbc23d50 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-05-29 15:08:41.969919: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
tf.Tensor([0. 0. 0. ... 0. 0. 0.], shape=(8537,), dtype=float32)
Traceback (most recent call last):
File "/Users/marius/Desktop/Masterarbeit/Github/virtual7/tempCodeRunnerFile.python", line 1234, in <module>
df_enc = tensorflow.one_hot(df, 2, on_value=None, off_value=None, axis=None, dtype=None, name=None)
File "/Users/marius/.pyenv/versions/3.7.3/lib/python3.7/site-packages/tensorflow_core/python/util/dispatch.py", line 180, in wrapper
return target(*args, **kwargs)
File "/Users/marius/.pyenv/versions/3.7.3/lib/python3.7/site-packages/tensorflow_core/python/ops/array_ops.py", line 3645, in one_hot
name)
File "/Users/marius/.pyenv/versions/3.7.3/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 5549, in one_hot
_ops.raise_from_not_ok_status(e, name)
File "/Users/marius/.pyenv/versions/3.7.3/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 6606, in raise_from_not_ok_status
six.raise_from(core._status_to_exception(e.code, message), None)
File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.NotFoundError: Could not find valid device for node.
Node:{{node OneHot}}
All kernels registered for op OneHot :
device='XLA_CPU_JIT'; TI in [DT_INT32, DT_UINT8, DT_INT64]; T in [DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, ..., DT_UINT16, DT_COMPLEX128, DT_HALF, DT_UINT32, DT_UINT64]
device='XLA_CPU'; TI in [DT_INT32, DT_UINT8, DT_INT64]; T in [DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, ..., DT_UINT16, DT_COMPLEX128, DT_HALF, DT_UINT32, DT_UINT64]
device='CPU'; TI in [DT_UINT8]; T in [DT_INT64]
device='CPU'; TI in [DT_INT32]; T in [DT_INT64]
device='CPU'; TI in [DT_INT64]; T in [DT_INT64]
device='CPU'; TI in [DT_UINT8]; T in [DT_INT32]
.....
device='CPU'; TI in [DT_INT32]; T in [DT_INT32]
device='CPU'; TI in [DT_INT64]; T in [DT_INT32]
device='CPU'; TI in [DT_UINT8]; T in [DT_UINT16]
[Op:OneHot] name: one_hot/```
您将目标投射到 tf.float32
,这与 tf.one_hot
在使用列表 时不兼容。在单热编码之前,您需要将目标转换为整数 dtype。尝试:
x = tf.cast(x, tf.int32)
或者,将您的张量转换为 NumPy 数组:
tensor = np.array([0., 1., 2., 3.])
tf.one_hot(tensor, depth=4)
<tf.Tensor: shape=(4, 4), dtype=float32, numpy=
array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]], dtype=float32)>
在我的功能工程中出现了以下错误。我的功能列表有 21 个子列表,每个 8537 个值要么是 0 要么是 1。当尝试 运行 通过 tensorflow 的 One Hot Encoding 时,它显示错误 Could not find valid device for node
有人可以快速修复该错误吗?
for feature in featurelist[1:]:
df = tensorflow.convert_to_tensor(feature, dtype=tensorflow.float32)
print(df)
df_enc = tensorflow.one_hot(df, 2, on_value=None, off_value=None, axis=None, dtype=None, name=None)
print(df_enc)
2020-05-29 15:08:41.969878: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fdefbc23d50 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-05-29 15:08:41.969919: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
tf.Tensor([0. 0. 0. ... 0. 0. 0.], shape=(8537,), dtype=float32)
Traceback (most recent call last):
File "/Users/marius/Desktop/Masterarbeit/Github/virtual7/tempCodeRunnerFile.python", line 1234, in <module>
df_enc = tensorflow.one_hot(df, 2, on_value=None, off_value=None, axis=None, dtype=None, name=None)
File "/Users/marius/.pyenv/versions/3.7.3/lib/python3.7/site-packages/tensorflow_core/python/util/dispatch.py", line 180, in wrapper
return target(*args, **kwargs)
File "/Users/marius/.pyenv/versions/3.7.3/lib/python3.7/site-packages/tensorflow_core/python/ops/array_ops.py", line 3645, in one_hot
name)
File "/Users/marius/.pyenv/versions/3.7.3/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 5549, in one_hot
_ops.raise_from_not_ok_status(e, name)
File "/Users/marius/.pyenv/versions/3.7.3/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 6606, in raise_from_not_ok_status
six.raise_from(core._status_to_exception(e.code, message), None)
File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.NotFoundError: Could not find valid device for node.
Node:{{node OneHot}}
All kernels registered for op OneHot :
device='XLA_CPU_JIT'; TI in [DT_INT32, DT_UINT8, DT_INT64]; T in [DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, ..., DT_UINT16, DT_COMPLEX128, DT_HALF, DT_UINT32, DT_UINT64]
device='XLA_CPU'; TI in [DT_INT32, DT_UINT8, DT_INT64]; T in [DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, ..., DT_UINT16, DT_COMPLEX128, DT_HALF, DT_UINT32, DT_UINT64]
device='CPU'; TI in [DT_UINT8]; T in [DT_INT64]
device='CPU'; TI in [DT_INT32]; T in [DT_INT64]
device='CPU'; TI in [DT_INT64]; T in [DT_INT64]
device='CPU'; TI in [DT_UINT8]; T in [DT_INT32]
.....
device='CPU'; TI in [DT_INT32]; T in [DT_INT32]
device='CPU'; TI in [DT_INT64]; T in [DT_INT32]
device='CPU'; TI in [DT_UINT8]; T in [DT_UINT16]
[Op:OneHot] name: one_hot/```
您将目标投射到 tf.float32
,这与 tf.one_hot
在使用列表 时不兼容。在单热编码之前,您需要将目标转换为整数 dtype。尝试:
x = tf.cast(x, tf.int32)
或者,将您的张量转换为 NumPy 数组:
tensor = np.array([0., 1., 2., 3.])
tf.one_hot(tensor, depth=4)
<tf.Tensor: shape=(4, 4), dtype=float32, numpy=
array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]], dtype=float32)>