Skip to content

Commit

Permalink
test loss function
Browse files Browse the repository at this point in the history
  • Loading branch information
Arno1235 committed Mar 22, 2023
1 parent dd253c1 commit 1c6f325
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions unet_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,22 @@ def get_loss(self, logits, labels):

### TEST ###

pred_prob = tf.nn.softmax(flat_logits, axis=-1)
pred = tf.one_hot(tf.argmax(pred_prob, -1), self.n_class)

flat_pred = tf.reshape(pred, [-1, self.n_class])

# dice
eps = 1e-5
intersection = tf.reduce_sum(flat_pred * flat_labels, axis=0)
sum_ = eps + tf.reduce_sum(flat_pred + flat_labels, axis=0)
dice = 2 * intersection / sum_

loss = 0
for d in dice:
loss += d
loss /= len(dice)
loss = 1-loss
# pred_prob = tf.nn.softmax(flat_logits, axis=-1)
# pred = tf.one_hot(tf.argmax(pred_prob, -1), self.n_class)

# flat_pred = tf.reshape(pred, [-1, self.n_class])

# # dice
# eps = 1e-5
# intersection = tf.reduce_sum(flat_pred * flat_labels, axis=0)
# sum_ = eps + tf.reduce_sum(flat_pred + flat_labels, axis=0)
# dice = 2 * intersection / sum_

# loss = 0
# for d in dice:
# loss += d
# loss /= len(dice)
# loss = 1-loss
# loss *= 1_000_000

# print(f'TEST loss: {loss}, dice: {dice}')
Expand Down

0 comments on commit 1c6f325

Please sign in to comment.