2

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?

3
  • Please post a sample of your X and y data. Commented Nov 3, 2019 at 18:47
  • 1
    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. Commented Nov 4, 2019 at 14:29
  • Good job; so, now please either post it as an answer to your own question so it may be useful for others in the future, or delete the question altogether Commented Nov 4, 2019 at 14:30

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Good job. When the mandatory 2-day period passes, you should accept your own answer (nothing wrong with that: stackoverflow.com/help/self-answer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.