Skip to content
Advertisement

List comprehension in keras custom loss function

I want to make my custom loss function. First, the model’s output shape is (None, 7, 3). So I want split the output to 3 lists. But I got an error as follows:

JavaScript

I think upper_b_true = [m[0] for m in y_true] is not supported. I don’t know how to address this problem.

JavaScript

I tried to execute it while partially annotating it, but I think the problem is the list compression part I mentioned.

Advertisement

Answer

You should use tf.unstack:

Unpacks the given dimension of a rank-R tensor into rank-(R-1) tensors.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement