-
Notifications
You must be signed in to change notification settings - Fork 10
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
added a little helper function to vggish to get features from waveforms #31
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,41 @@ | |
|
||
__pproc__ = Postprocessor(PCA_PARAMS) | ||
postprocess = __pproc__.postprocess | ||
|
||
|
||
def waveform_to_features(data, sample_rate, compress=True): | ||
'''Converts an audio waveform to VGGish features, with or without | ||
PCA compression. | ||
|
||
Parameters | ||
---------- | ||
data : np.array of either one dimension (mono) or two dimensions (stereo) | ||
|
||
sample_rate: | ||
Sample rate of the audio data | ||
|
||
compress : bool | ||
If True, PCA and quantization are applied to the features. | ||
If False, the features are taken directly from the model output | ||
|
||
Returns | ||
------- | ||
time_points : np.ndarray, len=n | ||
Time points in seconds of the features | ||
|
||
features : np.ndarray, shape=(n, 128) | ||
The output features, with or without PCA compression and quantization. | ||
''' | ||
|
||
import tensorflow as tf | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the rationale for within-function importing here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tf import is heavy (sometimes); we shouldn't do it until called for. If it's already been loaded elsewhere, then this is free. |
||
|
||
examples = waveform_to_examples(data, sample_rate) | ||
|
||
with tf.Graph().as_default(), tf.Session() as sess: | ||
time_points, features = transform(examples, sess) | ||
|
||
if compress: | ||
features_z = postprocess(features) | ||
return time_points, features_z | ||
|
||
return time_points, features |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per #29, we're making a conscious decision to converge to
time_points
then?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I literally just copied over from the existing functions. If we rename, we should do it all at once, and i think it's independent of this pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍