TransWikia.com

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

Data Science Asked by Danny Cupper on November 24, 2020

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(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2, 2)))

model.add(Conv2D(64, (3, 3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2, 2)))

model.add(Flatten())
model.add(Dense(64))

model.add(Dense(1))
model.add(Activation("sigmoid"))

model.compile(loss = 'binary_crossentropy',
             optimizer = 'adam',
             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)

~Miniconda3envstensorflowlibsite-packagestensorflow_corepythonkerasenginetraining.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,

~Miniconda3envstensorflowlibsite-packagestensorflow_corepythonkerasenginetraining_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)

~Miniconda3envstensorflowlibsite-packagestensorflow_corepythonkerasenginetraining_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

~Miniconda3envstensorflowlibsite-packagestensorflow_corepythonkerasenginedata_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.

One Answer

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

Answered by Brian Spiering on November 24, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP