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

Function crossentropy_metric

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

Source from the content-addressed store, hash-verified

81
82
83def crossentropy_metric(y_pred, y_true, void_labels, one_hot=False):
84 # Clip predictions
85 y_pred = T.clip(y_pred, _EPSILON, 1.0 - _EPSILON)
86
87 if one_hot:
88 y_true = T.argmax(y_true, axis=1)
89
90 # Create mask
91 mask = T.ones_like(y_true, dtype=_FLOATX)
92 for el in void_labels:
93 mask = T.set_subtensor(mask[T.eq(y_true, el).nonzero()], 0.)
94
95 # Modify y_true temporarily
96 y_true_tmp = y_true * mask
97 y_true_tmp = y_true_tmp.astype('int32')
98
99 # Compute cross-entropy
100 loss = T.nnet.categorical_crossentropy(y_pred, y_true_tmp)
101
102 # Compute masked mean loss
103 loss *= mask
104 loss = T.sum(loss) / T.sum(mask)
105
106 return loss
107
108
109SAVEPATH = 'save_models/'

Callers 1

trainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected