Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 382
T D Nguyen Avatar asked Nov 06 '22 12:11

T D Nguyen


1 Answers

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.

like image 116
krukah Avatar answered Nov 14 '22 22:11

krukah