couch
couch

Reputation: 71

ValueError in 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)

The Traceback is as follows:

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 data is a numpy array of pixel values and Y data is a list of labels.

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])

Yeilds:

[[[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?

Upvotes: 2

Views: 2487

Answers (1)

couch
couch

Reputation: 71

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.

Upvotes: 5

Related Questions