1515# See the License for the specific language governing permissions and
1616# limitations under the License.
1717
18- from typing import Any , Callable , Optional
18+ from typing import Any , Callable , Optional , Tuple
1919import tensorflow as tf
2020from basic_pitch .layers .math import log_base_b
2121
@@ -62,7 +62,7 @@ def __init__(
6262 self .center = center
6363 self .pad_mode = pad_mode
6464
65- def build (self , input_shape : tf . TensorShape ) -> None :
65+ def build (self , input_shape : Tuple [ Optional [ int ], ...] ) -> None :
6666 if self .window_length < self .fft_length :
6767 lpad = (self .fft_length - self .window_length ) // 2
6868 rpad = self .fft_length - self .window_length - lpad
@@ -77,10 +77,11 @@ def padded_window(window_length: int, dtype: tf.dtypes.DType = tf.float32) -> tf
7777 self .final_window_fn = padded_window
7878
7979 if self .center :
80+ rank = len (input_shape )
8081 self .spec = tf .keras .layers .Lambda (
8182 lambda x : tf .pad (
8283 x ,
83- [[0 , 0 ] for _ in range (input_shape . rank - 1 )] + [[self .fft_length // 2 , self .fft_length // 2 ]],
84+ [[0 , 0 ] for _ in range (rank - 1 )] + [[self .fft_length // 2 , self .fft_length // 2 ]],
8485 mode = self .pad_mode ,
8586 )
8687 )
@@ -159,9 +160,9 @@ class NormalizedLog(tf.keras.layers.Layer):
159160 This layer adds 1e-10 to all values as a way to avoid NaN math.
160161 """
161162
162- def build (self , input_shape : tf . Tensor ) -> None :
163+ def build (self , input_shape : Tuple [ Optional [ int ], ...] ) -> None :
163164 self .squeeze_batch = lambda batch : batch
164- rank = input_shape . rank
165+ rank = len ( input_shape )
165166 if rank == 4 :
166167 assert input_shape [1 ] == 1 , "If the rank is 4, the second dimension must be length 1"
167168 self .squeeze_batch = lambda batch : tf .squeeze (batch , axis = 1 )
0 commit comments