A lightweight yet powerful audio-to-MIDI converter with pitch bend detection
Python audiolightweightmachine-learningmidimusicpitch-detectionpolyphonicpythontranscriptiontypescript
minor reshape fixes and no more magic numbers
Saltinea42fa7773e9e
diff --git a/basic_pitch/nn.py b/basic_pitch/nn.pyindex 2a85648..b9acb0a 100644--- a/basic_pitch/nn.py+++ b/basic_pitch/nn.py@@ -22,6 +22,7 @@ import tensorflow.keras.backend as Kfrom basic_pitch.layers.math import log_base_b+SEMITONES_PER_OCTAVE = 12class HarmonicStacking(tf.keras.layers.Layer):"""Harmonic stacking layer@@ -47,7 +48,7 @@ class HarmonicStacking(tf.keras.layers.Layer):self.bins_per_semitone = bins_per_semitoneself.harmonics = harmonicsself.shifts = [- int(tf.math.round(12.0 * self.bins_per_semitone * log_base_b(float(h), 2))) for h in self.harmonics+ int(tf.math.round(SEMITONES_PER_OCTAVE * self.bins_per_semitone * log_base_b(float(h), 2))) for h in self.harmonics]self.n_output_freqs = n_output_freqs@@ -96,7 +97,7 @@ class FlattenAudioCh(tf.keras.layers.Layer):"""x: (batch, time, ch)"""shapes = K.int_shape(x)tf.assert_equal(shapes[2], 1)- return tf.keras.layers.Reshape([shapes[1]])(x) # ignore batch size+ return tf.squeeze(x, axis=2)class FlattenFreqCh(tf.keras.layers.Layer):@@ -109,4 +110,8 @@ class FlattenFreqCh(tf.keras.layers.Layer):def call(self, x: tf.Tensor) -> tf.Tensor:shapes = K.int_shape(x)- return tf.keras.layers.Reshape([shapes[1], shapes[2] * shapes[3]])(x) # ignore batch size+ batch_size = tf.shape(x)[0]+ time_dim = shapes[1]+ freq_dim = shapes[2]+ ch_dim = shapes[3]+ return tf.reshape(x, [batch_size, time_dim, freq_dim * ch_dim])