MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / test_lambda

Method test_lambda

tensorflow/python/keras/layers/core_test.py:96–130  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

94class 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])

Callers

nothing calls this directly

Calls 8

get_configMethod · 0.95
deserializeMethod · 0.45
functionMethod · 0.45
concatenateMethod · 0.45
squareMethod · 0.45
from_configMethod · 0.45
assertAllEqualMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected