Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor relevant Librosa filter code to avoid runtime dependencies on Numba and libsndfile. #4

Merged
merged 16 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion realbook/callbacks/spectrogram_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def on_train_begin(self, logs: Any = None) -> None:

with self.tensorboard_writer.as_default():
# Pull n random batches from the dataset and send them to TensorBoard.
for (data, _) in self.example_batches:
for data, _ in self.example_batches:
assert tf.rank(data) == 2, "Expected input data to be of rank 2, with shape (batch, audio)."
assert tf.shape(data)[0] < tf.shape(data)[1], (
"Expected input data to be of rank 2, with shape (batch, audio), but got shape"
Expand Down
6 changes: 3 additions & 3 deletions realbook/layers/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import warnings
from typing import Any, Callable, Dict, Optional, Union

import librosa
import tensorflow as tf
import numpy as np

from realbook.layers.math import log_base_b
from realbook.vendor import librosa_filters


def _create_padded_window(
Expand Down Expand Up @@ -209,7 +209,7 @@ def build(self, input_shape: tf.TensorShape) -> None:
self.fft_length
) # type: ignore

self.window_sum = librosa.filters.window_sumsquare(
self.window_sum = librosa_filters.window_sumsquare(
window=self.window.numpy(),
n_frames=input_shape[0] if input_shape.rank == 2 else input_shape[1],
win_length=self.window_length,
Expand Down Expand Up @@ -353,7 +353,7 @@ def build(self, input_shape: tf.TensorShape) -> None:
super().build(input_shape)

self.mel_weight_matrix = tf.constant(
librosa.filters.mel(
librosa_filters.mel(
sr=self.sample_rate,
n_fft=self.fft_length,
n_mels=self.n_mels,
Expand Down
16 changes: 16 additions & 0 deletions realbook/vendor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright 2023 Spotify AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Loading
Loading