def test_GWD(self):
# Compute categorical crossentropy
indices = self.mock_y > 0
selected_log = -np.log(self.mock_x_softmax[indices])
self.loss = 0#np.sum(selected_log) / np.sum(self.mock_y)
# Create keras model with this activation and compile it
model = Sequential()
activation_layer = Lambda(lambda x: x,
input_shape=self.data_shape[1:],
output_shape=self.data_shape[1:]
)
model.add(activation_layer)
model.compile('sgd', loss=gwd)
# Predict data from the model
loss = model.evaluate(self.mock_y, self.mock_y, batch_size=1, verbose=0)
# Assertions
print('Expected loss: {}'.format(self.loss))
print('Actual loss: {}'.format(loss))
self.assertTrue(np.allclose(loss, self.loss),
msg='Categorical cross-entropy loss 3D does not produce the expected results')
评论列表
文章目录