Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AI and Deep Learning by (50.2k points)

I am trying to create my own loss function:

def custom_mse(y_true, y_pred): 

tmp = 10000000000 

a = list(itertools.permutations(y_pred)) 

for i in range(0, len(a)): 

t = K.mean(K.square(a[i] - y_true), axis=-1) 

if t < tmp : 

tmp = t 

return tmp

It should create permutations of predicted vector, and return the smallest loss.

"`Tensor` objects are not iterable when eager execution is not " 

TypeError: `Tensor` objects are not iterable when eager execution is not enabled. 

To iterate over this tensor use `tf.map_fn`.

error. I fail to find any source for this error. Why is this happening?

Thanks for the help.

1 Answer

0 votes
by (107k points)

The error is happening because y_pred is a tensor (non-iterable without eager execution), and itertools.permutations expects an iterable to create the permutations from. The part where you can compute the minimum loss would not work either, because the values of tensor 't' are unknown at graph creation time.

If you wish to learn more about TensorFlow then visit this TensorFlow Tutorial.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...