Failed to convert a array to a Tensor

(遇到此error,看这篇就对了)

运行代码:model.fit(in_fe, labels, validation_split=0.25, epochs=10, batch_size=64)

报错:ValueError: Failed to convert a array to a Tensor (Unsupported object type

这里也是经过查找解决方法,有一种解决方法是说卸载numpy,换一个版本,这种方式不如直接用下面的转换数据格式的方式直接。

原因: fit()之前没有把训练样本和测试样本转化成Keras可接受的数据类型。

解决: fit() 之前先转换数据类型:

in_fe = in_fe.astype(‘float64’)

labels = labels.astype(‘float64’)

注:tensorflow的keras模块训练的时候,输入输出数据有自己的数据格式,numpy与Tensor的数据转换时有特定的要求。

继续:

运行程序的时候又遇到这个问题,不得已还是得换一个numpy版本:

原因在于tensorflow2.0的版本与numpy的版本的适配性不好。

解决方法:

  1. 卸载numpy: pip uninstall numpy
  2. 重新安装numpy的1.16.4版本:pip install numpy==1.16.4
  3. 但是我安装后出error了:(如果你没出error,就忽略这步)

Failed to convert a array to a Tensor

这个error就是有部分包不适配,我是这样解决的:

pip install mkl-random

pip uninstall gast

pip install gast==0.2.2,

实际上,它是重新安装依赖包。

[En]

In fact, it is to reinstall the dependent package.

Original: https://blog.csdn.net/civiljiao/article/details/123307160
Author: civiljiao
Title: Failed to convert a array to a Tensor

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/509101/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球