在Keras中使用VGGish。
项目描述
VGGish:一个类似VGG的音频分类模型
该仓库提供了一个VGGish模型,使用Keras实现,后端为tensorflow(由于tf.slim
已被弃用,我认为我们应该有一个最新的接口)。该仓库是基于AudioSet的模型开发的。有关更多详细信息,请访问slim版本。
安装
pip install vggish-keras
权重将在首次请求时下载。您还可以运行python -m vggish_keras.download_helpers.download_weights
来下载它们。
用法
基本 - 简单且高效的方法
import librosa
import numpy as np
import vggish_keras as vgk
# loads the model once and provides a simple function that takes in `filename` or `y, sr`
compute = vgk.get_embedding_function(hop_duration=0.25)
# model, pump, and sampler are available as attributes
compute.model.summary() # take a peak at the model
# compute from filename
Z, ts = compute(librosa.util.example_audio_file())
# compute from pcm
y, sr = librosa.load(librosa.util.example_audio_file())
Z, ts = compute(y=y, sr=sr)
替代方案 - 使用底层的辅助函数
# get the embeddings - WARNING: it instantiates a new model each time
Z, ts = vgk.get_embeddings(librosa.util.example_audio_file(), hop_duration=0.25)
# create model, pump, sampler once and pass to vgk.get_embeddings
# - more typing :'(
model, pump, sampler = vgk.get_embedding_model(hop_duration=0.25)
Z, ts = vgk.get_embeddings(
librosa.util.example_audio_file(),
model=model, pump=pump, sampler=sampler)
手动使用keras模型和pump直接
import librosa
import numpy as np
import vggish_keras as vgk
# define the model
pump = vgk.get_pump()
model = vgk.VGGish(pump)
sampler = vgk.get_sampler(pump)
# transform audio into VGGish embeddings
filename = librosa.util.example_audio_file()
X = np.concatenate([
x[vgk.params.PUMP_INPUT]
for x in sampler(pump(filename))])
Z = model.predict(X)
# calculate timestamps
ts = vgk.get_timesteps(Z, pump, sampler)
assert Z.shape == (13, 512)
参考
-
Gemmeke, J. et. al., AudioSet:音频事件的本体和人工标注数据集,ICASSP 2017
-
Hershey, S. et. al., 大型音频分类的CNN架构,ICASSP 2017
我在download_helpers/convert_ckpt.py中包含了一个权重转换脚本,展示了如何将.ckpt
格式的权重转换为.h5
格式,供感兴趣的人参考。
待办事项
- 目前,可以通过
vgk.params
全局更改参数(采样率、跳步大小等) - 我希望允许将参数覆盖传递给vgk.VGGish
- 目前它依赖于https://github.com/bmcfee/pumpp/pull/123。一旦合并,将移除自定义GitHub安装位置
项目详情
关闭
vggish-keras-0.1.1.tar.gz的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | f177db408699623335187d3cbcdd1aa916413bcf3b1a48db6e60640ae161c273 |
|
MD5 | 285d02e3066f099a1991134f2f6bbb3d |
|
BLAKE2b-256 | 88e2706800cb95ae36567cecfdc4e95f74dfa97f141b688601ec31de65724cbc |