I would also like to know more information regarding this question. It seems to have no answer.
I will like to know if there is a way to add loss constraint based blob/shape characteristics while respecting the loss diffentiability. Here are some example of desired constraint :

penalize if number of blobs exceeds
penalize so that a specific class segmentation is included into another one. I thought maybe by multiplication with the threholded segmentation map it will force inclusion not really a loss constraint however.
penalize if the blob is not convex.

Is there has been any progress on that question?