@@ -110,46 +110,58 @@ def maxpool_batchnorm_model(input_shape, pool_size=(2, 2)):
110110
111111
112112def test_tensorlist_stack_model ():
113- class TensorArrayStackLayer (tf .keras .layers .Layer ):
114- def __init__ (self ):
115- super ().__init__ ()
116-
117- def call (self , inputs ):
118- inputs = tf .squeeze (inputs )
119- outputs = tf .TensorArray (
120- tf .float32 , size = inputs .shape [0 ], infer_shape = False , element_shape = inputs .shape [1 :]
121- )
122- outputs = outputs .unstack (inputs )
123-
124- return outputs .stack ()
113+ def tensorlist_stack_model (input_shape ):
114+ class TensorArrayStackLayer (tf .keras .layers .Layer ):
115+ def __init__ (self ):
116+ super ().__init__ ()
117+
118+ def call (self , inputs ):
119+ inputs = tf .squeeze (inputs )
120+ outputs = tf .TensorArray (
121+ tf .float32 ,
122+ size = inputs .shape [0 ],
123+ infer_shape = False ,
124+ element_shape = inputs .shape [1 :],
125+ )
126+ outputs = outputs .unstack (inputs )
127+
128+ return outputs .stack ()
129+
130+ input_shape = (3 , 32 )
131+ model = tf .keras .Sequential (
132+ [tf .keras .layers .Input (shape = input_shape , batch_size = 1 ), TensorArrayStackLayer ()]
133+ )
134+ return model
125135
126- shape = (3 , 32 )
127- model = tf .keras .Sequential (
128- [tf .keras .layers .Input (shape = shape , batch_size = 1 ), TensorArrayStackLayer ()]
129- )
130- return model
136+ run_sequential_model (tensorlist_stack_model , input_shape = (3 , 32 ))
131137
132138
133139def test_tensorlist_read_model ():
134- class TensorArrayReadLayer (tf .keras .layers .Layer ):
135- def __init__ (self ):
136- super ().__init__ ()
137-
138- def call (self , inputs ):
139- inputs = tf .squeeze (inputs )
140- outputs = tf .TensorArray (
141- tf .float32 , size = inputs .shape [0 ], infer_shape = False , element_shape = inputs .shape [1 :]
142- )
143- for i in range (inputs .shape [0 ]):
144- outputs = outputs .write (i , inputs [i , :])
145-
146- return outputs .read (0 )
147-
148- shape = (3 , 32 )
149- model = tf .keras .Sequential (
150- [tf .keras .layers .Input (shape = shape , batch_size = 1 ), TensorArrayReadLayer ()]
151- )
152- return model
140+ def tensorlist_read_model (input_shape ):
141+ class TensorArrayReadLayer (tf .keras .layers .Layer ):
142+ def __init__ (self ):
143+ super ().__init__ ()
144+
145+ def call (self , inputs ):
146+ inputs = tf .squeeze (inputs )
147+ outputs = tf .TensorArray (
148+ tf .float32 ,
149+ size = inputs .shape [0 ],
150+ infer_shape = False ,
151+ element_shape = inputs .shape [1 :],
152+ )
153+ for i in range (inputs .shape [0 ]):
154+ outputs = outputs .write (i , inputs [i , :])
155+
156+ return outputs .read (0 )
157+
158+ input_shape = (3 , 32 )
159+ model = tf .keras .Sequential (
160+ [tf .keras .layers .Input (shape = input_shape , batch_size = 1 ), TensorArrayReadLayer ()]
161+ )
162+ return model
163+
164+ run_sequential_model (tensorlist_read_model , input_shape = (3 , 32 ))
153165
154166
155167if __name__ == "__main__" :
0 commit comments