-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import tensorflow_hub as hub | ||
import tensorflow.compat.v1 as tf | ||
import numpy as np | ||
|
||
assert bool(tf.config.list_physical_devices('GPU')) | ||
|
||
|
||
model = hub.load("/media/tandav/sg8tb1/downloads-archive/libmv-data/spice_model") | ||
|
||
# A single wave, 128 samples (8ms at 16kHz) long. | ||
wave = np.array(np.sin(np.linspace(-np.pi, np.pi, 128)), dtype=np.float32) | ||
|
||
# 16 such waves (2048 samples). | ||
waves = np.tile(wave, 16) | ||
|
||
# Run model. One would use real singing as input, here we use the above | ||
# waveform for testing. | ||
input = tf.constant(waves) | ||
output = model.signatures["serving_default"](input) | ||
pitches = output["pitch"] | ||
some_pitch = pitches[2] | ||
|
||
def output2hz(pitch_output): | ||
# Calibration constants | ||
PT_OFFSET = 25.58 | ||
PT_SLOPE = 63.07 | ||
FMIN = 10.0; | ||
BINS_PER_OCTAVE = 12.0; | ||
cqt_bin = pitch_output * PT_SLOPE + PT_OFFSET; | ||
return FMIN * 2.0 ** (1.0 * cqt_bin / BINS_PER_OCTAVE) | ||
|
||
hz = output2hz(some_pitch).numpy() | ||
assert abs(hz - 125) < 0.1 | ||
print(hz) # Should be ~ 125.00815 hz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
numpy<2.0 # todo: upgrade after tensorflow will support it | ||
tensorflow[and-cuda] | ||
tensorflow-hub | ||
# tensorflow<2.12.0 |