【问题标题】:Failed to find data adapter that can handle input: <class 'numpy.ndarray'>, (<class 'list'> containing values of types {"<class 'int'>"})找不到可以处理输入的数据适配器:<class 'numpy.ndarray'>,(<class 'list'> 包含类型 {"<class 'int'>"} 的值)
【发布时间】:2020-02-29 02:19:00
【问题描述】:
history = model.fit(X, y, batch_size=32, epochs=40, validation_split=0.1)

线路问题是这样的

显示错误:

ValueError: Failed to find data adapter that can handle input: <class 'numpy.ndarray'>, (<class 'list'> containing values of types {"<class 'int'>"})

【问题讨论】:

  • edit 您的问题并添加更多代码和上下文,以及完整的错误回溯。阅读how to ask
  • 什么是model?它不是任何标记包的一部分。显示完整的回溯。

标签: python list numpy pycharm


【解决方案1】:

我遇到了同样的问题。原来它是以列表的形式出现的。我必须将字段转换为 numpy 数组,例如:

training_padded = np.array(training_padded)
training_labels = np.array(training_labels)
testing_padded = np.array(testing_padded)
testing_labels = np.array(testing_labels)

就是这样!

【讨论】:

    【解决方案2】:

    ValueError in TensorFlow

    https://pythonprogramming.net/convolutional-neural-network-deep-learning-python-tensorflow-keras/

    我尝试了以下代码并为我工作:

    IMG_SIZE = 50
    
    X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
    
    y = np.array(y)
    
    history = model.fit(X, y, batch_size=32, epochs=40, validation_split=0.1)
    

    【讨论】:

    • 我还必须做 y = np.array(y)。
    【解决方案3】:

    所以这发生在更新版本的 tensorflow 上,我不确定从哪里开始,但我在 2.0.0 版上,同样的事情发生了

    我假设您只是将 X 数组转换为 numpy 数组 而是尝试使用 dtype 作为 np.uint8 将 'X' 和 'y' 转换为 numpy 数组

    这应该可以解决问题

    【讨论】:

    • 感谢您的帮助,它现在非常适合我的程序。它表明我要降级我的 tensorflow 并且一切似乎都正常
    【解决方案4】:

    就我而言,问题仅出在 y 中。这是一个清单。在那种情况下,我不得不改变

    y = np.array(y)

    【讨论】:

      【解决方案5】:

      VIKI 已经给出了很好的答案。我正在添加更多信息。在我添加 np.array() 包装器之前,它也曾经让我的 colab 主机崩溃。

      # Need to call np.array() around pandas dataframes.
      # This crashes the colab host from TF attempting a 32GB memory alloc when np.array() wrappers are not used around pandas dataframes.
      # Wrapping also cures warning about "Failed to find data adapter that can handle input"
      history = model.fit(x=np.array(tr_X), y=np.array(tr_Y), epochs=3, validation_data=(np.array(va_X), np.array(va_Y)), batch_size=batch_size, steps_per_epoch=spe, validation_freq=5)
      

      由于内存不足问题导致主机崩溃与此有关:

      Tensorflow dense gradient explanation?

      【讨论】:

        【解决方案6】:

        Mahmud 的回答修复了第 [30] 节中的 TensorFlow 教程“基本回归:预测燃油效率”错误。这些是 2 行:

        改变这个:

        example_batch = normed_train_data[:10]
        example_result = model.predict(example_batch)
        

        对此:

        example_batch = np.array(normed_train_data[0:10]) 
        example_result = model.predict(example_batch)
        

        感谢马哈茂德

        【讨论】:

          【解决方案7】:

          对于遇到此问题的人:

          在将数据放入模型之前检查类型。 例如,应该是

          print(type(X)) 
          # numpy.ndarray
          

          代替

          print(type(X))
          # list
          

          只需将 X 变换为

          import numpy as np
          X = np.array(X)
          

          【讨论】:

            【解决方案8】:

            只需键入转换数组。

            例如:

            import numpy as np
            features = np.array(features,dtype='float64')
            labels = np.array(labels, dtype ='float64')
            

            【讨论】:

              【解决方案9】:

              你需要像这样转换 X 和 y:

              X = np.array(X).reshape(-1, 50, 50, 1)
              

              对于你

              y=np.array(y)
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2020-10-14
                • 2023-03-30
                • 1970-01-01
                • 2021-10-29
                • 1970-01-01
                • 2022-06-22
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多