ValueError:无法找到可以处理输入的数据适配器:<class'numpy.ndarray'>,<class'pandas.core.frame.DataFrame'>

时间:2019-12-25 10:50:17

标签: python pandas tensorflow

在我的代码中,我的模型可以很好地编译,但是当我使用pd.get_dummies(pd.Series(test_labels))获取验证图像的标签时,它给了我以下错误。

File "train_model.py", line 43, in <module>
    pd.get_dummies(pd.Series(test_labels))])
  File "C:\Users\ariji\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 728, in fit
    use_multiprocessing=use_multiprocessing)
  File "C:\Users\ariji\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 224, in fit
    distribution_strategy=strategy)
  File "C:\Users\ariji\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_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\ariji\AppData\Local\Programs\Python\Python37\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 'pandas.core.frame.DataFrame'>

似乎是什么问题?我的模型是一个简单的张量流顺序模型。

1 个答案:

答案 0 :(得分:0)

这是因为pd.get_dummies给出了pd.DataFrame。您需要将其转换为numpy.ndarray类型。

尝试

pd.get_dummeis(pd.Series(test_labels)).to_numpy()