0 votes
1 view
in AI and Deep Learning by (16.4k 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 (36.8k 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.

...