-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from harritaylor/dev
Dev merge
- Loading branch information
Showing
8 changed files
with
93 additions
and
287 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 |
---|---|---|
@@ -1,35 +1,27 @@ | ||
# Torch VGGish | ||
A PyTorch port of [VGGish](https://github.com/tensorflow/models/tree/master/research/audioset)<sup>1</sup>, | ||
# VGGish | ||
A `torch`-compatible port of [VGGish](https://github.com/tensorflow/models/tree/master/research/audioset)<sup>[1]</sup>, | ||
a feature embedding frontend for audio classification models. The weights are ported directly from the tensorflow model, so embeddings created using `torchvggish` will be identical. | ||
|
||
## Quick start | ||
There are two options: you can install the last stable version from pypi, or clone this repo and install. | ||
```shell script | ||
# optional: create virtual env | ||
cd torchvggish && python3 -m venv .env | ||
source activate .env/bin/activate | ||
|
||
pip install -i https://test.pypi.org/simple/ torchvggish==0.1 | ||
|
||
# OR get the latest version | ||
git clone [email protected]:harritaylor/torchvggish.git | ||
pip install -r requirements.txt | ||
``` | ||
## Usage | ||
Barebones example of creating embeddings from an `example` wav file: | ||
|
||
```python | ||
from torchvggish import vggish, vggish_input | ||
import torch | ||
|
||
model = torch.hub.load('harritaylor/torchvggish', 'vggish') | ||
model.eval() | ||
|
||
# Initialise model and download weights | ||
embedding_model = vggish() | ||
embedding_model.eval() | ||
# Download an example audio file | ||
import urllib | ||
url, filename = ("http://soundbible.com/grab.php?id=1698&type=wav", "bus_chatter.wav") | ||
try: urllib.URLopener().retrieve(url, filename) | ||
except: urllib.request.urlretrieve(url, filename) | ||
|
||
example = vggish_input.wavfile_to_examples("example.wav") | ||
embeddings = embedding_model.forward(example) | ||
model.forward(filename) | ||
``` | ||
|
||
<hr> | ||
1. S. Hershey et al., ‘CNN Architectures for Large-Scale Audio Classification’,\ | ||
[1] S. Hershey et al., ‘CNN Architectures for Large-Scale Audio Classification’,\ | ||
in International Conference on Acoustics, Speech and Signal Processing (ICASSP),2017\ | ||
Available: https://arxiv.org/abs/1609.09430, https://ai.google/research/pubs/pub45611 | ||
|
||
|
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,15 @@ | ||
dependencies = ['torch', 'numpy', 'resampy', 'soundfile'] | ||
|
||
from torchvggish.vggish import VGGish | ||
|
||
model_urls = { | ||
'vggish': 'https://github.com/harritaylor/torchvggish/' | ||
'releases/download/v0.1/vggish-10086976.pth', | ||
'pca': 'https://github.com/harritaylor/torchvggish/' | ||
'releases/download/v0.1/vggish_pca_params-970ea276.pth' | ||
} | ||
|
||
|
||
def vggish(**kwargs): | ||
model = VGGish(urls=model_urls, **kwargs) | ||
return model |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.