def test_serialize_deserialize(self): # Create a layer object that sets all of its config options. layer = mat_mul_with_margin.MatMulWithMargin() # Create another layer object from the first object's config. new_layer = mat_mul_with_margin.MatMulWithMargin.from_config( layer.get_config()) # If the serialization was successful, the new config should match the old. self.assertAllEqual(layer.get_config(), new_layer.get_config())
def test_layer_invocation(self): """Validate that the Keras object can be created and invoked.""" input_width = 512 test_layer = mat_mul_with_margin.MatMulWithMargin() # Create a 2-dimensional input (the first dimension is implicit). left_encoded = tf.keras.Input(shape=(input_width, ), dtype=tf.float32) right_encoded = tf.keras.Input(shape=(input_width, ), dtype=tf.float32) left_logits, right_logits = test_layer(left_encoded, right_encoded) # Validate that the outputs are of the expected shape. expected_output_shape = [None, None] self.assertEqual(expected_output_shape, left_logits.shape.as_list()) self.assertEqual(expected_output_shape, right_logits.shape.as_list())