[英]Tensorflow | ValueError: Failed to find data adapter that can handle input: <class 'numpy.ndarray'>
I'm doing some code with Tensorflow and I'm facing this issue, as input I have two lists per sample and as output I have an encoded list of classes.我正在用 Tensorflow 做一些代码,我正面临这个问题,作为输入,我每个样本有两个列表,作为 output,我有一个编码的类列表。
For example:例如:
(raw) Values[0]: [[11.42, 10.09, 6.7], [7.52, 6.18, 2.11]]
(encoded) Targets[0]: [2, 3, 4, 8, 1, 5, 16, 6, 1, 7]
As in the example:就像在此样品中:
input_shape = 6000 samples x 2 lists/sample x 3 items/list
output_shape = 6000 samples x 10 items/sample
This is my first time dealing with multiple lists as input, and the problem here is that both lists contain important information for the model and that I can't just merge them, because they represent different states of the input data.这是我第一次处理多个列表作为输入,这里的问题是两个列表都包含 model 的重要信息,我不能只是合并它们,因为它们代表输入数据的不同状态。
What would you do in this case?在这种情况下你会怎么做? Maybe there is a way of merging the lists while keeping the information that both
lists
were initialy two different lists.也许有一种方法可以合并列表,同时保留两个
lists
最初是两个不同列表的信息。
Here is the full traceback:这是完整的回溯:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-79-d859259762d2> in <module>
----> 1 model.fit(x=values, y=target_tokenized)
~/.local/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
106 def _method_wrapper(self, *args, **kwargs):
107 if not self._in_multi_worker_mode(): # pylint: disable=protected-access
--> 108 return method(self, *args, **kwargs)
109
110 # Running inside `run_distribute_coordinator` already.
~/.local/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
1061 use_multiprocessing=use_multiprocessing,
1062 model=self,
-> 1063 steps_per_execution=self._steps_per_execution)
1064
1065 # Container that configures and calls `tf.keras.Callback`s.
~/.local/lib/python3.7/site-packages/tensorflow/python/keras/engine/data_adapter.py in __init__(self, x, y, sample_weight, batch_size, steps_per_epoch, initial_epoch, epochs, shuffle, class_weight, max_queue_size, workers, use_multiprocessing, model, steps_per_execution)
1102 self._steps_per_execution_value = steps_per_execution.numpy().item()
1103
-> 1104 adapter_cls = select_data_adapter(x, y)
1105 self._adapter = adapter_cls(
1106 x,
~/.local/lib/python3.7/site-packages/tensorflow/python/keras/engine/data_adapter.py in select_data_adapter(x, y)
969 "Failed to find data adapter that can handle "
970 "input: {}, {}".format(
--> 971 _type_name(x), _type_name(y)))
972 elif len(adapter_cls) > 1:
973 raise RuntimeError(
ValueError: Failed to find data adapter that can handle input: <class 'numpy.ndarray'>, (<class 'list'> containing values of types {'(<class \'list\'> containing values of types {"<class \'int\'>"})'})
You need to convert the list to numpy arrays您需要将列表转换为 numpy arrays
import numpy as np
lists = np.asarray(reg_lists)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.