MCPcopy Index your code
hub / github.com/lisa-lab/DeepLearningTutorials / accuracy_metric

Function accuracy_metric

code/unet/train_unet.py:55–80  ·  view source on GitHub ↗
(y_pred, y_true, void_labels, one_hot=False)

Source from the content-addressed store, hash-verified

53
54
55def accuracy_metric(y_pred, y_true, void_labels, one_hot=False):
56
57 assert (y_pred.ndim == 2) or (y_pred.ndim == 1)
58
59 # y_pred to indices
60 if y_pred.ndim == 2:
61 y_pred = T.argmax(y_pred, axis=1)
62
63 if one_hot:
64 y_true = T.argmax(y_true, axis=1)
65
66 # Compute accuracy
67 acc = T.eq(y_pred, y_true).astype(_FLOATX)
68
69 # Create mask
70 mask = T.ones_like(y_true, dtype=_FLOATX)
71 for el in void_labels:
72 indices = T.eq(y_true, el).nonzero()
73 if any(indices):
74 mask = T.set_subtensor(mask[indices], 0.)
75
76 # Apply mask
77 acc *= mask
78 acc = T.sum(acc) / T.sum(mask)
79
80 return acc
81
82
83def crossentropy_metric(y_pred, y_true, void_labels, one_hot=False):

Callers 1

trainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected