<p>A surface dice implementation was provided <a href="https://github.com/deepmind/surface-distance" rel="nofollow noreferrer">here</a> as part of <a href="https://arxiv.org/pdf/1809.04430.pdf" rel="nofollow noreferrer">this</a> study. You can use it as an evaluation metric but not as a loss function as it contains non-differentiable ops. You will need to provide a "tolerance" distance i.e. a surface dice of 0.9 means that 90% of surfaces lie within the tolerance (which is better calculated from the data itself, such as the inter-observer variation of the task you are solving)</p>
How to compute the Surface Dice-Sørensen Coefficient in pytorch?
<p>I would like to compute the <em>Surface Dice-Sørensen Coefficient</em> from this  <a href="https://arxiv.org/pdf/1809.04430.pdf" rel="nofollow noreferrer">paper</a> (page 19)in python3/pytorch.</p>

<p>I have to point out, that I do <strong>not</strong> try to implement the simple <em>standard volumetric Dice-Sørensen Coefficient</em>! This one would look as follows in my implementation:</p>

<pre class="lang-py prettyprint-override"><code>import torch

def volumetric_DSC(M1, M2):
    M1 = M1.view(-1)
    M2 = M2.view(-1)
    dividend = 2 * (M1 * M2).sum()
    divisor = (M1 * M1).sum() + (M2 * M2).sum()
    return dividend / divisor

if __name__ == "__main__":
    m1 = torch.empty(5, 5, 5).uniform_(0, 1)
    m1 = torch.bernoulli(m1)
    m2 = torch.empty(5, 5, 5).uniform_(0, 1)
    m2 = torch.bernoulli(m2)
    loss = volumetric_DSC(m1, m2)
    print("loss = {0}".format(loss))
</code></pre>

<p>How can I extend this code to a Surface Dice-Sørensen Coefficient loss?</p>