Tensorflow Data Adapter Error: ValueError: Failed to find data adapter that can handle input

后端 未结 5 811
挽巷
挽巷 2021-01-01 10:06

While running a sentdex tutorial script of a cryptocurrency RNN, link here

YouTube Tutorial: Cryptocurrency-predicting RNN Model,

but have encountered an err

相关标签:
5条回答
  • 2021-01-01 10:13

    may be it will help someone. First check your data type if it is numpy array & possibly ur algo required a DF.

    print(X.shape, X.dtype)
    print(y.shape, y.dtype)
    

    convert your numpy array into Pandas DF

    train_x = pd.DataFrame(train_x)
    train_y = pd.DataFrame(train_y)
    
    0 讨论(0)
  • 2021-01-01 10:14

    If you encounter this problem while dealing with a custom generator inheriting from the keras.utils.Sequence class, you might have to make sure that you do not mix a Keras or a tensorflow - Keras-import.
    This might especially happen when you have to switch to a previous tensorflow version for compatibility (like with cuDNN).

    If you for example use this with a tensorflow-version > 2...

    from keras.utils import Sequence
    
    class generatorClass(Sequence):
    
        def __init__(self, x_set, y_set, batch_size):
            ...
    
        def __len__(self):
            ...
    
        def __getitem__(self, idx):
            return ...
    

    ... but you actually try to fit this generator in a tensorflow-version < 2, you have to make sure to import the Sequence-class from this version like:

    keras = tf.compat.v1.keras
    Sequence = keras.utils.Sequence
    
    class generatorClass(Sequence):
    
        ...
    
    
    0 讨论(0)
  • 2021-01-01 10:26

    Have you checked whether your training/testing data and training/testing labels are all numpy arrays? It might be that you're mixing numpy arrays with lists.

    0 讨论(0)
  • 2021-01-01 10:28

    You can avoid this error by converting your labels to arrays before calling model.fit():

    train_x = np.asarray(train_x)
    train_y = np.asarray(train_y)
    validation_x = np.asarray(validation_x)
    validation_y = np.asarray(validation_y)
    
    0 讨论(0)
  • 2021-01-01 10:28

    I had a similar problem. In my case it was a problem that I was using a tf.keras.Sequential model but a keras generator.

    Wrong:

    from keras.preprocessing.sequence import TimeseriesGenerator
    gen = TimeseriesGenerator(...)
    

    Correct:

    gen = tf.keras.preprocessing.sequence.TimeseriesGenerator(...)
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题