该模型在 TensorFlow 1.15(最新版本)上运行良好,但在尝试调用 predict 时不适用于 Tensorflow 2.0。该模型是 Keras 模型。
model.predict(self.A.todense())
提取的错误信息:
/tensorflow-2.0.0/python3.6/tensorflow_core/python/framework/type_spec.py in type_spec_from_value(value)
490 491 raise TypeError("Could not build a TypeSpec for %r with type %s" %
--> 492 (value, type(value).name))
493 494
TypeError: Could not build a TypeSpec for matrix([[0, 1, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]], dtype=int64) with type matrix
最佳答案
当我使用 Pandas 对象时,我遇到了同样的错误,要么是 DataFrames
或 Series
, 作为输入和目标数据。您输入的类型似乎是 matrix
,在这种情况下,这也可能是您的问题;一个简单的解决方法是任何类型转换,np.array(self.A.todense())
可能会成功。
关于python - 模型预测时无法为矩阵构建 TypeSpec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58553695/