Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion basic_pitch/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import numpy as np
import tensorflow as tf
import mir_eval
Expand Down Expand Up @@ -188,12 +189,19 @@ def _array_to_sonification(array: tf.Tensor, max_outputs: int, clip: float = 0.3
audio_list = []

for i, gram in enumerate(gram_batch):
if gram.shape[1] != TIMES.shape[0]:
logging.warning(
f"Gram shape {gram.shape} does not match times shape {TIMES.shape}, times array will be truncated"
)
times_truncated = TIMES[: min(gram.shape[1], TIMES.shape[0])]
else:
times_truncated = TIMES

gram[gram < clip] = 0.0
y = mir_eval.sonify.time_frequency(
gram[:MAX_FREQ_INDEX, :],
FREQS[:MAX_FREQ_INDEX],
TIMES,
times_truncated,
fs=SONIFY_FS,
)
audio_list.append(y[:, np.newaxis])
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ classifiers = [
dependencies = [
"coremltools; platform_system == 'Darwin'",
"librosa>=0.8.0",
# TODO: mir_eval 0.8.1+ introduces fixes to sonification that broke our tests
# Likely we'd like to adapt the tests to release the constraint
"mir_eval>=0.6,<=0.8.0",
"mir_eval>=0.6.0",
"numpy>=1.18",
"onnxruntime; platform_system == 'Windows' and python_version < '3.11'",
"pretty_midi>=0.2.9",
Expand Down