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

Published: May 03, 2021

Tags: Python; TensorFlow; Machine Learning;

DMCA.com Protection Status

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