模型预测时无法为矩阵构建 TypeSpec

T D*_*yen 5 python neural-network keras tensorflow2.0

该模型在 TensorFlow 1.15(最新版本)上运行良好,但在尝试调用 predict 时不适用于 Tensorflow 2.0。该模型是 Keras 模型。

model.predict(self.A.todense())
Run Code Online (Sandbox Code Playgroud)

提取的错误信息:

/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" %
Run Code Online (Sandbox Code Playgroud)

--> 492(值,类型(值)。名称))

493 
494
Run Code Online (Sandbox Code Playgroud)

TypeError: 无法为 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
Run Code Online (Sandbox Code Playgroud)

小智 2

当我使用 Pandas 对象( 或 )作为输入和目标数据时,出现了同样的DataFrames错误Series。看起来您的输入类型为matrix,在这种情况下,这也可能是您的问题;一个简单的修复方法是任何类型转换,np.array(self.A.todense())都可能达到目的。