0

When executing the following tensorflow 2.8 method (after fitting model):

model.predict(X_test)

I get the following message:

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

None of suggestions reported in other similar questions seems to work. Here's my data:

type(X_test)
X_test.size
len(X_test)
X_test

The outputs:

numpy.ndarray
13
13
array([array([[[[1.72707179e-04],
                [3.01862194e-04],
                [1.30811683e-03],
                ...,
                [3.52285788e-05],
                [5.02625953e-05],
                [6.48639834e-05]],

                [[7.46249643e-05],
                [4.26480168e-04],
                [2.55916407e-03],
                ...,
                [6.17124970e-05],
                [5.78219624e-05],
                [8.79297804e-05]],

               [[2.28419929e-04],
               [1.81215862e-03],
               [3.15412483e-03],

                etc

Thanks.

1 Answers1

0

You are passing an input sample of object type to model.predict(), hence the error. Please try casting x_test to float32 using tf.cast() like below

x_test = tf.cast(x_test, tf.float32)

Input samples of a model.predict() could be:

  • A Numpy array (or array-like), or a list of arrays (in case the model has multiple inputs).
  • A TensorFlow tensor, or a list of tensors (in case the model has multiple inputs).
  • A tf.data dataset.
  • A generator or keras.utils.Sequence instance. A more detailed description of unpacking behavior for iterator types (Dataset, generator, Sequence) is given in the Unpacking behavior for iterator-like inputs section of Model.fit.