[英]Tensorflow One Hot Encoding - Could not find valid device for node
During my feature engingeering the following error occurred.在我的功能工程中,发生了以下错误。 My featurelist has 21 sublists with each 8537 values being either 0 or 1. When trying to run the One Hot Encoding via tensorflow it shows the error Could not find valid device for node
Does anyone have a quick fix for the error?我的功能列表有 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/```
You casted your target to tf.float32
, which is incompatible with tf.one_hot
when using a list .您将目标投射到tf.float32
,这在使用 list 时与tf.one_hot
不兼容。 You need to convert your target to an integer dtype before one-hot encoding.在单热编码之前,您需要将目标转换为 integer dtype。 Try:尝试:
x = tf.cast(x, tf.int32)
Or, convert your tensor to a NumPy array:或者,将您的张量转换为 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)>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.