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

Function accuracy_metric

code/fcn_2D_segm/train_fcn8.py:52–77  ·  view source on GitHub ↗
(y_pred, y_true, void_labels, one_hot=False)

Source from the content-addressed store, hash-verified

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