TensorFlow中的ValueError [英] ValueError in TensorFlow
本文介绍了TensorFlow中的ValueError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,在运行以下代码行时,我遇到了TensorFlow的一些问题:
So I ran into some problems with TensorFlow when running this line of code:
history = model.fit(X, y, batch_size=32, epochs=40, validation_split=0.1)
回溯如下:
Traceback (most recent call last):
File "cnnmodel.py", line 71, in <module>
history = model.fit(X, y, batch_size=32, epochs=40, validation_split=0.1)
File "C:\Users\couch\PyMOL\envs\test\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 728, in fit
use_multiprocessing=use_multiprocessing)
File "C:\Users\couch\PyMOL\envs\test\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 224, in fit
distribution_strategy=strategy)
File "C:\Uslow_core\python\keras\engine\training_v2.py", line 497, in _process_training_inputs
adapter_cls = data_adapter.select_data_adapter(x, y)
File "C:\Users\couch\PyMOL\envs\test\lib\site-packages\tensorflow_core\python\keras\engine\data_adapter.py", line 653, in select_data_adapter
_type_name(x), _type_name(y)))
ValueError: Failed to find data adapter that can handle input: <class 'numpy.ndarray'>, (<class 'list'> containing values of types {"<class 'int'>"})
X数据是一个像素值的小数数组,Y数据是一个标签列表.
X data is a numpy array of pixel values and Y data is a list of labels.
X和Y数据使用pickle和...重新格式化.
X and Y data were reformatted using pickle and...
import pickle
import numpy
X = pickle.load(open("X.pickle", "rb"))
y = pickle.load(open("y.pickle", "rb"))
print(X[0][0:64])
print(y[0:10])
产量:
[[[2]
[2]
[2]
...
[1]
[1]
[1]]
[[2]
[2]
[2]
...
[1]
[1]
[1]]
[[2]
[2]
[2]
...
[1]
[1]
[1]]
...
[[0]
[0]
[0]
...
[0]
[0]
[0]]
[[0]
[0]
[0]
...
[0]
[0]
[0]]
[[0]
[0]
[0]
...
[0]
[0]
[0]]]
[3, 3, 0, 0, 3, 4, 3, 1, 4, 4]
关于如何解决此问题的任何想法?
Any ideas on how to fix the problem?
推荐答案
我解决了它.原来输入的数据需要是相同的类型.腌制之前,我只是将y数据通过:y = numpy.array(y)
.现在可以使用了,我正在训练我的第一个模型.
I resolved it. Turns out the input data needs to be the same type. Before pickling, I simply passed the y data through: y = numpy.array(y)
. It now works and I am training my first model.
这篇关于TensorFlow中的ValueError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文