title: Calculating Multi-class Dice coefficient when predicating value are not integer
body: <p>I'm trying to calculating Multi-class Dice coefficient similar like this:
  <a href="https://stackoverflow.com/questions/61488732/how-calculate-the-dice-coefficient-for-multi-class-segmentation-task-using-pytho">How calculate the dice coefficient for multi-class segmentation task using Python?</a></p>
  <p>However, this will require that the classes be integer. For me, as shown below, in the predication, the result I got, some of classes are double. Did I make a mistake or I could simply round them to the nearest integer class:</p>
  <p><a href="https://i.stack.imgur.com/E1MbS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E1MbS.png" alt="enter image description here" /></a></p>
  <p>My code is below:</p>
  <pre><code>def down_block(x, filters, kernel_size=(3, 3), padding=&quot;same&quot;, strides=1):
      c = keras.layers.Conv2D(filters, kernel_size, padding=padding, strides=strides, activation=&quot;relu&quot;)(x)
      c = keras.layers.Conv2D(filters, kernel_size, padding=padding, strides=strides, activation=&quot;relu&quot;)(c)
      p = keras.layers.MaxPool2D((2, 2), (2, 2))(c)
      return c, p
  
  def up_block(x, skip, filters, kernel_size=(3, 3), padding=&quot;same&quot;, strides=1):
      us = keras.layers.UpSampling2D((2, 2))(x)
      concat = keras.layers.Concatenate()([us, skip])
      c = keras.layers.Conv2D(filters, kernel_size, padding=padding, strides=strides, activation=&quot;relu&quot;)(concat)
      c = keras.layers.Conv2D(filters, kernel_size, padding=padding, strides=strides, activation=&quot;relu&quot;)(c)
      return c
  
  def bottleneck(x, filters, kernel_size=(3, 3), padding=&quot;same&quot;, strides=1):
      c = keras.layers.Conv2D(filters, kernel_size, padding=padding, strides=strides, activation=&quot;relu&quot;)(x)
      c = keras.layers.Conv2D(filters, kernel_size, padding=padding, strides=strides, activation=&quot;relu&quot;)(c)
      return c 
  
  
  def UNet():
      f = [16, 32, 64, 128, 256]
      #inputs = keras.layers.Input((image_size, image_size, 3))
      inputs = keras.layers.Input((image_size, image_size, 1))
      
      p0 = inputs
      c1, p1 = down_block(p0, f[0]) #128 -&gt; 64
      c2, p2 = down_block(p1, f[1]) #64 -&gt; 32
      c3, p3 = down_block(p2, f[2]) #32 -&gt; 16
      c4, p4 = down_block(p3, f[3]) #16-&gt;8
      
      bn = bottleneck(p4, f[4])
      
      u1 = up_block(bn, c4, f[3]) #8 -&gt; 16
      u2 = up_block(u1, c3, f[2]) #16 -&gt; 32
      u3 = up_block(u2, c2, f[1]) #32 -&gt; 64
      u4 = up_block(u3, c1, f[0]) #64 -&gt; 128
      
      #outputs = keras.layers.Conv2D(1, (1, 1), padding=&quot;same&quot;, activation=&quot;sigmoid&quot;)(u4)
      outputs = keras.layers.Conv2D(4, (1, 1), padding=&quot;same&quot;, activation=&quot;softmax&quot;)(u4)
      #outputs = keras.layers.Conv2D(1, (1, 1), padding=&quot;same&quot;, activation=&quot;softmax&quot;)(u4)
      
      model = keras.models.Model(inputs, outputs)
      return model
  
  
  model.compile(optimizer=&quot;adam&quot;,  loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=[&quot;acc&quot;] )#,run_eagerly=True)
  model.summary()
  </code></pre>