# Keras error “Failed to find data adapter that can handle input” while trying to train a model

I've been following a tutorial on training a model and I've stumbled across an error that I've been struggling to find a solution for.

The code for the model training is bellow:

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
import pickle

X = pickle.load(open("X.pickle", "rb"))
y = pickle.load(open("y.pickle", "rb"))

X = X / 255.0

model = Sequential()
model.add(Conv2D(64, (3, 3), input_shape = X.shape[1:]))
model.add(MaxPooling2D(pool_size = (2, 2)))

model.add(MaxPooling2D(pool_size = (2, 2)))

model.compile(loss = 'binary_crossentropy',
metrics = ['accuracy'])

model.fit(X, y, batch_size=32, validation_split=0.1)


And the result I get when I run this code is:

ValueError Traceback (most recent call last) in 28 metrics = ['accuracy']) 29 ---> 30 model.fit(X, y, batch_size=32, validation_split=0.1)

~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow_core\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_freq, max_queue_size, workers, use_multiprocessing, **kwargs) 731 max_queue_size=max_queue_size, 732 workers=workers, --> 733 use_multiprocessing=use_multiprocessing) 734 735 def evaluate(self,

~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, **kwargs) 215 validation_data=validation_data, 216 validation_steps=validation_steps, --> 217 distribution_strategy=strategy) 218 219 total_samples = _get_total_number_of_samples(training_data_adapter)

~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in _process_training_inputs(model, x, y, batch_size, sample_weights, class_weights, steps_per_epoch, validation_split, validation_data, validation_steps, shuffle, distribution_strategy) 468 'at same time.') 469 --> 470 adapter_cls = data_adapter.select_data_adapter(x, y) 471 472 # Handle validation_split, we want to split the data and get the training

~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\data_adapter.py in select_data_adapter(x, y) 446 "Failed to find data adapter that can handle " 447 "input: {}, {}".format( --> 448 _type_name(x), _type_name(y))) 449 elif len(adapter_cls) > 1: 450 raise RuntimeError(

ValueError: Failed to find data adapter that can handle input: , ( containing values of types {""})

Thank you in advance if you can help me figure out where the problem is.

• Did you fix it? I too have run into the same error and am kind of struck. Please let me know if you have found a solution. – tv bharath Oct 8 '19 at 11:19
• Yes, basically you need to convert X and y as arrays before you load from pickle. All you have to do is at the top import numpy as np and then just change where you define X and y to: X = np.asarray(pickle.load(open("X.pickle", "rb"))) and then: y = np.asarray(pickle.load(open("y.pickle", "rb"))) @tvbharath – Danny Cupper Oct 8 '19 at 22:07

There is something wrong with your data. {""} means you have a Python dict that only contains an empty string.