bsky
bsky

Reputation: 20222

TypeError: Value passed to parameter 'a' has DataType not in list of allowed values

I have the following code:

_X = np.arange(1, 7).reshape((2, 3))
_Y = np.arange(1, 7).reshape((3, 2))

X = tf.convert_to_tensor(_X)
Y = tf.convert_to_tensor(_Y)

# Matrix multiplication
out1 = tf.matmul(X, Y)

For it, I am getting this error:

TypeError: Value passed to parameter 'a' has DataType int64 not in list of allowed values: float16, float32, float64, int32, complex64, complex128

I am using the latest version of Tensorflow. What could be the issue?

Upvotes: 7

Views: 14766

Answers (2)

abbas abaei
abbas abaei

Reputation: 73

you can try this way:

def weighted_binary_crossentropy(y_true, y_pred):
   y_true = tensorflow.cast(y_true, tensorflow.float32)
   y_pred = tensorflow.cast(y_pred, tensorflow.float32)
   ...

Upvotes: 1

Harsha Pokkalla
Harsha Pokkalla

Reputation: 1802

Inputs to tf.matmul accepts only these dtypes :

a: Tensor of type float16, float32, float64, int32, complex64, complex128 and rank > 1.

Changing dtype of X and Y to above dtypes works.

import tensorflow as tf
import numpy as np
_X = np.arange(1, 7).reshape((2, 3))
_Y = np.arange(1, 7).reshape((3, 2))

X = tf.convert_to_tensor(_X,dtype=tf.int32)
Y = tf.convert_to_tensor(_Y,dtype=tf.int32)

# Matrix multiplication
out1 = tf.matmul(X, Y)

sess = tf.Session()
print(sess.run(out1))

Upvotes: 10

Related Questions