MCPcopy Create free account
hub / github.com/lisa-lab/DeepLearningTutorials / accuracy_metric

Function accuracy_metric

code/cnn_1D_segm/train_fcn1D.py:23–47  ·  view source on GitHub ↗
(y_pred, y_true, void_labels, one_hot=False)

Source from the content-addressed store, hash-verified

21
22
23def accuracy_metric(y_pred, y_true, void_labels, one_hot=False):
24 assert (y_pred.ndim == 2) or (y_pred.ndim == 1)
25
26 # y_pred to indices
27 if y_pred.ndim == 2:
28 y_pred = T.argmax(y_pred, axis=1)
29
30 if one_hot:
31 y_true = T.argmax(y_true, axis=1)
32
33 # Compute accuracy
34 acc = T.eq(y_pred, y_true).astype(_FLOATX)
35
36 # Create mask
37 mask = T.ones_like(y_true, dtype=_FLOATX)
38 for el in void_labels:
39 indices = T.eq(y_true, el).nonzero()
40 if any(indices):
41 mask = T.set_subtensor(mask[indices], 0.)
42
43 # Apply mask
44 acc *= mask
45 acc = T.sum(acc) / T.sum(mask)
46
47 return acc
48
49
50def jaccard(y_pred, y_true, n_classes, one_hot=False):

Callers 1

trainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected