(self)
| 94 | class LambdaLayerTest(keras_parameterized.TestCase): |
| 95 | |
| 96 | def test_lambda(self): |
| 97 | testing_utils.layer_test( |
| 98 | keras.layers.Lambda, |
| 99 | kwargs={'function': lambda x: x + 1}, |
| 100 | input_shape=(3, 2)) |
| 101 | |
| 102 | testing_utils.layer_test( |
| 103 | keras.layers.Lambda, |
| 104 | kwargs={ |
| 105 | 'function': lambda x, a, b: x * a + b, |
| 106 | 'arguments': { |
| 107 | 'a': 0.6, |
| 108 | 'b': 0.4 |
| 109 | } |
| 110 | }, |
| 111 | input_shape=(3, 2)) |
| 112 | |
| 113 | # test serialization with function |
| 114 | def f(x): |
| 115 | return x + 1 |
| 116 | |
| 117 | ld = keras.layers.Lambda(f) |
| 118 | config = ld.get_config() |
| 119 | ld = keras.layers.deserialize({ |
| 120 | 'class_name': 'Lambda', |
| 121 | 'config': config |
| 122 | }) |
| 123 | self.assertEqual(ld.function(3), 4) |
| 124 | |
| 125 | # test with lambda |
| 126 | ld = keras.layers.Lambda( |
| 127 | lambda x: keras.backend.concatenate([math_ops.square(x), x])) |
| 128 | config = ld.get_config() |
| 129 | ld = keras.layers.Lambda.from_config(config) |
| 130 | self.assertAllEqual(self.evaluate(ld.function([3])), [9, 3]) |
| 131 | |
| 132 | def test_lambda_multiple_inputs(self): |
| 133 | ld = keras.layers.Lambda(lambda x: x[0], output_shape=lambda x: x[0]) |
nothing calls this directly
no test coverage detected