Skip to content

Commit

Permalink
add spice-test
Browse files Browse the repository at this point in the history
  • Loading branch information
tandav committed Jun 23, 2024
1 parent ea6e038 commit 3e965f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spice-test/main.py
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
4 changes: 4 additions & 0 deletions spice-test/requirements.txt
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

0 comments on commit 3e965f7

Please sign in to comment.