def test_loss_masking_time(self):
theano.config.mode = 'FAST_COMPILE'
weighted_loss = weighted_objective(objectives.get('categorical_crossentropy'))
shape = (3, 4, 2)
X = np.arange(24).reshape(shape)
Y = 2 * X
weights = np.ones((3, 4, 1)) # Normally the trailing 1 is added by standardize_weights
weights[0, 0] = 0
mask = np.ones((3, 4))
mask[1, 0] = 0
out = weighted_loss(X, Y, weights, mask).eval()
weights[0, 0] = 1e-9 # so that nonzero() doesn't remove this weight
out2 = weighted_loss(X, Y, weights, mask).eval()
print(out)
print(out2)
assert abs(out - out2) < 1e-8
评论列表
文章目录