T D Nguyen
T D Nguyen

Reputation: 7613

Could not build a TypeSpec for matrix when model predicts

The model works fine on TensorFlow 1.15 (newest release), but does not work on Tensorflow 2.0 when trying to call predict. The model is a Keras Model.

model.predict(self.A.todense())

Extracted error message:

/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

Upvotes: 5

Views: 3748

Answers (1)

krukah
krukah

Reputation: 41

I had the same error come up when I was using Pandas objects, either DataFrames or Series, as input and target data. It looks like your input is of type matrix, in which case this might be your problem as well; an easy fix would be any type conversion, np.array(self.A.todense()) would likely do the trick.

Upvotes: 2

Related Questions