簡體   English   中英

Tensorflow 一個熱編碼 - 找不到節點的有效設備

[英]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 ,這在使用 list 時tf.one_hot不兼容。 在單熱編碼之前,您需要將目標轉換為 integer 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)>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM