How to fix ValueError: Failed to convert a NumPy array to a Tensor ( TensorFlow / Keras ) ?

Active May 03, 2021    /    Viewed 4717    /    Comments 0    /    Edit


Example of how to fix ValueError: Failed to convert a NumPy array to a Tensor:

Check input and target data type

While trying to fit a model (see Model training APIs):

model.fit(train_x, train_y, epochs=600, batch_size=400, verbose=0, callbacks=[tfdocs.modeling.EpochDots()])

if you get the error message:

ValueError: Failed to convert a NumPy array to a Tensor

try:

train_x = np.asarray(train_x).astype(np.float32)

train_y = np.asarray(train_y).astype(np.float32)

It is the most common errors.

References


Card image cap
profile-image
Daidalos

Hi, I am Ben.

I have developed this web site from scratch with Django to share with everyone my notes. If you have any ideas or suggestions to improve the site, let me know ! (you can contact me using the form in the welcome page). Thanks!



Did you find this content useful ?, If so, please consider donating a tip to the author(s). MoonBooks.org is visited by millions of people each year and it will help us to maintain our servers and create new contents.

Amount